[gimp] Issue #3164: HEIC doesnt have color profile.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Issue #3164: HEIC doesnt have color profile.
- Date: Mon, 1 Apr 2019 13:33:39 +0000 (UTC)
commit 22e14e0b9bedb30a65b4ab27d3782496402325d9
Author: Jehan <jehan girinstud io>
Date: Mon Apr 1 15:29:58 2019 +0200
Issue #3164: HEIC doesnt have color profile.
Since this requires libheif 1.4.0, released end of February 2019, this
commit should not go into the gimp-2-10 branch right now.
configure.ac | 2 +-
plug-ins/common/file-heif.c | 59 +++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2128fc335c..5eddda0658 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,7 +65,7 @@ m4_define([harfbuzz_required_version], [0.9.19])
m4_define([intltool_required_version], [0.40.1])
m4_define([lcms_required_version], [2.8])
m4_define([libgudev_required_version], [167])
-m4_define([libheif_required_version], [1.1.0])
+m4_define([libheif_required_version], [1.4.0])
m4_define([liblzma_required_version], [5.0.0])
m4_define([libmypaint_required_version], [1.3.0])
m4_define([libpng_required_version], [1.6.25])
diff --git a/plug-ins/common/file-heif.c b/plug-ins/common/file-heif.c
index 5ac2f9e566..bfef48abbc 100644
--- a/plug-ins/common/file-heif.c
+++ b/plug-ins/common/file-heif.c
@@ -337,6 +337,7 @@ load_image (GFile *file,
struct heif_error err;
struct heif_image_handle *handle = NULL;
struct heif_image *img = NULL;
+ GimpColorProfile *profile = NULL;
gint n_images;
heif_item_id primary;
heif_item_id selected_image;
@@ -478,6 +479,42 @@ load_image (GFile *file,
return -1;
}
+ switch (heif_image_handle_get_color_profile_type (handle))
+ {
+ case heif_color_profile_type_not_present:
+ break;
+ case heif_color_profile_type_rICC:
+ case heif_color_profile_type_prof:
+ /* I am unsure, but it looks like both these types represent an
+ * ICC color profile. XXX
+ */
+ {
+ void *profile_data;
+ size_t profile_size;
+
+ profile_size = heif_image_handle_get_raw_color_profile_size (handle);
+ profile_data = g_malloc0 (profile_size);
+ err = heif_image_handle_get_raw_color_profile (handle, profile_data);
+
+ if (err.code)
+ g_warning ("%s: color profile loading failed and discarded.",
+ G_STRFUNC);
+ else
+ profile = gimp_color_profile_new_from_icc_profile ((guint8 *) profile_data,
+ profile_size, NULL);
+
+ g_free (profile_data);
+ }
+ break;
+ default:
+ /* heif_color_profile_type_nclx (what is that?) and any future
+ * profile type which we don't support in GIMP (yet).
+ */
+ g_warning ("%s: unknown color profile type has been discarded.",
+ G_STRFUNC);
+ break;
+ }
+
gimp_progress_update (0.75);
width = heif_image_get_width (img, heif_channel_interleaved);
@@ -490,6 +527,12 @@ load_image (GFile *file,
image_ID = gimp_image_new (width, height, GIMP_RGB);
gimp_image_set_filename (image_ID, g_file_get_uri (file));
+ if (profile)
+ {
+ gimp_image_set_color_profile (image_ID, profile);
+ g_object_unref (profile);
+ }
+
layer_ID = gimp_layer_new (image_ID,
_("image content"),
width, height,
@@ -622,6 +665,7 @@ save_image (GFile *file,
struct heif_image_handle *handle;
struct heif_writer writer;
struct heif_error err;
+ GimpColorProfile *profile = NULL;
GOutputStream *output;
GeglBuffer *buffer;
const Babl *format;
@@ -634,8 +678,9 @@ save_image (GFile *file,
gimp_progress_init_printf (_("Exporting '%s'"),
g_file_get_parse_name (file));
- width = gimp_drawable_width (drawable_ID);
- height = gimp_drawable_height (drawable_ID);
+ profile = gimp_image_get_effective_color_profile (image_ID);
+ width = gimp_drawable_width (drawable_ID);
+ height = gimp_drawable_height (drawable_ID);
has_alpha = gimp_drawable_has_alpha (drawable_ID);
@@ -646,6 +691,16 @@ save_image (GFile *file,
heif_chroma_interleaved_24bit,
&image);
+ if (profile)
+ {
+ const guint8 *icc_data;
+ gsize icc_length;
+
+ icc_data = gimp_color_profile_get_icc_profile (profile, &icc_length);
+ heif_image_set_raw_color_profile (image, "prof", icc_data, icc_length);
+ g_object_unref (profile);
+ }
+
heif_image_add_plane (image, heif_channel_interleaved,
width, height, has_alpha ? 32 : 24);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]