From 862415e002d913548ea9e9cc9b01b6bdb3f510cc Mon Sep 17 00:00:00 2001 From: Benedikt Kantz Date: Sat, 4 Nov 2023 16:11:16 +0100 Subject: [PATCH] Add depth image parsing for emscripten --- .gitignore | 1 + build-emscripten.sh | 5 +- libheif/heif_emscripten.h | 489 +++++++++++++++++++++++--------------- 3 files changed, 302 insertions(+), 193 deletions(-) diff --git a/.gitignore b/.gitignore index 795929c780..4918c1d365 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ third-party/SVT-AV1/ third-party/dav1d/ third-party/libwebp/ third-party/rav1e/ +buildjs* \ No newline at end of file diff --git a/build-emscripten.sh b/build-emscripten.sh index f9449c2888..c617c4e218 100755 --- a/build-emscripten.sh +++ b/build-emscripten.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR=$PWD if [[ $# -ne 1 ]] ; then echo "Usage: $0 SRCDIR" @@ -27,7 +27,7 @@ STANDALONE="${STANDALONE:-0}" DEBUG="${DEBUG:-0}" USE_WASM="${USE_WASM:-1}" -echo "Build using ${CORES} CPU cores" +echo "Build using ${CORES} CPU cores in dir ${DIR}" LIBRARY_LINKER_FLAGS="" LIBRARY_INCLUDE_FLAGS="" @@ -50,6 +50,7 @@ if [ "$ENABLE_LIBDE265" = "1" ]; then LIBRARY_LINKER_FLAGS="$LIBRARY_LINKER_FLAGS -lde265" LIBRARY_INCLUDE_FLAGS="$LIBRARY_INCLUDE_FLAGS -L${DIR}/libde265-${LIBDE265_VERSION}/libde265/.libs" fi +echo "libde265: $CONFIGURE_ARGS_LIBDE265" CONFIGURE_ARGS_AOM="" if [ "$ENABLE_AOM" = "1" ]; then diff --git a/libheif/heif_emscripten.h b/libheif/heif_emscripten.h index 395e1a7566..2c583c873c 100644 --- a/libheif/heif_emscripten.h +++ b/libheif/heif_emscripten.h @@ -19,22 +19,24 @@ static std::string _heif_get_version() } static struct heif_error _heif_context_read_from_memory( - struct heif_context* context, const std::string& data) + struct heif_context *context, const std::string &data) { return heif_context_read_from_memory(context, data.data(), data.size(), nullptr); } static emscripten::val heif_js_context_get_image_handle( - struct heif_context* context, heif_item_id id) + struct heif_context *context, heif_item_id id) { emscripten::val result = emscripten::val::object(); - if (!context) { + if (!context) + { return result; } - struct heif_image_handle* handle; + struct heif_image_handle *handle; struct heif_error err = heif_context_get_image_handle(context, id, &handle); - if (err.code != heif_error_Ok) { + if (err.code != heif_error_Ok) + { return emscripten::val(err); } @@ -42,20 +44,23 @@ static emscripten::val heif_js_context_get_image_handle( } static emscripten::val heif_js_context_get_list_of_top_level_image_IDs( - struct heif_context* context) + struct heif_context *context) { emscripten::val result = emscripten::val::array(); - if (!context) { + if (!context) + { return result; } int count = heif_context_get_number_of_top_level_images(context); - if (count <= 0) { + if (count <= 0) + { return result; } - heif_item_id* ids = (heif_item_id*) malloc(count * sizeof(heif_item_id)); - if (!ids) { + heif_item_id *ids = (heif_item_id *)malloc(count * sizeof(heif_item_id)); + if (!ids) + { struct heif_error err; err.code = heif_error_Memory_allocation_error; err.subcode = heif_suberror_Security_limit_exceeded; @@ -63,12 +68,14 @@ static emscripten::val heif_js_context_get_list_of_top_level_image_IDs( } int received = heif_context_get_list_of_top_level_image_IDs(context, ids, count); - if (!received) { + if (!received) + { free(ids); return result; } - for (int i = 0; i < received; i++) { + for (int i = 0; i < received; i++) + { result.set(i, ids[i]); } free(ids); @@ -197,17 +204,19 @@ static emscripten::val heif_js_decode_image(struct heif_image_handle* handle, * The returned object includes a pointer to an heif_image in the property "image". * This image has to be released after the image data has been read (copied) with heif_image_release(). */ -static emscripten::val heif_js_decode_image2(struct heif_image_handle* handle, +static emscripten::val heif_js_decode_image2(struct heif_image_handle *handle, enum heif_colorspace colorspace, enum heif_chroma chroma) { emscripten::val result = emscripten::val::object(); - if (!handle) { + if (!handle) + { return result; } - struct heif_image* image; + struct heif_image *image; struct heif_error err = heif_decode_image(handle, &image, colorspace, chroma, nullptr); - if (err.code != heif_error_Ok) { + if (err.code != heif_error_Ok) + { return emscripten::val(err); } @@ -223,26 +232,27 @@ static emscripten::val heif_js_decode_image2(struct heif_image_handle* handle, result.set("chroma", heif_image_get_chroma_format(image)); result.set("colorspace", heif_image_get_colorspace(image)); - std::vector channels { - heif_channel_Y, - heif_channel_Cb, - heif_channel_Cr, - heif_channel_R, - heif_channel_G, - heif_channel_B, - heif_channel_Alpha, - heif_channel_interleaved - }; + std::vector channels{ + heif_channel_Y, + heif_channel_Cb, + heif_channel_Cr, + heif_channel_R, + heif_channel_G, + heif_channel_B, + heif_channel_Alpha, + heif_channel_interleaved}; emscripten::val val_channels = emscripten::val::array(); - for (auto channel : channels) { - if (heif_image_has_channel(image, channel)) { + for (auto channel : channels) + { + if (heif_image_has_channel(image, channel)) + { emscripten::val val_channel_info = emscripten::val::object(); val_channel_info.set("id", channel); - int stride; - const uint8_t* plane = heif_image_get_plane_readonly(image, channel, &stride); + int stride = -1; + const uint8_t *plane = heif_image_get_plane_readonly(image, channel, &stride); val_channel_info.set("stride", stride); val_channel_info.set("data", emscripten::val(emscripten::typed_memory_view(stride * height, plane))); @@ -259,170 +269,267 @@ static emscripten::val heif_js_decode_image2(struct heif_image_handle* handle, return result; } +static emscripten::val heif_js_depth_img_decode(struct heif_image_handle *handle, heif_item_id depth_image_id) +{ + emscripten::val depth_result = emscripten::val::object(); + struct heif_image_handle *depth_handle; + heif_image_handle_get_depth_image_handle(handle, depth_image_id, &depth_handle); + if (!depth_handle) + { + depth_result.set("err", "could not get handle of depth image"); + depth_result.set("id", depth_image_id); + return depth_result; + } + + int width = heif_image_handle_get_width(depth_handle); + depth_result.set("width", width); + + int height = heif_image_handle_get_height(depth_handle); + depth_result.set("height", height); + + struct heif_image *depth_image; + struct heif_error err = heif_decode_image(depth_handle, &depth_image, heif_colorspace_monochrome, heif_chroma_monochrome, nullptr); + if (err.code) + { + depth_result.set("err", "could not get image of depth image"); + depth_result.set("msg", err.message); + depth_result.set("id", depth_image_id); + return depth_result; + } + + depth_result.set("testdata", emscripten::val(emscripten::typed_memory_view(10, "123456890"))); + return depth_result; + std::vector channels{ + heif_channel_Y, + heif_channel_Cb, + heif_channel_Cr, + heif_channel_R, + heif_channel_G, + heif_channel_B, + heif_channel_Alpha, + heif_channel_interleaved}; + + for (auto &&channel : channels) + { + if (heif_image_has_channel(depth_image, channel)) + { + depth_result.set("c_width", heif_image_get_width(depth_image, channel)); + depth_result.set("c_height", heif_image_get_height(depth_image, channel)); + + int stride; + const uint8_t *plane = heif_image_get_plane_readonly(depth_image, channel, &stride); + if (plane) + { + depth_result.set("stride", stride); + depth_result.set("data", emscripten::val(emscripten::typed_memory_view(stride * height, plane))); + depth_result.set("buffersize", stride * height); + depth_result.set("channel", channel); + depth_result.set("testdata", emscripten::val(emscripten::typed_memory_view(10, "123456890"))); + return depth_result; + } + } + } + + depth_result.set("err", "could get no plane of depth image"); + depth_result.set("id", depth_image_id); + return depth_result; +} +static emscripten::val heif_js_get_depth_imgs_decoded(struct heif_image_handle *handle) +{ + // similar to https://github.com/bigcat88/pillow_heif/blob/b2bf2744d0e4203088481b938af91974b3a2006f/pillow_heif/_pillow_heif.c#L1094 + emscripten::val results = emscripten::val::array(); + if (!handle) + { + return results; + } + int n_images = heif_image_handle_get_number_of_depth_images(handle); + if (n_images == 0) + return results; + heif_item_id *ids = (heif_item_id *)malloc(n_images * sizeof(heif_item_id)); + + n_images = heif_image_handle_get_list_of_depth_image_IDs(handle, ids, n_images); + for (int i = 0; i < n_images; i++) + { + + struct heif_image_handle *depth_handle; + heif_image_handle_get_depth_image_handle(handle, ids[i], &depth_handle); + results.call("push", emscripten::val(depth_handle)); + } + free(ids); + return results; +} #define EXPORT_HEIF_FUNCTION(name) \ emscripten::function(#name, &name, emscripten::allow_raw_pointers()) -EMSCRIPTEN_BINDINGS(libheif) { - emscripten::function("heif_get_version", &_heif_get_version, - emscripten::allow_raw_pointers()); - EXPORT_HEIF_FUNCTION(heif_get_version_number); - - EXPORT_HEIF_FUNCTION(heif_context_alloc); - EXPORT_HEIF_FUNCTION(heif_context_free); - emscripten::function("heif_context_read_from_memory", - &_heif_context_read_from_memory, emscripten::allow_raw_pointers()); - EXPORT_HEIF_FUNCTION(heif_context_get_number_of_top_level_images); - emscripten::function("heif_js_context_get_list_of_top_level_image_IDs", - &heif_js_context_get_list_of_top_level_image_IDs, emscripten::allow_raw_pointers()); - emscripten::function("heif_js_context_get_image_handle", - &heif_js_context_get_image_handle, emscripten::allow_raw_pointers()); - //emscripten::function("heif_js_decode_image", - //&heif_js_decode_image, emscripten::allow_raw_pointers()); - emscripten::function("heif_js_decode_image2", - &heif_js_decode_image2, emscripten::allow_raw_pointers()); - EXPORT_HEIF_FUNCTION(heif_image_handle_release); - EXPORT_HEIF_FUNCTION(heif_image_handle_get_width); - EXPORT_HEIF_FUNCTION(heif_image_handle_get_height); - EXPORT_HEIF_FUNCTION(heif_image_handle_is_primary_image); - EXPORT_HEIF_FUNCTION(heif_image_release); - - emscripten::enum_("heif_error_code") - .value("heif_error_Ok", heif_error_Ok) - .value("heif_error_Input_does_not_exist", heif_error_Input_does_not_exist) - .value("heif_error_Invalid_input", heif_error_Invalid_input) - .value("heif_error_Plugin_loading_error", heif_error_Plugin_loading_error) - .value("heif_error_Unsupported_filetype", heif_error_Unsupported_filetype) - .value("heif_error_Unsupported_feature", heif_error_Unsupported_feature) - .value("heif_error_Usage_error", heif_error_Usage_error) - .value("heif_error_Memory_allocation_error", heif_error_Memory_allocation_error) - .value("heif_error_Decoder_plugin_error", heif_error_Decoder_plugin_error) - .value("heif_error_Encoder_plugin_error", heif_error_Encoder_plugin_error) - .value("heif_error_Encoding_error", heif_error_Encoding_error) - .value("heif_error_Color_profile_does_not_exist", heif_error_Color_profile_does_not_exist); - emscripten::enum_("heif_suberror_code") - .value("heif_suberror_Unspecified", heif_suberror_Unspecified) - .value("heif_suberror_Cannot_write_output_data", heif_suberror_Cannot_write_output_data) - .value("heif_suberror_Encoder_initialization", heif_suberror_Encoder_initialization) - .value("heif_suberror_Encoder_encoding", heif_suberror_Encoder_encoding) - .value("heif_suberror_Encoder_cleanup", heif_suberror_Encoder_cleanup) - .value("heif_suberror_Too_many_regions", heif_suberror_Too_many_regions) - .value("heif_suberror_End_of_data", heif_suberror_End_of_data) - .value("heif_suberror_Invalid_box_size", heif_suberror_Invalid_box_size) - .value("heif_suberror_No_ftyp_box", heif_suberror_No_ftyp_box) - .value("heif_suberror_No_idat_box", heif_suberror_No_idat_box) - .value("heif_suberror_No_meta_box", heif_suberror_No_meta_box) - .value("heif_suberror_No_hdlr_box", heif_suberror_No_hdlr_box) - .value("heif_suberror_No_hvcC_box", heif_suberror_No_hvcC_box) - .value("heif_suberror_No_pitm_box", heif_suberror_No_pitm_box) - .value("heif_suberror_No_ipco_box", heif_suberror_No_ipco_box) - .value("heif_suberror_No_ipma_box", heif_suberror_No_ipma_box) - .value("heif_suberror_No_iloc_box", heif_suberror_No_iloc_box) - .value("heif_suberror_No_iinf_box", heif_suberror_No_iinf_box) - .value("heif_suberror_No_iprp_box", heif_suberror_No_iprp_box) - .value("heif_suberror_No_iref_box", heif_suberror_No_iref_box) - .value("heif_suberror_No_pict_handler", heif_suberror_No_pict_handler) - .value("heif_suberror_Ipma_box_references_nonexisting_property", heif_suberror_Ipma_box_references_nonexisting_property) - .value("heif_suberror_No_properties_assigned_to_item", heif_suberror_No_properties_assigned_to_item) - .value("heif_suberror_No_item_data", heif_suberror_No_item_data) - .value("heif_suberror_Invalid_grid_data", heif_suberror_Invalid_grid_data) - .value("heif_suberror_Missing_grid_images", heif_suberror_Missing_grid_images) - .value("heif_suberror_No_av1C_box", heif_suberror_No_av1C_box) - .value("heif_suberror_Invalid_clean_aperture", heif_suberror_Invalid_clean_aperture) - .value("heif_suberror_Invalid_overlay_data", heif_suberror_Invalid_overlay_data) - .value("heif_suberror_Overlay_image_outside_of_canvas", heif_suberror_Overlay_image_outside_of_canvas) - .value("heif_suberror_Plugin_is_not_loaded", heif_suberror_Plugin_is_not_loaded) - .value("heif_suberror_Plugin_loading_error", heif_suberror_Plugin_loading_error) - .value("heif_suberror_Auxiliary_image_type_unspecified", heif_suberror_Auxiliary_image_type_unspecified) - .value("heif_suberror_Cannot_read_plugin_directory", heif_suberror_Cannot_read_plugin_directory) - .value("heif_suberror_No_or_invalid_primary_item", heif_suberror_No_or_invalid_primary_item) - .value("heif_suberror_No_infe_box", heif_suberror_No_infe_box) - .value("heif_suberror_Security_limit_exceeded", heif_suberror_Security_limit_exceeded) - .value("heif_suberror_Unknown_color_profile_type", heif_suberror_Unknown_color_profile_type) - .value("heif_suberror_Wrong_tile_image_chroma_format", heif_suberror_Wrong_tile_image_chroma_format) - .value("heif_suberror_Invalid_fractional_number", heif_suberror_Invalid_fractional_number) - .value("heif_suberror_Invalid_image_size", heif_suberror_Invalid_image_size) - .value("heif_suberror_Nonexisting_item_referenced", heif_suberror_Nonexisting_item_referenced) - .value("heif_suberror_Null_pointer_argument", heif_suberror_Null_pointer_argument) - .value("heif_suberror_Nonexisting_image_channel_referenced", heif_suberror_Nonexisting_image_channel_referenced) - .value("heif_suberror_Unsupported_plugin_version", heif_suberror_Unsupported_plugin_version) - .value("heif_suberror_Unsupported_writer_version", heif_suberror_Unsupported_writer_version) - .value("heif_suberror_Unsupported_parameter", heif_suberror_Unsupported_parameter) - .value("heif_suberror_Invalid_parameter_value", heif_suberror_Invalid_parameter_value) - .value("heif_suberror_Invalid_property", heif_suberror_Invalid_property) - .value("heif_suberror_Item_reference_cycle", heif_suberror_Item_reference_cycle) - .value("heif_suberror_Invalid_pixi_box", heif_suberror_Invalid_pixi_box) - .value("heif_suberror_Invalid_region_data", heif_suberror_Invalid_region_data) - .value("heif_suberror_Unsupported_codec", heif_suberror_Unsupported_codec) - .value("heif_suberror_Unsupported_image_type", heif_suberror_Unsupported_image_type) - .value("heif_suberror_Unsupported_data_version", heif_suberror_Unsupported_data_version) - .value("heif_suberror_Unsupported_color_conversion", heif_suberror_Unsupported_color_conversion) - .value("heif_suberror_Unsupported_item_construction_method", heif_suberror_Unsupported_item_construction_method) - .value("heif_suberror_Unsupported_header_compression_method", heif_suberror_Unsupported_header_compression_method) - .value("heif_suberror_Unsupported_bit_depth", heif_suberror_Unsupported_bit_depth) - .value("heif_suberror_Wrong_tile_image_pixel_depth", heif_suberror_Wrong_tile_image_pixel_depth) - .value("heif_suberror_Unknown_NCLX_color_primaries", heif_suberror_Unknown_NCLX_color_primaries) - .value("heif_suberror_Unknown_NCLX_transfer_characteristics", heif_suberror_Unknown_NCLX_transfer_characteristics) - .value("heif_suberror_Unknown_NCLX_matrix_coefficients", heif_suberror_Unknown_NCLX_matrix_coefficients); - emscripten::enum_("heif_compression_format") - .value("heif_compression_undefined", heif_compression_undefined) - .value("heif_compression_HEVC", heif_compression_HEVC) - .value("heif_compression_AVC", heif_compression_AVC) - .value("heif_compression_JPEG", heif_compression_JPEG) - .value("heif_compression_AV1", heif_compression_AV1) - .value("heif_compression_VVC", heif_compression_VVC) - .value("heif_compression_EVC", heif_compression_EVC) - .value("heif_compression_JPEG2000", heif_compression_JPEG2000) - .value("heif_compression_uncompressed", heif_compression_uncompressed) - .value("heif_compression_mask", heif_compression_mask); - emscripten::enum_("heif_chroma") - .value("heif_chroma_undefined", heif_chroma_undefined) - .value("heif_chroma_monochrome", heif_chroma_monochrome) - .value("heif_chroma_420", heif_chroma_420) - .value("heif_chroma_422", heif_chroma_422) - .value("heif_chroma_444", heif_chroma_444) - .value("heif_chroma_interleaved_RGB", heif_chroma_interleaved_RGB) - .value("heif_chroma_interleaved_RGBA", heif_chroma_interleaved_RGBA) - .value("heif_chroma_interleaved_RRGGBB_BE", heif_chroma_interleaved_RRGGBB_BE) - .value("heif_chroma_interleaved_RRGGBBAA_BE", heif_chroma_interleaved_RRGGBBAA_BE) - .value("heif_chroma_interleaved_RRGGBB_LE", heif_chroma_interleaved_RRGGBB_LE) - .value("heif_chroma_interleaved_RRGGBBAA_LE", heif_chroma_interleaved_RRGGBBAA_LE) - // Aliases - .value("heif_chroma_interleaved_24bit", heif_chroma_interleaved_24bit) - .value("heif_chroma_interleaved_32bit", heif_chroma_interleaved_32bit); - emscripten::enum_("heif_chroma_downsampling_algorithm") - .value("heif_chroma_downsampling_average", heif_chroma_downsampling_average) - .value("heif_chroma_downsampling_nearest_neighbor", heif_chroma_downsampling_nearest_neighbor) - .value("heif_chroma_downsampling_sharp_yuv", heif_chroma_downsampling_sharp_yuv); - emscripten::enum_("heif_chroma_upsampling_algorithm") - .value("heif_chroma_upsampling_bilinear", heif_chroma_upsampling_bilinear) - .value("heif_chroma_upsampling_nearest_neighbor", heif_chroma_upsampling_nearest_neighbor); - emscripten::enum_("heif_colorspace") - .value("heif_colorspace_undefined", heif_colorspace_undefined) - .value("heif_colorspace_YCbCr", heif_colorspace_YCbCr) - .value("heif_colorspace_RGB", heif_colorspace_RGB) - .value("heif_colorspace_monochrome", heif_colorspace_monochrome); - emscripten::enum_("heif_channel") - .value("heif_channel_Y", heif_channel_Y) - .value("heif_channel_Cr", heif_channel_Cr) - .value("heif_channel_Cb", heif_channel_Cb) - .value("heif_channel_R", heif_channel_R) - .value("heif_channel_G", heif_channel_G) - .value("heif_channel_B", heif_channel_B) - .value("heif_channel_Alpha", heif_channel_Alpha) - .value("heif_channel_interleaved", heif_channel_interleaved); - - emscripten::class_("heif_context"); - emscripten::class_("heif_image_handle"); - emscripten::class_("heif_image"); - emscripten::value_object("heif_error") - .field("code", &heif_error::code) - .field("subcode", &heif_error::subcode) - .field("message", emscripten::optional_override([](const struct heif_error& err) { - return std::string(err.message); - }), emscripten::optional_override([](struct heif_error& err, const std::string& value) { - err.message = value.c_str(); - })); +EMSCRIPTEN_BINDINGS(libheif) +{ + emscripten::function("heif_get_version", &_heif_get_version, + emscripten::allow_raw_pointers()); + EXPORT_HEIF_FUNCTION(heif_get_version_number); + + EXPORT_HEIF_FUNCTION(heif_context_alloc); + EXPORT_HEIF_FUNCTION(heif_context_free); + emscripten::function("heif_context_read_from_memory", + &_heif_context_read_from_memory, emscripten::allow_raw_pointers()); + EXPORT_HEIF_FUNCTION(heif_context_get_number_of_top_level_images); + emscripten::function("heif_js_context_get_list_of_top_level_image_IDs", + &heif_js_context_get_list_of_top_level_image_IDs, emscripten::allow_raw_pointers()); + emscripten::function("heif_js_context_get_image_handle", + &heif_js_context_get_image_handle, emscripten::allow_raw_pointers()); + // emscripten::function("heif_js_decode_image", + //&heif_js_decode_image, emscripten::allow_raw_pointers()); + emscripten::function("heif_js_decode_image2", + &heif_js_decode_image2, emscripten::allow_raw_pointers()); + emscripten::function("heif_js_depth_img_decode", + &heif_js_depth_img_decode, emscripten::allow_raw_pointers()); + emscripten::function("heif_js_get_depth_imgs_decoded", + &heif_js_get_depth_imgs_decoded, emscripten::allow_raw_pointers()); + EXPORT_HEIF_FUNCTION(heif_image_handle_release); + EXPORT_HEIF_FUNCTION(heif_image_handle_get_width); + EXPORT_HEIF_FUNCTION(heif_image_handle_get_height); + EXPORT_HEIF_FUNCTION(heif_image_handle_get_number_of_depth_images); + EXPORT_HEIF_FUNCTION(heif_image_handle_get_list_of_depth_image_IDs); + EXPORT_HEIF_FUNCTION(heif_image_handle_get_depth_image_handle); + EXPORT_HEIF_FUNCTION(heif_image_handle_is_primary_image); + EXPORT_HEIF_FUNCTION(heif_image_handle_is_primary_image); + EXPORT_HEIF_FUNCTION(heif_image_release); + + emscripten::enum_("heif_error_code") + .value("heif_error_Ok", heif_error_Ok) + .value("heif_error_Input_does_not_exist", heif_error_Input_does_not_exist) + .value("heif_error_Invalid_input", heif_error_Invalid_input) + .value("heif_error_Plugin_loading_error", heif_error_Plugin_loading_error) + .value("heif_error_Unsupported_filetype", heif_error_Unsupported_filetype) + .value("heif_error_Unsupported_feature", heif_error_Unsupported_feature) + .value("heif_error_Usage_error", heif_error_Usage_error) + .value("heif_error_Memory_allocation_error", heif_error_Memory_allocation_error) + .value("heif_error_Decoder_plugin_error", heif_error_Decoder_plugin_error) + .value("heif_error_Encoder_plugin_error", heif_error_Encoder_plugin_error) + .value("heif_error_Encoding_error", heif_error_Encoding_error) + .value("heif_error_Color_profile_does_not_exist", heif_error_Color_profile_does_not_exist); + emscripten::enum_("heif_suberror_code") + .value("heif_suberror_Unspecified", heif_suberror_Unspecified) + .value("heif_suberror_Cannot_write_output_data", heif_suberror_Cannot_write_output_data) + .value("heif_suberror_Encoder_initialization", heif_suberror_Encoder_initialization) + .value("heif_suberror_Encoder_encoding", heif_suberror_Encoder_encoding) + .value("heif_suberror_Encoder_cleanup", heif_suberror_Encoder_cleanup) + .value("heif_suberror_Too_many_regions", heif_suberror_Too_many_regions) + .value("heif_suberror_End_of_data", heif_suberror_End_of_data) + .value("heif_suberror_Invalid_box_size", heif_suberror_Invalid_box_size) + .value("heif_suberror_No_ftyp_box", heif_suberror_No_ftyp_box) + .value("heif_suberror_No_idat_box", heif_suberror_No_idat_box) + .value("heif_suberror_No_meta_box", heif_suberror_No_meta_box) + .value("heif_suberror_No_hdlr_box", heif_suberror_No_hdlr_box) + .value("heif_suberror_No_hvcC_box", heif_suberror_No_hvcC_box) + .value("heif_suberror_No_pitm_box", heif_suberror_No_pitm_box) + .value("heif_suberror_No_ipco_box", heif_suberror_No_ipco_box) + .value("heif_suberror_No_ipma_box", heif_suberror_No_ipma_box) + .value("heif_suberror_No_iloc_box", heif_suberror_No_iloc_box) + .value("heif_suberror_No_iinf_box", heif_suberror_No_iinf_box) + .value("heif_suberror_No_iprp_box", heif_suberror_No_iprp_box) + .value("heif_suberror_No_iref_box", heif_suberror_No_iref_box) + .value("heif_suberror_No_pict_handler", heif_suberror_No_pict_handler) + .value("heif_suberror_Ipma_box_references_nonexisting_property", heif_suberror_Ipma_box_references_nonexisting_property) + .value("heif_suberror_No_properties_assigned_to_item", heif_suberror_No_properties_assigned_to_item) + .value("heif_suberror_No_item_data", heif_suberror_No_item_data) + .value("heif_suberror_Invalid_grid_data", heif_suberror_Invalid_grid_data) + .value("heif_suberror_Missing_grid_images", heif_suberror_Missing_grid_images) + .value("heif_suberror_No_av1C_box", heif_suberror_No_av1C_box) + .value("heif_suberror_Invalid_clean_aperture", heif_suberror_Invalid_clean_aperture) + .value("heif_suberror_Invalid_overlay_data", heif_suberror_Invalid_overlay_data) + .value("heif_suberror_Overlay_image_outside_of_canvas", heif_suberror_Overlay_image_outside_of_canvas) + .value("heif_suberror_Plugin_is_not_loaded", heif_suberror_Plugin_is_not_loaded) + .value("heif_suberror_Plugin_loading_error", heif_suberror_Plugin_loading_error) + .value("heif_suberror_Auxiliary_image_type_unspecified", heif_suberror_Auxiliary_image_type_unspecified) + .value("heif_suberror_Cannot_read_plugin_directory", heif_suberror_Cannot_read_plugin_directory) + .value("heif_suberror_No_or_invalid_primary_item", heif_suberror_No_or_invalid_primary_item) + .value("heif_suberror_No_infe_box", heif_suberror_No_infe_box) + .value("heif_suberror_Security_limit_exceeded", heif_suberror_Security_limit_exceeded) + .value("heif_suberror_Unknown_color_profile_type", heif_suberror_Unknown_color_profile_type) + .value("heif_suberror_Wrong_tile_image_chroma_format", heif_suberror_Wrong_tile_image_chroma_format) + .value("heif_suberror_Invalid_fractional_number", heif_suberror_Invalid_fractional_number) + .value("heif_suberror_Invalid_image_size", heif_suberror_Invalid_image_size) + .value("heif_suberror_Nonexisting_item_referenced", heif_suberror_Nonexisting_item_referenced) + .value("heif_suberror_Null_pointer_argument", heif_suberror_Null_pointer_argument) + .value("heif_suberror_Nonexisting_image_channel_referenced", heif_suberror_Nonexisting_image_channel_referenced) + .value("heif_suberror_Unsupported_plugin_version", heif_suberror_Unsupported_plugin_version) + .value("heif_suberror_Unsupported_writer_version", heif_suberror_Unsupported_writer_version) + .value("heif_suberror_Unsupported_parameter", heif_suberror_Unsupported_parameter) + .value("heif_suberror_Invalid_parameter_value", heif_suberror_Invalid_parameter_value) + .value("heif_suberror_Invalid_property", heif_suberror_Invalid_property) + .value("heif_suberror_Item_reference_cycle", heif_suberror_Item_reference_cycle) + .value("heif_suberror_Invalid_pixi_box", heif_suberror_Invalid_pixi_box) + .value("heif_suberror_Invalid_region_data", heif_suberror_Invalid_region_data) + .value("heif_suberror_Unsupported_codec", heif_suberror_Unsupported_codec) + .value("heif_suberror_Unsupported_image_type", heif_suberror_Unsupported_image_type) + .value("heif_suberror_Unsupported_data_version", heif_suberror_Unsupported_data_version) + .value("heif_suberror_Unsupported_color_conversion", heif_suberror_Unsupported_color_conversion) + .value("heif_suberror_Unsupported_item_construction_method", heif_suberror_Unsupported_item_construction_method) + .value("heif_suberror_Unsupported_header_compression_method", heif_suberror_Unsupported_header_compression_method) + .value("heif_suberror_Unsupported_bit_depth", heif_suberror_Unsupported_bit_depth) + .value("heif_suberror_Wrong_tile_image_pixel_depth", heif_suberror_Wrong_tile_image_pixel_depth) + .value("heif_suberror_Unknown_NCLX_color_primaries", heif_suberror_Unknown_NCLX_color_primaries) + .value("heif_suberror_Unknown_NCLX_transfer_characteristics", heif_suberror_Unknown_NCLX_transfer_characteristics) + .value("heif_suberror_Unknown_NCLX_matrix_coefficients", heif_suberror_Unknown_NCLX_matrix_coefficients); + emscripten::enum_("heif_compression_format") + .value("heif_compression_undefined", heif_compression_undefined) + .value("heif_compression_HEVC", heif_compression_HEVC) + .value("heif_compression_AVC", heif_compression_AVC) + .value("heif_compression_JPEG", heif_compression_JPEG) + .value("heif_compression_AV1", heif_compression_AV1) + .value("heif_compression_VVC", heif_compression_VVC) + .value("heif_compression_EVC", heif_compression_EVC) + .value("heif_compression_JPEG2000", heif_compression_JPEG2000) + .value("heif_compression_uncompressed", heif_compression_uncompressed) + .value("heif_compression_mask", heif_compression_mask); + emscripten::enum_("heif_chroma") + .value("heif_chroma_undefined", heif_chroma_undefined) + .value("heif_chroma_monochrome", heif_chroma_monochrome) + .value("heif_chroma_420", heif_chroma_420) + .value("heif_chroma_422", heif_chroma_422) + .value("heif_chroma_444", heif_chroma_444) + .value("heif_chroma_interleaved_RGB", heif_chroma_interleaved_RGB) + .value("heif_chroma_interleaved_RGBA", heif_chroma_interleaved_RGBA) + .value("heif_chroma_interleaved_RRGGBB_BE", heif_chroma_interleaved_RRGGBB_BE) + .value("heif_chroma_interleaved_RRGGBBAA_BE", heif_chroma_interleaved_RRGGBBAA_BE) + .value("heif_chroma_interleaved_RRGGBB_LE", heif_chroma_interleaved_RRGGBB_LE) + .value("heif_chroma_interleaved_RRGGBBAA_LE", heif_chroma_interleaved_RRGGBBAA_LE) + // Aliases + .value("heif_chroma_interleaved_24bit", heif_chroma_interleaved_24bit) + .value("heif_chroma_interleaved_32bit", heif_chroma_interleaved_32bit); + emscripten::enum_("heif_chroma_downsampling_algorithm") + .value("heif_chroma_downsampling_average", heif_chroma_downsampling_average) + .value("heif_chroma_downsampling_nearest_neighbor", heif_chroma_downsampling_nearest_neighbor) + .value("heif_chroma_downsampling_sharp_yuv", heif_chroma_downsampling_sharp_yuv); + emscripten::enum_("heif_chroma_upsampling_algorithm") + .value("heif_chroma_upsampling_bilinear", heif_chroma_upsampling_bilinear) + .value("heif_chroma_upsampling_nearest_neighbor", heif_chroma_upsampling_nearest_neighbor); + emscripten::enum_("heif_colorspace") + .value("heif_colorspace_undefined", heif_colorspace_undefined) + .value("heif_colorspace_YCbCr", heif_colorspace_YCbCr) + .value("heif_colorspace_RGB", heif_colorspace_RGB) + .value("heif_colorspace_monochrome", heif_colorspace_monochrome); + emscripten::enum_("heif_channel") + .value("heif_channel_Y", heif_channel_Y) + .value("heif_channel_Cr", heif_channel_Cr) + .value("heif_channel_Cb", heif_channel_Cb) + .value("heif_channel_R", heif_channel_R) + .value("heif_channel_G", heif_channel_G) + .value("heif_channel_B", heif_channel_B) + .value("heif_channel_Alpha", heif_channel_Alpha) + .value("heif_channel_interleaved", heif_channel_interleaved); + + emscripten::class_("heif_context"); + emscripten::class_("heif_image_handle"); + emscripten::class_("heif_image"); + emscripten::value_object("heif_error") + .field("code", &heif_error::code) + .field("subcode", &heif_error::subcode) + .field("message", emscripten::optional_override([](const struct heif_error &err) + { return std::string(err.message); }), + emscripten::optional_override([](struct heif_error &err, const std::string &value) + { err.message = value.c_str(); })); } -#endif // LIBHEIF_BOX_EMSCRIPTEN_H +#endif // LIBHEIF_BOX_EMSCRIPTEN_H