#ifndef LIBHEIF_HEIF_H
#define LIBHEIF_HEIF_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <stdint.h>
#include <libheif/heif_version.h>
#if defined(_MSC_VER) && !defined(LIBHEIF_STATIC_BUILD)
#ifdef LIBHEIF_EXPORTS
#define LIBHEIF_API __declspec(dllexport)
#else
#define LIBHEIF_API __declspec(dllimport)
#endif
#elif defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
#ifdef LIBHEIF_EXPORTS
#define LIBHEIF_API __attribute__((__visibility__("default")))
#else
#define LIBHEIF_API
#endif
#else
#define LIBHEIF_API
#endif
LIBHEIF_API const char *heif_get_version(void);
LIBHEIF_API uint32_t heif_get_version_number(void);
LIBHEIF_API int heif_get_version_number_major(void);
LIBHEIF_API int heif_get_version_number_minor(void);
LIBHEIF_API int heif_get_version_number_maintenance(void);
#define LIBHEIF_MAKE_VERSION(h, m, l) ((h) << 24 | (m) << 16 | (l) << 8)
#define LIBHEIF_HAVE_VERSION(h, m, l) (LIBHEIF_NUMERIC_VERSION >= LIBHEIF_MAKE_VERSION(h, m, l))
struct heif_context;
struct heif_image_handle;
struct heif_image;
enum heif_error_code {
heif_error_Ok = 0,
heif_error_Input_does_not_exist = 1,
heif_error_Invalid_input = 2,
heif_error_Unsupported_filetype = 3,
heif_error_Unsupported_feature = 4,
heif_error_Usage_error = 5,
heif_error_Memory_allocation_error = 6,
heif_error_Decoder_plugin_error = 7,
heif_error_Encoder_plugin_error = 8,
heif_error_Encoding_error = 9
};
enum heif_suberror_code {
heif_suberror_Unspecified = 0,
heif_suberror_End_of_data = 100,
heif_suberror_Invalid_box_size = 101,
heif_suberror_No_ftyp_box = 102,
heif_suberror_No_idat_box = 103,
heif_suberror_No_meta_box = 104,
heif_suberror_No_hdlr_box = 105,
heif_suberror_No_hvcC_box = 106,
heif_suberror_No_pitm_box = 107,
heif_suberror_No_ipco_box = 108,
heif_suberror_No_ipma_box = 109,
heif_suberror_No_iloc_box = 110,
heif_suberror_No_iinf_box = 111,
heif_suberror_No_iprp_box = 112,
heif_suberror_No_iref_box = 113,
heif_suberror_No_pict_handler = 114,
heif_suberror_Ipma_box_references_nonexisting_property = 115,
heif_suberror_No_properties_assigned_to_item = 116,
heif_suberror_No_item_data = 117,
heif_suberror_Invalid_grid_data = 118,
heif_suberror_Missing_grid_images = 119,
heif_suberror_Invalid_clean_aperture = 120,
heif_suberror_Invalid_overlay_data = 121,
heif_suberror_Overlay_image_outside_of_canvas = 122,
heif_suberror_Auxiliary_image_type_unspecified = 123,
heif_suberror_No_or_invalid_primary_item = 124,
heif_suberror_No_infe_box = 125,
heif_suberror_Security_limit_exceeded = 1000,
heif_suberror_Nonexisting_item_referenced = 2000,
heif_suberror_Null_pointer_argument = 2001,
heif_suberror_Nonexisting_image_channel_referenced = 2002,
heif_suberror_Unsupported_plugin_version = 2003,
heif_suberror_Unsupported_writer_version = 2004,
heif_suberror_Unsupported_parameter = 2005,
heif_suberror_Invalid_parameter_value = 2006,
heif_suberror_Unsupported_codec = 3000,
heif_suberror_Unsupported_image_type = 3001,
heif_suberror_Unsupported_data_version = 3002,
heif_suberror_Unsupported_color_conversion = 3003,
heif_suberror_Unsupported_item_construction_method = 3004,
heif_suberror_Cannot_write_output_data = 5000,
};
struct heif_error
{
enum heif_error_code code;
enum heif_suberror_code subcode;
const char* message;
};
typedef uint32_t heif_item_id;
LIBHEIF_API
struct heif_context* heif_context_alloc(void);
LIBHEIF_API
void heif_context_free(struct heif_context*);
struct heif_reading_options;
enum heif_reader_grow_status {
heif_reader_grow_status_size_reached,
heif_reader_grow_status_timeout,
heif_reader_grow_status_size_beyond_eof
};
struct heif_reader {
int reader_api_version;
int64_t (*get_position)(void* userdata);
int (*read)(void* data,
size_t size,
void* userdata);
int (*seek)(int64_t position,
void* userdata);
enum heif_reader_grow_status (*wait_for_file_size)(int64_t target_size, void* userdata);
};
LIBHEIF_API
struct heif_error heif_context_read_from_file(struct heif_context*, const char* filename,
const struct heif_reading_options*);
LIBHEIF_API
struct heif_error heif_context_read_from_memory(struct heif_context*,
const void* mem, size_t size,
const struct heif_reading_options*);
LIBHEIF_API
struct heif_error heif_context_read_from_memory_without_copy(struct heif_context*,
const void* mem, size_t size,
const struct heif_reading_options*);
LIBHEIF_API
struct heif_error heif_context_read_from_reader(struct heif_context*,
const struct heif_reader* reader,
void* userdata,
const struct heif_reading_options*);
LIBHEIF_API
int heif_context_get_number_of_top_level_images(struct heif_context* ctx);
LIBHEIF_API
int heif_context_is_top_level_image_ID(struct heif_context* ctx, heif_item_id id);
LIBHEIF_API
int heif_context_get_list_of_top_level_image_IDs(struct heif_context* ctx,
heif_item_id* ID_array,
int count);
LIBHEIF_API
struct heif_error heif_context_get_primary_image_ID(struct heif_context* ctx, heif_item_id* id);
LIBHEIF_API
struct heif_error heif_context_get_primary_image_handle(struct heif_context* ctx,
struct heif_image_handle**);
LIBHEIF_API
struct heif_error heif_context_get_image_handle(struct heif_context* ctx,
heif_item_id id,
struct heif_image_handle**);
LIBHEIF_API
void heif_context_debug_dump_boxes_to_file(struct heif_context* ctx, int fd);
LIBHEIF_API
void heif_image_handle_release(const struct heif_image_handle*);
LIBHEIF_API
int heif_image_handle_is_primary_image(const struct heif_image_handle* handle);
LIBHEIF_API
int heif_image_handle_get_width(const struct heif_image_handle* handle);
LIBHEIF_API
int heif_image_handle_get_height(const struct heif_image_handle* handle);
LIBHEIF_API
int heif_image_handle_has_alpha_channel(const struct heif_image_handle*);
LIBHEIF_API
int heif_image_handle_has_depth_image(const struct heif_image_handle*);
LIBHEIF_API
int heif_image_handle_get_number_of_depth_images(const struct heif_image_handle* handle);
LIBHEIF_API
int heif_image_handle_get_list_of_depth_image_IDs(const struct heif_image_handle* handle,
heif_item_id* ids, int count);
LIBHEIF_API
struct heif_error heif_image_handle_get_depth_image_handle(const struct heif_image_handle* handle,
heif_item_id depth_image_id,
struct heif_image_handle** out_depth_handle);
enum heif_depth_representation_type {
heif_depth_representation_type_uniform_inverse_Z = 0,
heif_depth_representation_type_uniform_disparity = 1,
heif_depth_representation_type_uniform_Z = 2,
heif_depth_representation_type_nonuniform_disparity = 3
};
struct heif_depth_representation_info {
uint8_t version;
uint8_t has_z_near;
uint8_t has_z_far;
uint8_t has_d_min;
uint8_t has_d_max;
double z_near;
double z_far;
double d_min;
double d_max;
enum heif_depth_representation_type depth_representation_type;
uint32_t disparity_reference_view;
uint32_t depth_nonlinear_representation_model_size;
uint8_t* depth_nonlinear_representation_model;
};
LIBHEIF_API
void heif_depth_representation_info_free(const struct heif_depth_representation_info* info);
LIBHEIF_API
int heif_image_handle_get_depth_image_representation_info(const struct heif_image_handle* handle,
heif_item_id depth_image_id,
const struct heif_depth_representation_info** out);
LIBHEIF_API
int heif_image_handle_get_number_of_thumbnails(const struct heif_image_handle* handle);
LIBHEIF_API
int heif_image_handle_get_list_of_thumbnail_IDs(const struct heif_image_handle* handle,
heif_item_id* ids, int count);
LIBHEIF_API
struct heif_error heif_image_handle_get_thumbnail(const struct heif_image_handle* main_image_handle,
heif_item_id thumbnail_id,
struct heif_image_handle** out_thumbnail_handle);
LIBHEIF_API
int heif_image_handle_get_number_of_metadata_blocks(const struct heif_image_handle* handle,
const char* type_filter);
LIBHEIF_API
int heif_image_handle_get_list_of_metadata_block_IDs(const struct heif_image_handle* handle,
const char* type_filter,
heif_item_id* ids, int count);
LIBHEIF_API
const char* heif_image_handle_get_metadata_type(const struct heif_image_handle* handle,
heif_item_id metadata_id);
LIBHEIF_API
const char* heif_image_handle_get_metadata_content_type(const struct heif_image_handle* handle,
heif_item_id metadata_id);
LIBHEIF_API
size_t heif_image_handle_get_metadata_size(const struct heif_image_handle* handle,
heif_item_id metadata_id);
LIBHEIF_API
struct heif_error heif_image_handle_get_metadata(const struct heif_image_handle* handle,
heif_item_id metadata_id,
void* out_data);
enum heif_compression_format {
heif_compression_undefined = 0,
heif_compression_HEVC = 1,
heif_compression_AVC = 2,
heif_compression_JPEG = 3
};
enum heif_chroma {
heif_chroma_undefined=99,
heif_chroma_monochrome=0,
heif_chroma_420=1,
heif_chroma_422=2,
heif_chroma_444=3,
heif_chroma_interleaved_RGB =10,
heif_chroma_interleaved_RGBA=11
};
#define heif_chroma_interleaved_24bit heif_chroma_interleaved_RGB
#define heif_chroma_interleaved_32bit heif_chroma_interleaved_RGBA
enum heif_colorspace {
heif_colorspace_undefined=99,
heif_colorspace_YCbCr=0,
heif_colorspace_RGB =1,
heif_colorspace_monochrome=2
};
enum heif_channel {
heif_channel_Y = 0,
heif_channel_Cb = 1,
heif_channel_Cr = 2,
heif_channel_R = 3,
heif_channel_G = 4,
heif_channel_B = 5,
heif_channel_Alpha = 6,
heif_channel_interleaved = 10
};
enum heif_progress_step {
heif_progress_step_total = 0,
heif_progress_step_load_tile = 1
};
struct heif_decoding_options
{
uint8_t version;
uint8_t ignore_transformations;
void (*start_progress)(enum heif_progress_step step, int max_progress, void* progress_user_data);
void (*on_progress)(enum heif_progress_step step, int progress, void* progress_user_data);
void (*end_progress)(enum heif_progress_step step, void* progress_user_data);
void* progress_user_data;
};
LIBHEIF_API
struct heif_decoding_options* heif_decoding_options_alloc();
LIBHEIF_API
void heif_decoding_options_free(struct heif_decoding_options*);
LIBHEIF_API
struct heif_error heif_decode_image(const struct heif_image_handle* in_handle,
struct heif_image** out_img,
enum heif_colorspace colorspace,
enum heif_chroma chroma,
const struct heif_decoding_options* options);
LIBHEIF_API
enum heif_colorspace heif_image_get_colorspace(const struct heif_image*);
LIBHEIF_API
enum heif_chroma heif_image_get_chroma_format(const struct heif_image*);
LIBHEIF_API
int heif_image_get_width(const struct heif_image*,enum heif_channel channel);
LIBHEIF_API
int heif_image_get_height(const struct heif_image*,enum heif_channel channel);
LIBHEIF_API
int heif_image_get_bits_per_pixel(const struct heif_image*,enum heif_channel channel);
LIBHEIF_API
int heif_image_has_channel(const struct heif_image*, enum heif_channel channel);
LIBHEIF_API
const uint8_t* heif_image_get_plane_readonly(const struct heif_image*,
enum heif_channel channel,
int* out_stride);
LIBHEIF_API
uint8_t* heif_image_get_plane(struct heif_image*,
enum heif_channel channel,
int* out_stride);
struct heif_scaling_options;
LIBHEIF_API
struct heif_error heif_image_scale_image(const struct heif_image* input,
struct heif_image** output,
int width, int height,
const struct heif_scaling_options* options);
LIBHEIF_API
void heif_image_release(const struct heif_image*);
LIBHEIF_API
struct heif_error heif_context_write_to_file(struct heif_context*,
const char* filename);
struct heif_writer {
int writer_api_version;
struct heif_error (*write)(struct heif_context* ctx,
const void* data,
size_t size,
void* userdata);
};
LIBHEIF_API
struct heif_error heif_context_write(struct heif_context*,
struct heif_writer* writer,
void* userdata);
struct heif_encoder;
struct heif_encoder_descriptor;
struct heif_encoder_parameter;
LIBHEIF_API
int heif_context_get_encoder_descriptors(struct heif_context*,
enum heif_compression_format format_filter,
const char* name_filter,
const struct heif_encoder_descriptor** out_encoders,
int count);
LIBHEIF_API
const char* heif_encoder_descriptor_get_name(const struct heif_encoder_descriptor*);
LIBHEIF_API
const char* heif_encoder_descriptor_get_id_name(const struct heif_encoder_descriptor*);
LIBHEIF_API
enum heif_compression_format
heif_encoder_descriptor_get_compression_format(const struct heif_encoder_descriptor*);
LIBHEIF_API
int heif_encoder_descriptor_supportes_lossy_compression(const struct heif_encoder_descriptor*);
LIBHEIF_API
int heif_encoder_descriptor_supportes_lossless_compression(const struct heif_encoder_descriptor*);
LIBHEIF_API
struct heif_error heif_context_get_encoder(struct heif_context* context,
const struct heif_encoder_descriptor*,
struct heif_encoder** out_encoder);
LIBHEIF_API
int heif_have_decoder_for_format(enum heif_compression_format format);
LIBHEIF_API
int heif_have_encoder_for_format(enum heif_compression_format format);
LIBHEIF_API
struct heif_error heif_context_get_encoder_for_format(struct heif_context* context,
enum heif_compression_format format,
struct heif_encoder**);
LIBHEIF_API
void heif_encoder_release(struct heif_encoder*);
LIBHEIF_API
const char* heif_encoder_get_name(const struct heif_encoder*);
LIBHEIF_API
struct heif_error heif_encoder_set_lossy_quality(struct heif_encoder*, int quality);
LIBHEIF_API
struct heif_error heif_encoder_set_lossless(struct heif_encoder*, int enable);
LIBHEIF_API
struct heif_error heif_encoder_set_logging_level(struct heif_encoder*, int level);
LIBHEIF_API
const struct heif_encoder_parameter*const* heif_encoder_list_parameters(struct heif_encoder*);
LIBHEIF_API
const char* heif_encoder_parameter_get_name(const struct heif_encoder_parameter*);
enum heif_encoder_parameter_type {
heif_encoder_parameter_type_integer = 1,
heif_encoder_parameter_type_boolean = 2,
heif_encoder_parameter_type_string = 3
};
LIBHEIF_API
enum heif_encoder_parameter_type heif_encoder_parameter_get_type(const struct heif_encoder_parameter*);
LIBHEIF_API
struct heif_error heif_encoder_parameter_get_valid_integer_range(const struct heif_encoder_parameter*,
int* have_minimum_maximum,
int* minimum, int* maximum);
LIBHEIF_API
struct heif_error heif_encoder_parameter_get_valid_string_values(const struct heif_encoder_parameter*,
const char*const** out_stringarray);
LIBHEIF_API
struct heif_error heif_encoder_set_parameter_integer(struct heif_encoder*,
const char* parameter_name,
int value);
LIBHEIF_API
struct heif_error heif_encoder_get_parameter_integer(struct heif_encoder*,
const char* parameter_name,
int* value);
LIBHEIF_API
struct heif_error heif_encoder_parameter_integer_valid_range(struct heif_encoder*,
const char* parameter_name,
int* have_minimum_maximum,
int* minimum, int* maximum);
LIBHEIF_API
struct heif_error heif_encoder_set_parameter_boolean(struct heif_encoder*,
const char* parameter_name,
int value);
LIBHEIF_API
struct heif_error heif_encoder_get_parameter_boolean(struct heif_encoder*,
const char* parameter_name,
int* value);
LIBHEIF_API
struct heif_error heif_encoder_set_parameter_string(struct heif_encoder*,
const char* parameter_name,
const char* value);
LIBHEIF_API
struct heif_error heif_encoder_get_parameter_string(struct heif_encoder*,
const char* parameter_name,
char* value, int value_size);
LIBHEIF_API
struct heif_error heif_encoder_parameter_string_valid_values(struct heif_encoder*,
const char* parameter_name,
const char*const** out_stringarray);
LIBHEIF_API
struct heif_error heif_encoder_set_parameter(struct heif_encoder*,
const char* parameter_name,
const char* value);
LIBHEIF_API
struct heif_error heif_encoder_get_parameter(struct heif_encoder*,
const char* parameter_name,
char* value_ptr, int value_size);
struct heif_encoding_options {
uint8_t version;
uint8_t save_alpha_channel;
};
LIBHEIF_API
struct heif_encoding_options* heif_encoding_options_alloc();
LIBHEIF_API
void heif_encoding_options_free(struct heif_encoding_options*);
LIBHEIF_API
struct heif_error heif_context_encode_image(struct heif_context*,
const struct heif_image* image,
struct heif_encoder* encoder,
const struct heif_encoding_options* options,
struct heif_image_handle** out_image_handle);
LIBHEIF_API
struct heif_error heif_context_set_primary_image(struct heif_context*,
struct heif_image_handle* image_handle);
LIBHEIF_API
struct heif_error heif_context_encode_thumbnail(struct heif_context*,
const struct heif_image* image,
const struct heif_image_handle* master_image_handle,
struct heif_encoder* encoder,
const struct heif_encoding_options* options,
int bbox_size,
struct heif_image_handle** out_thumb_image_handle);
LIBHEIF_API
struct heif_error heif_context_assign_thumbnail(struct heif_context*,
const struct heif_image_handle* thumbnail_image,
const struct heif_image_handle* master_image);
LIBHEIF_API
struct heif_error heif_context_add_exif_metadata(struct heif_context*,
const struct heif_image_handle* image_handle,
const void* data, int size);
LIBHEIF_API
struct heif_error heif_context_add_XMP_metadata(struct heif_context*,
const struct heif_image_handle* image_handle,
const void* data, int size);
LIBHEIF_API
struct heif_error heif_image_create(int width, int height,
enum heif_colorspace colorspace,
enum heif_chroma chroma,
struct heif_image** out_image);
LIBHEIF_API
struct heif_error heif_image_add_plane(struct heif_image* image,
enum heif_channel channel,
int width, int height, int bit_depth);
struct heif_decoder_plugin;
struct heif_encoder_plugin;
LIBHEIF_API
struct heif_error heif_register_decoder(struct heif_context* heif, const struct heif_decoder_plugin*);
LIBHEIF_API
struct heif_error heif_register_decoder_plugin(const struct heif_decoder_plugin*);
LIBHEIF_API
struct heif_error heif_register_encoder_plugin(const struct heif_encoder_plugin*);
#ifdef __cplusplus
}
#endif
#endif