[gimp/gimp-2-10] plug-ins: follow the assigned profile TRC in PNG export.



commit 72c5d24fe91956a5572151ec036f5ad2d5f63cdc
Author: Jehan <jehan girinstud io>
Date:   Sat May 25 14:01:55 2019 +0200

    plug-ins: follow the assigned profile TRC in PNG export.
    
    Similar to JPEG export (commit c5f7bac2ba2121636bbf84d5e4af4d11e98fa511)
    as discussed with Ell. GIMP should follow and save as-is any *assigned*
    profile. We only make a decision about whether to convert from storage
    precision to another format when the profile is the default GIMP one.

 plug-ins/common/file-png.c | 88 ++++++++++++++++++++++++----------------------
 1 file changed, 45 insertions(+), 43 deletions(-)
---
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 003f24ae7c..72f22e7e79 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -1463,7 +1463,7 @@ save_image (const gchar  *filename,
   gint              num;              /* Number of rows to load */
   FILE             *fp;               /* File pointer */
   GimpColorProfile *profile = NULL;   /* Color profile */
-  gboolean          linear;           /* Save linear RGB */
+  gboolean          out_linear;       /* Save linear RGB */
   GeglBuffer       *buffer;           /* GEGL buffer for layer */
   const Babl       *file_format;      /* BABL format of file */
   png_structp       pp;               /* PNG read pointer */
@@ -1478,47 +1478,57 @@ save_image (const gchar  *filename,
   time_t            cutime;           /* Time since epoch */
   struct tm        *gmt;              /* GMT broken down */
   gint              color_type;       /* PNG color type */
-  gint              bit_depth = 16;   /* Default to bit bepth 16 */
+  gint              bit_depth;        /* Default to bit depth 16 */
 
   guchar            remap[256];       /* Re-mapping for the palette */
 
   png_textp         text = NULL;
 
+  out_linear = FALSE;
 #if defined(PNG_iCCP_SUPPORTED)
+  profile = gimp_image_get_color_profile (orig_image_ID);
   if (pngvals.save_profile)
-    profile = gimp_image_get_effective_color_profile (orig_image_ID);
+    {
+      if (profile && gimp_color_profile_is_linear (profile) &&
+          pngvals.export_format == PNG_FORMAT_AUTO)
+        out_linear = TRUE;
+
+      if (! profile)
+        profile = gimp_image_get_effective_color_profile (orig_image_ID);
+
+      if (! out_linear && gimp_color_profile_is_linear (profile))
+        {
+          /* This should happen only when using default linear profile
+           * (no profile explicitly set) or when not exporting to
+           * PNG_FORMAT_AUTO.
+           */
+          GimpColorProfile *saved_profile;
+
+          saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile);
+          g_object_unref (profile);
+          profile = saved_profile;
+        }
+    }
 #endif
 
+  /* We save as 8-bit PNG only if:
+   * (1) Work image is 8-bit linear with linear profile to be saved.
+   * (2) Work image is 8-bit non-linear or perceptual with or without
+   * profile.
+   */
+  bit_depth = 16;
   switch (gimp_image_get_precision (image_ID))
     {
     case GIMP_PRECISION_U8_LINEAR:
-      /* only keep 8 bit linear RGB if we also save a profile */
-      if (profile)
+      if (out_linear)
         bit_depth = 8;
-
-    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:
-      /* save linear RGB only if we save a profile, or a loader won't
-       * do the right thing
-       */
-      if (profile)
-        linear = TRUE;
-      else
-        linear = FALSE;
       break;
 
     case GIMP_PRECISION_U8_GAMMA:
       bit_depth = 8;
+      break;
 
-    case GIMP_PRECISION_U16_GAMMA:
-    case GIMP_PRECISION_U32_GAMMA:
-    case GIMP_PRECISION_HALF_GAMMA:
-    case GIMP_PRECISION_FLOAT_GAMMA:
-    case GIMP_PRECISION_DOUBLE_GAMMA:
-      linear = FALSE;
+    default:
       break;
     }
 
@@ -1604,14 +1614,14 @@ save_image (const gchar  *filename,
         color_type = PNG_COLOR_TYPE_RGB;
         if (bit_depth == 8)
           {
-            if (linear)
+            if (out_linear)
               file_format = babl_format ("RGB u8");
             else
               file_format = babl_format ("R'G'B' u8");
           }
         else
           {
-            if (linear)
+            if (out_linear)
               file_format = babl_format ("RGB u16");
             else
               file_format = babl_format ("R'G'B' u16");
@@ -1622,14 +1632,14 @@ save_image (const gchar  *filename,
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
         if (bit_depth == 8)
           {
-            if (linear)
+            if (out_linear)
               file_format = babl_format ("RGBA u8");
             else
               file_format = babl_format ("R'G'B'A u8");
           }
         else
           {
-            if (linear)
+            if (out_linear)
               file_format = babl_format ("RGBA u16");
             else
               file_format = babl_format ("R'G'B'A u16");
@@ -1640,14 +1650,14 @@ save_image (const gchar  *filename,
         color_type = PNG_COLOR_TYPE_GRAY;
         if (bit_depth == 8)
           {
-            if (linear)
+            if (out_linear)
               file_format = babl_format ("Y u8");
             else
               file_format = babl_format ("Y' u8");
           }
         else
           {
-            if (linear)
+            if (out_linear)
               file_format = babl_format ("Y u16");
             else
               file_format = babl_format ("Y' u16");
@@ -1658,14 +1668,14 @@ save_image (const gchar  *filename,
         color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
         if (bit_depth == 8)
           {
-            if (linear)
+            if (out_linear)
               file_format = babl_format ("YA u8");
             else
               file_format = babl_format ("Y'A u8");
           }
         else
           {
-            if (linear)
+            if (out_linear)
               file_format = babl_format ("YA u16");
             else
               file_format = babl_format ("Y'A u16");
@@ -1739,14 +1749,6 @@ save_image (const gchar  *filename,
           bit_depth = 16;
           break;
       }
-      if (linear && profile)
-        {
-          GimpColorProfile *saved_profile;
-
-          saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile);
-          g_object_unref (profile);
-          profile = saved_profile;
-        }
     }
 
   bpp = babl_format_get_bytes_per_pixel (file_format);
@@ -1831,7 +1833,7 @@ save_image (const gchar  *filename,
     }
 
 #if defined(PNG_iCCP_SUPPORTED)
-  if (profile)
+  if (pngvals.save_profile)
     {
       GimpParasite *parasite;
       gchar        *profile_name = NULL;
@@ -1855,9 +1857,9 @@ save_image (const gchar  *filename,
                     icc_length);
 
       g_free (profile_name);
-
-      g_object_unref (profile);
     }
+  if (profile)
+    g_object_unref (profile);
 #endif
 
 #ifdef PNG_zTXt_SUPPORTED


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