[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31994] trunk/blender/source/blender/nodes /intern/CMP_nodes/CMP_image.c: bugfix [#23706] SEGFAULT: File Load of EXR

Campbell Barton ideasman42 at gmail.com
Sat Sep 18 09:19:33 CEST 2010


Revision: 31994
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31994
Author:   campbellbarton
Date:     2010-09-18 09:19:32 +0200 (Sat, 18 Sep 2010)

Log Message:
-----------
bugfix [#23706] SEGFAULT: File Load of EXR
image node was modifying the original buffer color management, now only modify a copy.

Modified Paths:
--------------
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_image.c

Modified: trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_image.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_image.c	2010-09-18 04:24:04 UTC (rev 31993)
+++ trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_image.c	2010-09-18 07:19:32 UTC (rev 31994)
@@ -62,38 +62,55 @@
 	ImBuf *ibuf;
 	CompBuf *stackbuf;
 	int type;
-	
+
+	float *rect;
+	int alloc= FALSE;
+
 	ibuf= BKE_image_get_ibuf(ima, iuser);
-	if(ibuf==NULL)
+	if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) {
 		return NULL;
+	}
 
-	if (!(rd->color_mgt_flag & R_COLOR_MANAGEMENT)) {
-		int profile = IB_PROFILE_NONE;
-		
-		/* temporarily set profile to none to not disturb actual */
-		SWAP(int, ibuf->profile, profile);
-		
-		if (ibuf->rect_float != NULL) {
-			imb_freerectfloatImBuf(ibuf);
-		}
-		IMB_float_from_rect(ibuf);
-		
-		SWAP(int, ibuf->profile, profile);
-	}
-	
 	if (ibuf->rect_float == NULL) {
 		IMB_float_from_rect(ibuf);
 	}
 
+	/* now we need a float buffer from the image
+	 * with matching color management */
+	if(rd->color_mgt_flag & R_COLOR_MANAGEMENT) {
+		if(ibuf->profile == IB_PROFILE_LINEAR_RGB) {
+			rect= ibuf->rect_float;
+		}
+		else {
+			rect= MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
+			srgb_to_linearrgb_rgba_rgba_buf(rect, ibuf->rect_float, ibuf->x * ibuf->y);
+			alloc= TRUE;
+		}
+	}
+	else {
+		if(ibuf->profile != IB_PROFILE_LINEAR_RGB) {
+			rect= ibuf->rect_float;
+		}
+		else {
+			rect= MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
+			linearrgb_to_srgb_rgba_rgba_buf(rect, ibuf->rect_float, ibuf->x * ibuf->y);
+			alloc= TRUE;
+		}
+	}
+	/* done coercing into the correct color management */
+
+
 	type= ibuf->channels;
 	
 	if(rd->scemode & R_COMP_CROP) {
-		stackbuf= get_cropped_compbuf(&rd->disprect, ibuf->rect_float, ibuf->x, ibuf->y, type);
+		stackbuf= get_cropped_compbuf(&rd->disprect, rect, ibuf->x, ibuf->y, type);
+		if(alloc)
+			MEM_freeN(rect);
 	}
 	else {
 		/* we put imbuf copy on stack, cbuf knows rect is from other ibuf when freed! */
-		stackbuf= alloc_compbuf(ibuf->x, ibuf->y, type, 0);
-		stackbuf->rect= ibuf->rect_float;
+		stackbuf= alloc_compbuf(ibuf->x, ibuf->y, type, alloc);
+		stackbuf->rect= rect;
 	}
 	
 	/*code to respect the premul flag of images; I'm





More information about the Bf-blender-cvs mailing list