Revision: 15500
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15500
Author:   ton
Date:     2008-07-09 12:51:03 +0200 (Wed, 09 Jul 2008)

Log Message:
-----------
Fix for reported openexr file reading failures.

For simple RGB(A) files, the channel names in openexr were supposed
to be simply "R" "G" "B" and "A" too.
Other programs like other names... like lower case, or like "ambient.r"

Tested with file from renderman.

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/openexr/openexr_api.cpp

Modified: trunk/blender/source/blender/imbuf/intern/openexr/openexr_api.cpp
===================================================================
--- trunk/blender/source/blender/imbuf/intern/openexr/openexr_api.cpp   
2008-07-09 10:13:09 UTC (rev 15499)
+++ trunk/blender/source/blender/imbuf/intern/openexr/openexr_api.cpp   
2008-07-09 10:51:03 UTC (rev 15500)
@@ -842,7 +842,7 @@
 } RGBA;
 
 
-#if 0
+/* debug only */
 static void exr_print_filecontents(InputFile *file)
 {
        const ChannelList &channels = file->header().channels();
@@ -853,8 +853,29 @@
                printf("OpenEXR-load: Found channel %s of type %d\n", i.name(), 
channel.type);
        }
 }
-#endif
 
+/* for non-multilayer, map  R G B A channel names to something that's in this 
file */
+static const char *exr_rgba_channelname(InputFile *file, const char *chan)
+{
+       const ChannelList &channels = file->header().channels();
+       
+       for (ChannelList::ConstIterator i = channels.begin(); i != 
channels.end(); ++i)
+       {
+               const Channel &channel = i.channel();
+               const char *str= i.name();
+               int len= strlen(str);
+               if(len) {
+                       if(strcasecmp(chan, str+len-1)==0) {
+                               printf("name %s\n", str);
+                               return str;
+                       }
+               }
+       }
+       return chan;
+}
+
+
+
 static int exr_has_zbuffer(InputFile *file)
 {
        const ChannelList &channels = file->header().channels();
@@ -896,7 +917,8 @@
                //printf("OpenEXR-load: image data window %d %d %d %d\n", 
                //         dw.min.x, dw.min.y, dw.max.x, dw.max.y);
 
-               // exr_print_filecontents(file);
+               if(0) // debug
+                       exr_print_filecontents(file);
                
                is_multi= exr_is_renderresult(file);
                
@@ -935,11 +957,15 @@
                                        /* but, since we read y-flipped 
(negative y stride) we move to last scanline */
                                        first+= 4*(height-1)*width;
                                        
-                                       frameBuffer.insert ("R", Slice (FLOAT,  
(char *) first, xstride, ystride));
-                                       frameBuffer.insert ("G", Slice (FLOAT,  
(char *) (first+1), xstride, ystride));
-                                       frameBuffer.insert ("B", Slice (FLOAT,  
(char *) (first+2), xstride, ystride));
-                                                                               
                                                                        /* 1.0 
is fill value */
-                                       frameBuffer.insert ("A", Slice (FLOAT,  
(char *) (first+3), xstride, ystride, 1, 1, 1.0f));
+                                       frameBuffer.insert ( 
exr_rgba_channelname(file, "R"), 
+                                                                               
Slice (FLOAT,  (char *) first, xstride, ystride));
+                                       frameBuffer.insert ( 
exr_rgba_channelname(file, "G"), 
+                                                                               
Slice (FLOAT,  (char *) (first+1), xstride, ystride));
+                                       frameBuffer.insert ( 
exr_rgba_channelname(file, "B"), 
+                                                                               
Slice (FLOAT,  (char *) (first+2), xstride, ystride));
+                                                                               
                                                                        
+                                       frameBuffer.insert ( 
exr_rgba_channelname(file, "A"), 
+                                                                               
Slice (FLOAT,  (char *) (first+3), xstride, ystride, 1, 1, 1.0f)); /* 1.0 is 
fill value */
 
                                        if(exr_has_zbuffer(file)) 
                                        {


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to