[gegl] exr-load/save: for now, only do associated alpha in EXRs



commit d3b2adf93d9adb04d88c8fa869a9d124c4e298e1
Author: Øyvind Kolås <pippin gimp org>
Date:   Fri Jun 14 00:11:41 2019 +0200

    exr-load/save: for now, only do associated alpha in EXRs
    
    Not sure if this is *always* correct, it probably most of the time is
    and could be manually separated in the cases where it might be wrong
    to load as associated.

 operations/external/exr-load.cpp | 34 +++++++++++++++++++++++-----------
 operations/external/exr-save.cc  | 20 ++++++++++----------
 2 files changed, 33 insertions(+), 21 deletions(-)
---
diff --git a/operations/external/exr-load.cpp b/operations/external/exr-load.cpp
index e3a2538a3..e864f7e3e 100644
--- a/operations/external/exr-load.cpp
+++ b/operations/external/exr-load.cpp
@@ -559,10 +559,19 @@ query_exr (const gchar *path,
  (NULL, c2.white[0], c2.white[1], c2.red[0], c2.red[1], c2.green[0], c2.green[1], c2.blue[0], c2.blue[1], 
babl_trc ("sRGB"), babl_trc ("sRGB"), babl_trc ("sRGB"), BABL_SPACE_FLAG_EQUALIZE);
       }
 
+      if (ch.findChannel ("A"))
+        {
+          format_flags |= COLOR_ALPHA;
+        }
+
+
       if (ch.findChannel ("R") || ch.findChannel ("G") || ch.findChannel ("B"))
         {
-          strcpy (format_string, "RGB");
-          format_flags = COLOR_RGB;
+          if (format_flags & COLOR_ALPHA)
+            strcpy (format_string, "RaGaBa");
+          else
+            strcpy (format_string, "RGB");
+          format_flags |= COLOR_RGB;
 
           if ((chan = ch.findChannel ("R")))
             pt = chan->type;
@@ -574,15 +583,21 @@ query_exr (const gchar *path,
       else if (ch.findChannel ("Y") &&
                (ch.findChannel("RY") || ch.findChannel("BY")))
         {
-          strcpy (format_string, "RGB");
-          format_flags = COLOR_Y | COLOR_C;
+          if (format_flags & COLOR_ALPHA)
+            strcpy (format_string, "RaGaBa");
+          else
+            strcpy (format_string, "RGB");
+          format_flags |= COLOR_Y | COLOR_C;
 
           pt = ch.findChannel ("Y")->type;
         }
       else if (ch.findChannel ("Y"))
         {
-          strcpy (format_string, "Y");
-          format_flags = COLOR_Y;
+          if (format_flags & COLOR_ALPHA)
+            strcpy (format_string, "Ya");
+          else
+            strcpy (format_string, "Y");
+          format_flags |= COLOR_Y;
           pt = ch.findChannel ("Y")->type;
         }
       else
@@ -591,11 +606,8 @@ query_exr (const gchar *path,
           return FALSE;
         }
 
-      if (ch.findChannel ("A"))
-        {
-          strcat (format_string, "A");
-          format_flags |= COLOR_ALPHA;
-        }
+      if (format_flags & COLOR_ALPHA)
+        strcat (format_string, "A");
 
       switch (pt)
         {
diff --git a/operations/external/exr-save.cc b/operations/external/exr-save.cc
index 018e5d9af..1e8c09d96 100644
--- a/operations/external/exr-save.cc
+++ b/operations/external/exr-save.cc
@@ -243,16 +243,16 @@ gegl_exr_save_process (GeglOperation       *operation,
    */
   const Babl *original_format = gegl_buffer_get_format (input);
   const Babl *original_space = babl_format_get_space (original_format);
-  unsigned depth = babl_format_get_n_components (original_format);
+  unsigned n_components = babl_format_get_n_components (original_format);
 
-  switch (depth)
+  switch (n_components)
     {
-      case 1: output_format = "Y float";    break;
-      case 2: output_format = "YA float";   break;
-      case 3: output_format = "RGB float";  break;
-      case 4: output_format = "RGBA float"; break;
+      case 1: output_format = "Y float";       break;
+      case 2: output_format = "YaA float";     break;
+      case 3: output_format = "RGB float";     break;
+      case 4: output_format = "RaGaBaA float"; break;
       default:
-        g_warning ("exr-save: cannot write exr with depth %d.", depth);
+        g_warning ("exr-save: cannot write exr with n_components %d.", n_components);
         return FALSE;
         break;
     }
@@ -262,11 +262,11 @@ gegl_exr_save_process (GeglOperation       *operation,
    * can set the origin.
    */
   float *pixels
-    = (float *) g_malloc (rect->width * rect->height * depth * sizeof *pixels);
+    = (float *) g_malloc (rect->width * rect->height * n_components * sizeof *pixels);
   if (pixels == 0)
     {
       g_warning ("exr-save: could allocate %d*%d*%d pixels.",
-        rect->width, rect->height, depth);
+        rect->width, rect->height, n_components);
       return FALSE;
     }
 
@@ -277,7 +277,7 @@ gegl_exr_save_process (GeglOperation       *operation,
   try
     {
       exr_save_process (pixels, original_space, rect->width, rect->height,
-                        depth, tile_size, filename);
+                        n_components, tile_size, filename);
       status = TRUE;
     }
   catch (std::exception &e)


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