[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25846] trunk/blender/source/blender: Color management fixes

Matt Ebb matt at mke3.net
Sat Jan 9 01:16:36 CET 2010


Revision: 25846
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25846
Author:   broken
Date:     2010-01-09 01:16:35 +0100 (Sat, 09 Jan 2010)

Log Message:
-----------
Color management fixes

Now it's a bit more robust, tagging images with profiles when they're loaded, 
which then get interpreted later on by conversion functions. Just Linear RGB 
and sRGB profiles at the moment, same as before.

This commit fixes Martin's problem with EXRs and Multilayer images loading/
saving too dark, and it also makes the sequence editor work correctly with it too.

Also fixes:
[#19647] gamma correction with color management is reset when resetting Curve
[#19454] 2.5: Dither does not work when Color management is enabled

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/colortools.c
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/blenkernel/intern/sequencer.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/space_image/image_draw.c
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c
    trunk/blender/source/blender/imbuf/intern/amiga.c
    trunk/blender/source/blender/imbuf/intern/bmp.c
    trunk/blender/source/blender/imbuf/intern/dds/dds_api.cpp
    trunk/blender/source/blender/imbuf/intern/divers.c
    trunk/blender/source/blender/imbuf/intern/hamx.c
    trunk/blender/source/blender/imbuf/intern/iris.c
    trunk/blender/source/blender/imbuf/intern/jpeg.c
    trunk/blender/source/blender/imbuf/intern/openexr/openexr_api.cpp
    trunk/blender/source/blender/imbuf/intern/png.c
    trunk/blender/source/blender/imbuf/intern/radiance_hdr.c
    trunk/blender/source/blender/imbuf/intern/readimage.c
    trunk/blender/source/blender/imbuf/intern/targa.c
    trunk/blender/source/blender/imbuf/intern/tiff.c
    trunk/blender/source/blender/makesrna/intern/rna_scene.c
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_image.c

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h	2010-01-09 00:16:35 UTC (rev 25846)
@@ -143,6 +143,9 @@
 struct RenderResult *BKE_image_acquire_renderresult(struct Scene *scene, struct Image *ima);
 void BKE_image_release_renderresult(struct Scene *scene, struct Image *ima);
 
+/* frees all ibufs used by any image datablocks */
+void	BKE_image_free_image_ibufs(void);
+	
 /* goes over all textures that use images */
 void	BKE_image_free_all_textures(void);
 

Modified: trunk/blender/source/blender/blenkernel/intern/colortools.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/colortools.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/blenkernel/intern/colortools.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -763,10 +763,16 @@
 	}
 }
 
-
+/* only used for image editor curves */
 void curvemapping_do_ibuf(CurveMapping *cumap, ImBuf *ibuf)
 {
+	ImBuf *tmpbuf;
 	int pixel;
+	char *tmpcbuf;
+	float *pix_in;
+	float col[3];
+	int stride= 4;
+	float *pix_out;
 	
 	if(ibuf==NULL)
 		return;
@@ -775,35 +781,45 @@
 	else if(ibuf->rect==NULL)
 		imb_addrectImBuf(ibuf);
 	
+	if (!ibuf->rect || !ibuf->rect_float)
+		return;
+	
+	/* work on a temp buffer, so can color manage afterwards.
+	 * No worse off memory wise than comp nodes */
+	tmpbuf = IMB_dupImBuf(ibuf);
+	
 	curvemapping_premultiply(cumap, 0);
 	
-	if(ibuf->rect_float && ibuf->rect) {
-		float *pixf= ibuf->rect_float;
-		float col[3];
-		int stride= 4;
-		char *pixc= (char *)ibuf->rect;
-		
-		if(ibuf->channels)
-			stride= ibuf->channels;
-		
-		for(pixel= ibuf->x*ibuf->y; pixel>0; pixel--, pixf+=stride, pixc+=4) {
-			if(stride<3) {
-				col[0]= curvemap_evaluateF(cumap->cm, *pixf);
-				pixc[1]= pixc[2]= pixc[3]= pixc[0]= FTOCHAR(col[0]);
-			}
-			else {
-				curvemapping_evaluate_premulRGBF(cumap, col, pixf);
-				pixc[0]= FTOCHAR(col[0]);
-				pixc[1]= FTOCHAR(col[1]);
-				pixc[2]= FTOCHAR(col[2]);
-				if(stride>3)
-					pixc[3]= FTOCHAR(pixf[3]);
-				else
-					pixc[3]= 255;
-			}
+	pix_in= ibuf->rect_float;
+	pix_out= tmpbuf->rect_float;
+//	pixc= (char *)ibuf->rect;
+	
+	if(ibuf->channels)
+		stride= ibuf->channels;
+	
+	for(pixel= ibuf->x*ibuf->y; pixel>0; pixel--, pix_in+=stride, pix_out+=4) {
+		if(stride<3) {
+			col[0]= curvemap_evaluateF(cumap->cm, *pix_in);
+			
+			pix_out[1]= pix_out[2]= pix_out[3]= pix_out[0]= col[0];
 		}
+		else {
+			curvemapping_evaluate_premulRGBF(cumap, col, pix_in);
+			pix_out[0]= col[0];
+			pix_out[1]= col[1];
+			pix_out[2]= col[2];
+			if(stride>3)
+				pix_out[3]= pix_in[3];
+			else
+				pix_out[3]= 1.f;
+		}
 	}
 	
+	IMB_rect_from_float(tmpbuf);
+	SWAP(char *, tmpbuf->rect, ibuf->rect);
+	IMB_freeImBuf(tmpbuf);
+	
+	
 	curvemapping_premultiply(cumap, 1);
 }
 

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -725,6 +725,17 @@
 	}
 }
 
