[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50800] trunk/blender/source/blender: Color Management: different fixes for byte buffers

Sergey Sharybin sergey.vfx at gmail.com
Fri Sep 21 22:44:45 CEST 2012


Revision: 50800
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50800
Author:   nazgul
Date:     2012-09-21 20:44:41 +0000 (Fri, 21 Sep 2012)
Log Message:
-----------
Color Management: different fixes for byte buffers

- Color space of byte buffer for generated images haven't been
  updated properly on change

- Byte buffers weren't handling data color spaces on display transform
  properly

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/imbuf/IMB_colormanagement.h
    trunk/blender/source/blender/imbuf/intern/colormanagement.c
    trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2012-09-21 17:56:16 UTC (rev 50799)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2012-09-21 20:44:41 UTC (rev 50800)
@@ -603,7 +603,8 @@
 	return BKE_image_load(filepath);
 }
 
-static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, float color[4])
+static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type,
+                            float color[4], const char *colorspace)
 {
 	ImBuf *ibuf;
 	unsigned char *rect = NULL;
@@ -616,6 +617,9 @@
 	else {
 		ibuf = IMB_allocImBuf(width, height, depth, IB_rect);
 		rect = (unsigned char *)ibuf->rect;
+
+		if (colorspace)
+			IMB_colormanagement_assign_rect_colorspace(ibuf, colorspace);
 	}
 
 	BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
@@ -651,7 +655,7 @@
 		ima->gen_type = gen_type;
 		ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0);
 
-		ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, gen_type, color);
+		ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, gen_type, color, NULL);
 		image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
 
 		/* assign colorspaces */
@@ -2793,7 +2797,8 @@
 				/* UV testgrid or black or solid etc */
 				if (ima->gen_x == 0) ima->gen_x = 1024;
 				if (ima->gen_y == 0) ima->gen_y = 1024;
-				ibuf = add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 24, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type, color);
+				ibuf = add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 24, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type,
+				                     color, ima->colorspace_settings.name);
 				image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
 				ima->ok = IMA_OK_LOADED;
 			}

Modified: trunk/blender/source/blender/imbuf/IMB_colormanagement.h
===================================================================
--- trunk/blender/source/blender/imbuf/IMB_colormanagement.h	2012-09-21 17:56:16 UTC (rev 50799)
+++ trunk/blender/source/blender/imbuf/IMB_colormanagement.h	2012-09-21 20:44:41 UTC (rev 50800)
@@ -62,6 +62,7 @@
                                            struct ColorManagedViewSettings *view_settings);
 
 const char *IMB_colormanagement_role_colorspace_name_get(int role);
+void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char *name);
 
 /* ** Color space transformation functions ** */
 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,

Modified: trunk/blender/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/colormanagement.c	2012-09-21 17:56:16 UTC (rev 50799)
+++ trunk/blender/source/blender/imbuf/intern/colormanagement.c	2012-09-21 20:44:41 UTC (rev 50800)
@@ -847,16 +847,17 @@
 
 void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace)
 {
+	ColorSpace *colorspace = colormanage_colorspace_get_named(from_colorspace);
+
+	if (colorspace->is_data) {
+		ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
+		return;
+	}
+
 	if (ibuf->rect_float) {
-		ColorSpace *colorspace = colormanage_colorspace_get_named(from_colorspace);
 		const char *to_colorspace = global_role_scene_linear;
 		int predivide = ibuf->flags & IB_cm_predivide;
 
-		if (colorspace->is_data) {
-			ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
-			return;
-		}
-
 		if (ibuf->rect)
 			imb_freerectImBuf(ibuf);
 
@@ -1038,6 +1039,17 @@
 	return NULL;
 }
 
+void IMB_colormanagement_assign_rect_colorspace(ImBuf *ibuf, const char *name)
+{
+	ColorSpace *colorspace = colormanage_colorspace_get_named(name);
+	ibuf->rect_colorspace = colorspace;
+
+	if (colorspace->is_data)
+		ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
+	else
+		ibuf->colormanage_flag &= ~IMB_COLORMANAGE_IS_DATA;
+}
+
 /*********************** Threaded display buffer transform routines *************************/
 
 typedef struct DisplayBufferThread {
@@ -1132,6 +1144,7 @@
 	int buffer_size = channels * width * height;
 
 	int predivide = handle->predivide;
+	int is_data = handle->is_data;
 
 	linear_buffer = MEM_callocN(buffer_size * sizeof(float), "color conversion linear buffer");
 
@@ -1153,9 +1166,11 @@
 			*fp = (float)(*cp) / 255.0f;
 		}
 
-		/* convert float buffer to scene linear space */
-		IMB_colormanagement_transform(linear_buffer, width, height, channels,
-		                              from_colorspace, to_colorspace, predivide);
+		if (!is_data) {
+			/* convert float buffer to scene linear space */
+			IMB_colormanagement_transform(linear_buffer, width, height, channels,
+			                              from_colorspace, to_colorspace, predivide);
+		}
 	}
 	else if (handle->float_colorspace) {
 		/* currently float is non-linear only in sequencer, which is working

Modified: trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c	2012-09-21 17:56:16 UTC (rev 50799)
+++ trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c	2012-09-21 20:44:41 UTC (rev 50800)
@@ -144,15 +144,15 @@
 	
 	ED_spacetypes_init();   /* editors/space_api/spacetype.c */
 	
+	/* initialize color management stuff */
+	IMB_colormanagement_init();
+
 	ED_file_init();         /* for fsmenu */
 	ED_node_init_butfuncs();
 	
 	BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
 	BLF_lang_init();
 
-	/* initialize color management stuff */
-	IMB_colormanagement_init();
-
 	/* get the default database, plus a wm */
 	WM_homefile_read(C, NULL, G.factory_startup);
 




More information about the Bf-blender-cvs mailing list