[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31592] trunk/blender/source/blender: fix for dark images from the sequencer when color management is disabled.

Campbell Barton ideasman42 at gmail.com
Thu Aug 26 11:12:10 CEST 2010


Revision: 31592
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31592
Author:   campbellbarton
Date:     2010-08-26 11:12:10 +0200 (Thu, 26 Aug 2010)

Log Message:
-----------
fix for dark images from the sequencer when color management is disabled.
the render engine assumes the RenderResult's rectf is not in linear color space when color management is disabled so the sequencer and opengl render need to follow this else it results in dark images.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/editors/render/render_opengl.c
    trunk/blender/source/blender/render/intern/source/pipeline.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2010-08-26 08:04:58 UTC (rev 31591)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2010-08-26 09:12:10 UTC (rev 31592)
@@ -75,6 +75,12 @@
 float linearrgb_to_srgb(float c);
 void srgb_to_linearrgb_v3_v3(float *col_to, float *col_from);
 void linearrgb_to_srgb_v3_v3(float *col_to, float *col_from);
+
+/* rgba buffer convenience functions */
+void srgb_to_linearrgb_rgba_buf(float *col, int tot);
+void linearrgb_to_srgb_rgba_buf(float *col, int tot);
+void srgb_to_linearrgb_rgba_rgba_buf(float *col_to, float *col_from, int tot);
+void linearrgb_to_srgb_rgba_rgba_buf(float *col_to, float *col_from, int tot);
 	
 /************************** Other *************************/
 

Modified: trunk/blender/source/blender/blenlib/intern/math_color.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color.c	2010-08-26 08:04:58 UTC (rev 31591)
+++ trunk/blender/source/blender/blenlib/intern/math_color.c	2010-08-26 09:12:10 UTC (rev 31592)
@@ -372,7 +372,41 @@
 	col_to[2] = linearrgb_to_srgb(col_from[2]);
 }
 
+/* todo, should these be moved elsewhere?, they dont belong in imbuf */
+void srgb_to_linearrgb_rgba_buf(float *col, int tot)
+{
+	while(tot--) {
+		srgb_to_linearrgb_v3_v3(col, col);
+		col += 4;
+	}
+}
 
+void linearrgb_to_srgb_rgba_buf(float *col, int tot)
+{
+	while(tot--) {
+		linearrgb_to_srgb_v3_v3(col, col);
+		col += 4;
+	}
+}
+
+void srgb_to_linearrgb_rgba_rgba_buf(float *col_to, float *col_from, int tot)
+{
+	while(tot--) {
+		srgb_to_linearrgb_v3_v3(col_to, col_from);
+		col_to += 4;
+		col_from += 4;
+	}
+}
+
+void linearrgb_to_srgb_rgba_rgba_buf(float *col_to, float *col_from, int tot)
+{
+	while(tot--) {
+		linearrgb_to_srgb_v3_v3(col_to, col_from);
+		col_to += 4;
+		col_from += 4;
+	}
+}
+
 void minmax_rgb(short c[])
 {
 	if(c[0]>255) c[0]=255;

Modified: trunk/blender/source/blender/editors/render/render_opengl.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_opengl.c	2010-08-26 08:04:58 UTC (rev 31591)
+++ trunk/blender/source/blender/editors/render/render_opengl.c	2010-08-26 09:12:10 UTC (rev 31592)
@@ -116,6 +116,17 @@
 
 	rr= RE_AcquireResultRead(oglrender->re);
 	
+	/* note on color management:
+	 * looked into how best to deal with color management here and found heres how it should work.
+	 *
+	 * OpenGL materials etc are color corrected, so a float buffer from the graphics card is
+	 * color corrected, without running any conversion functions.
+	 * 
+	 * With color correction disabled blender expects the rr->rectf to be non-color managed so
+	 * just do a direct copy from the byte array to the rectf with no conversion too.
+	 * notice IMB_float_from_rect has the profile set so no conversion is done.
+	 */
+
 	if(view_context) {
 		GPU_offscreen_bind(oglrender->ofs); /* bind */
 
@@ -134,6 +145,7 @@
 	}
 	else {
 		ImBuf *ibuf_view= ED_view3d_draw_offscreen_imbuf_simple(scene, oglrender->sizex, oglrender->sizey, OB_SOLID);
+		ibuf_view->profile = IB_PROFILE_NONE; /* ensures no conversion!, see note above */
 		IMB_float_from_rect(ibuf_view);
 
 		memcpy(rr->rectf, ibuf_view->rect_float, sizeof(float) * 4 * oglrender->sizex * oglrender->sizey);

Modified: trunk/blender/source/blender/render/intern/source/pipeline.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/pipeline.c	2010-08-26 08:04:58 UTC (rev 31591)
+++ trunk/blender/source/blender/render/intern/source/pipeline.c	2010-08-26 09:12:10 UTC (rev 31592)
@@ -2473,21 +2473,22 @@
 		if(ibuf->rect_float) {
 			if (!rr->rectf)
 				rr->rectf= MEM_mallocN(4*sizeof(float)*rr->rectx*rr->recty, "render_seq rectf");
-
-			memcpy(rr->rectf, ibuf->rect_float, 4*sizeof(float)*rr->rectx*rr->recty);
-
-			/* sequencer float buffer is not in linear color space, convert
-			 * should always be true, use a fake ibuf for the colorspace conversion */
-			if(ibuf->profile != IB_PROFILE_LINEAR_RGB) {
-				ImBuf ibuf_dummy;
-				memset(&ibuf_dummy, 0, sizeof(ImBuf));
-				ibuf_dummy.profile= ibuf->profile;
-				ibuf_dummy.x= rr->rectx;
-				ibuf_dummy.y= rr->recty;
-				ibuf_dummy.rect_float= rr->rectf;
-				/* only touch the rr->rectf */
-				IMB_convert_profile(&ibuf_dummy, IB_PROFILE_LINEAR_RGB);
+			
+			/* color management: when off ensure rectf is non-lin, since thats what the internal
+			 * render engine delivers */
+			if(re->r.color_mgt_flag & R_COLOR_MANAGEMENT) {
+				if(ibuf->profile == IB_PROFILE_LINEAR_RGB)
+					memcpy(rr->rectf, ibuf->rect_float, 4*sizeof(float)*rr->rectx*rr->recty);
+				else
+					srgb_to_linearrgb_rgba_rgba_buf(rr->rectf, ibuf->rect_float, rr->rectx*rr->recty);
+					
 			}
+			else {
+				if(ibuf->profile != IB_PROFILE_LINEAR_RGB)
+					memcpy(rr->rectf, ibuf->rect_float, 4*sizeof(float)*rr->rectx*rr->recty);
+				else
+					linearrgb_to_srgb_rgba_rgba_buf(rr->rectf, ibuf->rect_float, rr->rectx*rr->recty);
+			}
 			
 			/* TSK! Since sequence render doesn't free the *rr render result, the old rect32
 			   can hang around when sequence render has rendered a 32 bits one before */





More information about the Bf-blender-cvs mailing list