[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30223] trunk/blender/source/blender/imbuf /intern/openexr/openexr_api.cpp: [#22824] OpenEXR Save from byte buffer bug

Campbell Barton ideasman42 at gmail.com
Mon Jul 12 13:28:17 CEST 2010


Revision: 30223
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30223
Author:   campbellbarton
Date:     2010-07-12 13:28:16 +0200 (Mon, 12 Jul 2010)

Log Message:
-----------
[#22824] OpenEXR Save from byte buffer bug
- Saving a typical byte buffer as an exr wasnt converting into linear colorspace.
- Remove checks for 1 and 2 channel images, these will write as RGB anyway and are very rare.
- 3 Channel images were having the alpha channel written from the red color channel, write 1.0 instead.

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	2010-07-12 11:17:42 UTC (rev 30222)
+++ trunk/blender/source/blender/imbuf/intern/openexr/openexr_api.cpp	2010-07-12 11:28:16 UTC (rev 30223)
@@ -46,6 +46,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_math_color.h"
 
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
@@ -236,29 +237,46 @@
 				for (int j = ibuf->x; j > 0; j--) 
 				{
 					to->r = from[0];
-					to->g = (channels >= 2)? from[1]: from[0];
-					to->b = (channels >= 3)? from[2]: from[0];
-					to->a = (channels >= 4)? from[3]: from[0];
+					to->g = from[1];
+					to->b = from[2];
+					to->a = (channels >= 4)? from[3]: 1.0f;
 					to++; from += 4;
 				}
 			}
 		}
 		else {
 			unsigned char *from;
-			
-			for (int i = ibuf->y-1; i >= 0; i--) 
-			{
-				from= (unsigned char *)ibuf->rect + channels*i*width;
-				
-				for (int j = ibuf->x; j > 0; j--) 
+
+			if(ibuf->profile != IB_PROFILE_NONE) {
+				for (int i = ibuf->y-1; i >= 0; i--)
 				{
-					to->r = (float)(from[0])/255.0;
-					to->g = (float)((channels >= 2)? from[1]: from[0])/255.0;
-					to->b = (float)((channels >= 3)? from[2]: from[0])/255.0;
-					to->a = (float)((channels >= 4)? from[3]: from[0])/255.0;
-					to++; from += 4;
+					from= (unsigned char *)ibuf->rect + channels*i*width;
+
+					for (int j = ibuf->x; j > 0; j--)
+					{
+						to->r = (float)(from[0])/255.0;
+						to->g = (float)(from[1])/255.0;
+						to->b = (float)(from[2])/255.0;
+						to->a = (float)(channels >= 4) ? from[3]/255.0 : 1.0f;
+						to++; from += 4;
+					}
 				}
 			}
+			else {
+				for (int i = ibuf->y-1; i >= 0; i--)
+				{
+					from= (unsigned char *)ibuf->rect + channels*i*width;
+
+					for (int j = ibuf->x; j > 0; j--)
+					{
+						to->r = srgb_to_linearrgb((float)from[0] / 255.0);
+						to->g = srgb_to_linearrgb((float)from[1] / 255.0);
+						to->b = srgb_to_linearrgb((float)from[2] / 255.0);
+						to->a = channels >= 4 ? (float)from[3]/255.0 : 1.0f;
+						to++; from += 4;
+					}
+				}
+			}
 		}
 		
 //		printf("OpenEXR-save: Writing OpenEXR file of height %d.\n", height);
@@ -308,9 +326,9 @@
 		float *rect[4] = {NULL, NULL, NULL, NULL};
 
 		rect[0]= ibuf->rect_float + channels*(height-1)*width;
-		rect[1]= (channels >= 2)? rect[0]+1: rect[0];
-		rect[2]= (channels >= 3)? rect[0]+2: rect[0];
-		rect[3]= (channels >= 4)? rect[0]+3: rect[0];
+		rect[1]= rect[0]+1;
+		rect[2]= rect[0]+2;
+		rect[3]= (channels >= 4)? rect[0]+3: 1.0f;
 
 		frameBuffer.insert ("R", Slice (FLOAT,  (char *)rect[0], xstride, ystride));
 		frameBuffer.insert ("G", Slice (FLOAT,  (char *)rect[1], xstride, ystride));





More information about the Bf-blender-cvs mailing list