[gegl] png-save: avoid storing CMYK ICC profiles



commit e400d9f73dd531fd7a707a582c3db500480eae47
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Nov 28 13:46:56 2018 +0100

    png-save: avoid storing CMYK ICC profiles
    
    In that case we've stored synthetic sRGB profile based data, discard
    profile when saving to satisfy libpng sanity.

 operations/external/png-save.c  |  6 +++--
 operations/external/tiff-save.c | 51 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 4 deletions(-)
---
diff --git a/operations/external/png-save.c b/operations/external/png-save.c
index 0167c7aa4..b57d933d4 100644
--- a/operations/external/png-save.c
+++ b/operations/external/png-save.c
@@ -160,6 +160,8 @@ export_png (GeglOperation       *operation,
         double green[2];
         double blue[2];
         const Babl *trc[3];
+        int is_cmyk = babl_space_is_cmyk (space);
+
         babl_space_get (space, &wp[0], &wp[1],
                         &red[0], &red[1],
                         &green[0], &green[1],
@@ -168,7 +170,7 @@ export_png (GeglOperation       *operation,
         png_set_cHRM (png, info, wp[0], wp[1], red[0], red[1], green[0], green[1], blue[0], blue[1]);
       /* XXX: should also set gamma based on trc! */
         if (trc[0] == babl_trc("sRGB") ||
-            trc[0] == babl_trc("2.2"))
+            trc[0] == babl_trc("2.2") || is_cmyk)
         {
           png_set_gAMA (png, info, 2.2);
         }
@@ -181,7 +183,7 @@ export_png (GeglOperation       *operation,
           png_set_gAMA (png, info, 2.2);
         }
 
-        {
+        if (!is_cmyk) {
           int icc_len;
           const char *name = babl_get_name (space);
           const char *icc_profile;
diff --git a/operations/external/tiff-save.c b/operations/external/tiff-save.c
index 03ccdf4d5..2e98d83c3 100644
--- a/operations/external/tiff-save.c
+++ b/operations/external/tiff-save.c
@@ -24,6 +24,12 @@
 
 property_file_path (path, _("File"), "")
     description (_("Target path and filename, use '-' for stdout"))
+property_int (bitdepth, _("Bitdepth"), -1)
+  description (_("-1, 8, 16, 32 and 64 are the currently accepted values, -1 means auto"))
+  value_range (-1, 64)
+property_int (ieeef, _("IEEEF"), -1)
+  description (_("floating point -1 means auto, 0 means integer 1 meant float."))
+  value_range (-1, 1)
 
 #else
 
@@ -549,12 +555,38 @@ export_tiff (GeglOperation *operation,
   else
     {
       g_warning("sample format not supported: %s", babl_get_name(type));
-
       sample_format = SAMPLEFORMAT_UINT;
       type = babl_type("u8");
       bits_per_sample = 8;
     }
 
+  if (o->bitdepth > 0)
+  {
+    switch (o->bitdepth)
+    {
+      case 8:
+        bits_per_sample = 8;
+      break;
+      case 16:
+        bits_per_sample = 16;
+      break;
+      case 32:
+        bits_per_sample = 32;
+      break;
+      case 64:
+        bits_per_sample = 64;
+      break;
+    }
+  }
+  if (o->ieeef >= 0)
+  {
+    if (o->ieeef == 1)
+      sample_format = SAMPLEFORMAT_IEEEFP;
+    else
+      sample_format = SAMPLEFORMAT_UINT;
+  }
+
+
   TIFFSetField(p->tiff, TIFFTAG_BITSPERSAMPLE, bits_per_sample);
   TIFFSetField(p->tiff, TIFFTAG_SAMPLEFORMAT, sample_format);
 
@@ -569,8 +601,23 @@ export_tiff (GeglOperation *operation,
       return -1;
     }
 
+  if (o->bitdepth > 0 || o->ieeef >= 0)
+  {
+    switch (bits_per_sample)
+    {
+      case 8: type = babl_type ("u8"); 
+              sample_format = SAMPLEFORMAT_UINT;
+              break;
+      case 16: type = babl_type (o->ieeef==1?"half":"u16"); break;
+      case 32: type = babl_type (o->ieeef==1?"float":"u32"); break;
+      case 64: type = babl_type ("double");
+              sample_format = SAMPLEFORMAT_IEEEFP;
+              break;
+    }
+  }
+
   g_snprintf(format_string, 32, "%s %s",
-             babl_get_name(model), babl_get_name(type));
+              babl_get_name(model), babl_get_name(type));
 
   format = babl_format_with_space (format_string, space);
 


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