+/* frees all ibufs used by any image datablocks */
+void BKE_image_free_image_ibufs(void)
+{
+	Image *ima;
+	
+	for(ima= G.main->image.first; ima; ima= ima->id.next) {
+		image_free_buffers(ima);
+	}
+	
+}
+
 void BKE_image_free_all_textures(void)
 {
 	Tex *tex;
@@ -1898,6 +1909,7 @@
 			ibuf->rect_float= rpass->rect;
 			ibuf->flags |= IB_rectfloat;
 			ibuf->channels= rpass->channels;
+			ibuf->profile = IB_PROFILE_LINEAR_RGB;
 
 			image_assign_ibuf(ima, ibuf, iuser?iuser->multi_index:IMA_NO_INDEX, 0);
 		}

Modified: trunk/blender/source/blender/blenkernel/intern/sequencer.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/sequencer.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/blenkernel/intern/sequencer.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -1694,7 +1694,19 @@
 
 	if(seq->flag & SEQ_MAKE_FLOAT) {
 		if (!se->ibuf->rect_float) {
-			IMB_float_from_rect(se->ibuf);
+			if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) {
+				IMB_float_from_rect(se->ibuf);
+			} else {
+				int profile = IB_PROFILE_NONE;
+				
+				/* no color management:
+				 * don't disturb the existing profiles */
+				SWAP(int, se->ibuf->profile, profile);
+
+				IMB_float_from_rect(se->ibuf);
+				
+				SWAP(int, se->ibuf->profile, profile);
+			}
 		}
 		if (se->ibuf->rect) {
 			imb_freerectImBuf(se->ibuf);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -4081,10 +4081,17 @@
 
 		s->clonecanvas= ibuf;
 
+		/* temporarily add float rect for cloning */
 		if(s->canvas->rect_float && !s->clonecanvas->rect_float) {
-			/* temporarily add float rect for cloning */
+			int profile = IB_PROFILE_NONE;
+			
+			/* Don't want to color manage, but don't disturb existing profiles */
+			SWAP(int, s->clonecanvas->profile, profile);
+
 			IMB_float_from_rect(s->clonecanvas);
 			s->clonefreefloat= 1;
+			
+			SWAP(int, s->clonecanvas->profile, profile);
 		}
 		else if(!s->canvas->rect_float && !s->clonecanvas->rect)
 			IMB_rect_from_float(s->clonecanvas);

Modified: trunk/blender/source/blender/editors/space_image/image_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_draw.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/editors/space_image/image_draw.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -126,7 +126,7 @@
 			else {
 				if (color_manage) {
 						if (ima && ima->source == IMA_SRC_VIEWER)
-							ibuf->profile = IB_PROFILE_SRGB;
+							ibuf->profile = IB_PROFILE_LINEAR_RGB;
 				} else {
 					ibuf->profile = IB_PROFILE_NONE;
 				}

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -1269,7 +1269,7 @@
 			
 			if(!ibuf->rect) {
 				if(color_manage)
-					ibuf->profile= IB_PROFILE_SRGB;
+					ibuf->profile = IB_PROFILE_LINEAR_RGB;
 				else
 					ibuf->profile = IB_PROFILE_NONE;
 				IMB_rect_from_float(ibuf);

Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -699,8 +699,14 @@
 		break;
 	}
 
-	if(ibuf->rect_float && ibuf->rect==NULL)
-		IMB_rect_from_float(ibuf);
+	if(ibuf->rect_float && ibuf->rect==NULL) {
+		if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) {
+			ibuf->profile = IB_PROFILE_LINEAR_RGB;
+		} else {
+			ibuf->profile = IB_PROFILE_NONE;
+		}
+		IMB_rect_from_float(ibuf);	
+	}
 	
 	/* needed for gla draw */
 	glaDefine2DArea(&ar->winrct);

Modified: trunk/blender/source/blender/imbuf/intern/amiga.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/amiga.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/imbuf/intern/amiga.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -452,6 +452,7 @@
 	if (ibuf == 0) return (0);
 
 	ibuf->ftype = (ftype | AMI);
+	ibuf->profile = IB_PROFILE_SRGB;
 	
 	if (cmap){
 		ibuf->mincol = 0;

Modified: trunk/blender/source/blender/imbuf/intern/bmp.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/bmp.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/imbuf/intern/bmp.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -175,6 +175,7 @@
 
 	if (ibuf) {
 		ibuf->ftype = BMP;
+		ibuf->profile = IB_PROFILE_SRGB;
 	}
 	
 	return(ibuf);

Modified: trunk/blender/source/blender/imbuf/intern/dds/dds_api.cpp
===================================================================
--- trunk/blender/source/blender/imbuf/intern/dds/dds_api.cpp	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/imbuf/intern/dds/dds_api.cpp	2010-01-09 00:16:35 UTC (rev 25846)
@@ -101,6 +101,7 @@
 	if (ibuf == 0) return(0); /* memory allocation failed */
 
 	ibuf->ftype = DDS;
+	ibuf->profile = IB_PROFILE_SRGB;
 
 	if ((flags & IB_test) == 0) {
 		if (!imb_addrectImBuf(ibuf)) return(ibuf);

Modified: trunk/blender/source/blender/imbuf/intern/divers.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/divers.c	2010-01-08 20:55:13 UTC (rev 25845)
+++ trunk/blender/source/blender/imbuf/intern/divers.c	2010-01-09 00:16:35 UTC (rev 25846)
@@ -175,12 +175,14 @@
 }
 
 
+/* assume converting from linear float to sRGB byte */
 void IMB_rect_from_float(struct ImBuf *ibuf)
 {
 	/* quick method to convert floatbuf to byte */
 	float *tof = (float *)ibuf->rect_float;
-	float dither= ibuf->dither;
-	float srgb[3];
+	int do_dither = ibuf->dither != 0.f;
+	float dither= ibuf->dither / 255.0;
+	float srgb[4];
 	int i, channels= ibuf->channels;
 	short profile= ibuf->profile;
 	unsigned char *to = (unsigned char *) ibuf->rect;
@@ -195,7 +197,7 @@
 		for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof++)
 			to[1]= to[2]= to[3]= to[0] = FTOCHAR(tof[0]);
 	}
-	else if (profile == IB_PROFILE_SRGB) {
+	else if (profile == IB_PROFILE_LINEAR_RGB) {
 		if(channels == 3) {
 			for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=3) {
 				srgb[0]= linearrgb_to_srgb(tof[0]);
@@ -209,10 +211,26 @@
 			}
 		}
 		else if (channels == 4) {
-			floatbuf_to_srgb_byte(tof, to, 0, ibuf->x, 0, ibuf->y, ibuf->x);
+			if (dither != 0.f) {
+				for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=4) {
+					const float d = (BLI_frand()-0.5)*dither;
+					

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list