[gegl] exr-load: return a gegl buffer in the correct format for half-float (16 bit) OpenEXR images



commit 29dc0f28fe228676403f29bed601aee7207de1a9
Author: Felix Ulber <felix ulber gmx de>
Date:   Thu Nov 22 00:18:29 2012 +0100

    exr-load: return a gegl buffer in the correct format for half-float (16 bit) OpenEXR images
    
    The query_exr function is called first to gather information about the image, then import_exr is called using this information.
    1) query_exr returned babl_format("<Color Model> float") for both, float and half float image data.
    2) In function insert_channels (called from import_exr) the actual pixel data is read from the OpenEXR interface. Here values are hard-coded to allways obtain 32bit float data. Which in conjunction with 1) doesn't cause corruption in case of a half float image data, but it makes data allways float, which may not be wanted and unnecessary waste of memory.

 operations/external/exr-load.cpp |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/operations/external/exr-load.cpp b/operations/external/exr-load.cpp
index 719cd44..dcca02d 100644
--- a/operations/external/exr-load.cpp
+++ b/operations/external/exr-load.cpp
@@ -408,30 +408,39 @@ insert_channels (FrameBuffer  &fb,
                  gint          format_flags,
                  gint          bpp)
 {
-  gint alpha_offset = 12;
+  gint alpha_offset;
   PixelType tp;
+  // bytes per channel - is there a babl mechanism to obtain that from format_flags?
+  gint bpc = 4;
 
   if (format_flags & COLOR_U32)
     tp = UINT;
+  else if (format_flags & COLOR_FP16)
+    {
+      tp = HALF;
+      bpc = 2;
+    }
   else
     tp = FLOAT;
 
+  alpha_offset = bpc*3;
+
   if (format_flags & COLOR_RGB)
     {
-      fb.insert ("R", Slice (tp, base,    bpp, 0, 1,1, 0.0));
-      fb.insert ("G", Slice (tp, base+4,  bpp, 0, 1,1, 0.0));
-      fb.insert ("B", Slice (tp, base+8,  bpp, 0, 1,1, 0.0));
+      fb.insert ("R", Slice (tp, base,          bpp, 0, 1,1, 0.0));
+      fb.insert ("G", Slice (tp, base+bpc,      bpp, 0, 1,1, 0.0));
+      fb.insert ("B", Slice (tp, base+bpc*2,    bpp, 0, 1,1, 0.0));
     }
   else if (format_flags & COLOR_C)
     {
-      fb.insert ("Y",  Slice (tp, base,   bpp,   0, 1,1, 0.5));
-      fb.insert ("RY", Slice (tp, base+4, bpp*2, 0, 2,2, 0.0));
-      fb.insert ("BY", Slice (tp, base+8, bpp*2, 0, 2,2, 0.0));
+      fb.insert ("Y",  Slice (tp, base,         bpp,   0, 1,1, 0.5));
+      fb.insert ("RY", Slice (tp, base+bpc,     bpp*2, 0, 2,2, 0.0));
+      fb.insert ("BY", Slice (tp, base+bpc*2,   bpp*2, 0, 2,2, 0.0));
     }
   else if (format_flags & COLOR_Y)
     {
       fb.insert ("Y",  Slice (tp, base, bpp, 0, 1,1, 0.5));
-      alpha_offset = 4;
+      alpha_offset = bpc;
     }
 
   if (format_flags & COLOR_ALPHA)
@@ -584,6 +593,9 @@ query_exr (const gchar *path,
             strcat (format_string, " u32");
             break;
           case HALF:
+	    format_flags |= COLOR_FP16;
+            strcat (format_string, " half");
+            break;
           case FLOAT:
           default:
             format_flags |= COLOR_FP32;



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