[gimp/gimp-2-10] plug-ins: add the 8-bit linear with no assigned profile exception...



commit 39672c855958b09d88bf580bfdc82a3290f2c10a
Author: Jehan <jehan girinstud io>
Date:   Thu Jun 6 16:16:38 2019 +0200

    plug-ins: add the 8-bit linear with no assigned profile exception...
    
    ... in JPEG export.
    Same as the WebP export, which is quite similar (8-bit max format), when
    no profile was explicitly set, we want to convert any data from storage
    format to non-linear (unlike when exporting high bit depth formats, such
    as TIFF).
    We only make an exception for 8-bit linear. This commit adds this
    exception.
    
    (cherry picked from commit 0461022198624b1bb1fafcd2d886cd015e7faa22)

 plug-ins/file-jpeg/jpeg-save.c | 61 +++++++++++++++++++++++++-----------------
 1 file changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c
index 18cf2492cd..93598e8a12 100644
--- a/plug-ins/file-jpeg/jpeg-save.c
+++ b/plug-ins/file-jpeg/jpeg-save.c
@@ -277,7 +277,7 @@ save_image (const gchar  *filename,
   FILE             * volatile outfile;
   guchar           *data;
   guchar           *src;
-  GimpColorProfile *profile;
+  GimpColorProfile *profile = NULL;
 
   gboolean         has_alpha;
   gboolean         out_linear = FALSE;
@@ -335,17 +335,44 @@ save_image (const gchar  *filename,
       return FALSE;
     }
 
-  profile = gimp_image_get_color_profile (orig_image_ID);
+  /* When we don't save profiles, we convert data to sRGB because
+   * that's what most/all readers expect on a no-profile JPEG.
+   * If we save an assigned profile, let's just follow its TRC.
+   * If we save the default linear profile (i.e. no assigned
+   * profile), we convert it to sRGB, except when it is 8-bit linear.
+   */
   if (jsvals.save_profile)
     {
-      /* When we don't save profiles, we convert data to sRGB because
-       * that's what most/all readers expect on a no-profile JPEG.
-       * If we save an assigned profile, let's just follow its TRC.
-       * If we save the default linear profile (i.e. no assigned
-       * profile), we convert it to sRGB.
+      profile = gimp_image_get_color_profile (orig_image_ID);
+
+      /* If a profile is explicitly set, follow its TRC, whatever the
+       * storage format.
        */
       if (profile && gimp_color_profile_is_linear (profile))
         out_linear = TRUE;
+
+      if (! profile)
+        {
+          /* There is always an effective profile. */
+          profile = gimp_image_get_effective_color_profile (orig_image_ID);
+
+          if (gimp_color_profile_is_linear (profile))
+            {
+              if (gimp_image_get_precision (image_ID) != GIMP_PRECISION_U8_LINEAR)
+                {
+                  GimpColorProfile *saved_profile;
+
+                  saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile);
+                  g_object_unref (profile);
+                  profile = saved_profile;
+                }
+              else
+                {
+                  /* Keep linear profile as-is for 8-bit linear image. */
+                  out_linear = TRUE;
+                }
+            }
+        }
     }
 
   jpeg_stdio_dest (&cinfo, outfile);
@@ -578,27 +605,11 @@ save_image (const gchar  *filename,
       const guint8 *icc_data;
       gsize         icc_length;
 
-      if (! profile)
-        /* There is always an effective profile. */
-        profile = gimp_image_get_effective_color_profile (orig_image_ID);
-
-      if (gimp_color_profile_is_linear (profile) && ! out_linear)
-        {
-          /* Convert profile from linear to sRGB. This would normally
-           * only happen when there was no assigned profile (i.e. the
-           * default linear profile is in use). */
-          GimpColorProfile *saved_profile;
-
-          saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile);
-          g_object_unref (profile);
-          profile = saved_profile;
-        }
-
       icc_data = gimp_color_profile_get_icc_profile (profile, &icc_length);
       jpeg_icc_write_profile (&cinfo, icc_data, icc_length);
+
+      g_object_unref (profile);
     }
-  if (profile)
-    g_object_unref (profile);
 
   /* Step 5: while (scan lines remain to be written) */
   /*           jpeg_write_scanlines(...); */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]