From 532866007d0f189f8bea5f149f979e8ebb53de23 Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 12 Apr 2019 12:57:18 +0200 Subject: [PATCH] Issue #1070: exporting to jpeg from 32-bit float linear image... ... produces jpeg in linear color space. The problem was that we were anyway always exporting to non-linear while attaching a linear profile. A first approach would have been to export in linear instead when the work image is linear, as proposed by mitch in a first version of the patch. Yet as Elle Stone notes, it is not a great idea to export 8-bit images as linear. Instead let's continue to always export as non-linear, as we were already doing. Yet when we also save a profile, and this one was originally linear, let's convert it to sRGB TRC before exporting. (cherry picked from commit 8594275bb7a807feae997146d6dbf3ca72a1a0b1) --- plug-ins/file-jpeg/jpeg-save.c | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c index c04f43706f..61e38d9a46 100644 --- a/plug-ins/file-jpeg/jpeg-save.c +++ b/plug-ins/file-jpeg/jpeg-save.c @@ -550,14 +550,55 @@ save_image (const gchar *filename, if (profile) { - const guint8 *icc_data; - gsize icc_length; + GimpColorProfile *saved_profile; + const guint8 *icc_data; + gsize icc_length; + gboolean linear; - icc_data = gimp_color_profile_get_icc_profile (profile, &icc_length); + switch (gimp_image_get_precision (orig_image_ID)) + { + case GIMP_PRECISION_U8_LINEAR: + case GIMP_PRECISION_U16_LINEAR: + case GIMP_PRECISION_U32_LINEAR: + case GIMP_PRECISION_HALF_LINEAR: + case GIMP_PRECISION_FLOAT_LINEAR: + case GIMP_PRECISION_DOUBLE_LINEAR: + linear = TRUE; + break; + case GIMP_PRECISION_U8_NON_LINEAR: + case GIMP_PRECISION_U16_NON_LINEAR: + case GIMP_PRECISION_U32_NON_LINEAR: + case GIMP_PRECISION_HALF_NON_LINEAR: + case GIMP_PRECISION_FLOAT_NON_LINEAR: + case GIMP_PRECISION_DOUBLE_NON_LINEAR: + + case GIMP_PRECISION_U8_PERCEPTUAL: + case GIMP_PRECISION_U16_PERCEPTUAL: + case GIMP_PRECISION_U32_PERCEPTUAL: + case GIMP_PRECISION_HALF_PERCEPTUAL: + case GIMP_PRECISION_FLOAT_PERCEPTUAL: + case GIMP_PRECISION_DOUBLE_PERCEPTUAL: + linear = FALSE; + break; + } + + /* Though it would be technically possible to export with a + * linear profile, it is not such a great idea to export 8-bit + * formats as linear. This is why our current JPEG exporter + * only exports 8-bit non linear JPEG images. + */ + if (linear) + saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile); + else + saved_profile = profile; + + icc_data = gimp_color_profile_get_icc_profile (saved_profile, &icc_length); jpeg_icc_write_profile (&cinfo, icc_data, icc_length); g_object_unref (profile); + if (linear) + g_object_unref (saved_profile); } }