From 7e92011ab26a41a7c05fbac82753dc04e7cb4a1a Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sat, 11 Dec 2021 15:49:48 +0100 Subject: Extract the ICC profile and Exif data from HEIC --- fastiv-io.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/fastiv-io.c b/fastiv-io.c index 639038b..c5cd485 100644 --- a/fastiv-io.c +++ b/fastiv-io.c @@ -1163,7 +1163,38 @@ load_libheif_image(struct heif_context *ctx, heif_item_id id, GError **error) } } - // TODO(p): Attach any ICC color profile and Exif data. + heif_item_id exif_id = 0; + if (heif_image_handle_get_list_of_metadata_block_IDs( + handle, "Exif", &exif_id, 1)) { + size_t exif_len = heif_image_handle_get_metadata_size(handle, exif_id); + void *exif = g_malloc0(exif_len); + err = heif_image_handle_get_metadata(handle, exif_id, exif); + if (err.code) { + g_warning("%s", err.message); + g_free(exif); + } else { + cairo_surface_set_user_data(surface, &fastiv_io_key_exif, + g_bytes_new_take(exif, exif_len), + (cairo_destroy_func_t) g_bytes_unref); + } + } + + // https://loc.gov/preservation/digital/formats/fdd/fdd000526.shtml#factors + if (heif_image_handle_get_color_profile_type(handle) == + heif_color_profile_type_prof) { + size_t icc_len = heif_image_handle_get_raw_color_profile_size(handle); + void *icc = g_malloc0(icc_len); + err = heif_image_handle_get_raw_color_profile(handle, icc); + if (err.code) { + g_warning("%s", err.message); + g_free(icc); + } else { + cairo_surface_set_user_data(surface, &fastiv_io_key_icc, + g_bytes_new_take(icc, icc_len), + (cairo_destroy_func_t) g_bytes_unref); + } + } + cairo_surface_mark_dirty(surface); fail_process: -- cgit v1.2.3-70-g09d2