[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50745] trunk/blender: Color Management: don't apply display transform on Non-Color images

Sergey Sharybin sergey.vfx at gmail.com
Wed Sep 19 17:01:37 CEST 2012


Revision: 50745
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50745
Author:   nazgul
Date:     2012-09-19 15:01:36 +0000 (Wed, 19 Sep 2012)
Log Message:
-----------
Color Management: don't apply display transform on Non-Color images

Also don't color manage data buffers in texture painting.

Makes it possible to view heights and normal maps in proper space
and also paint on them without applying extra transformation.

Modified Paths:
--------------
    trunk/blender/intern/opencolorio/ocio_capi.cpp
    trunk/blender/intern/opencolorio/ocio_capi.h
    trunk/blender/intern/opencolorio/ocio_capi_stub.cpp
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/imbuf/IMB_imbuf_types.h
    trunk/blender/source/blender/imbuf/intern/IMB_colormanagement_intern.h
    trunk/blender/source/blender/imbuf/intern/colormanagement.c

Modified: trunk/blender/intern/opencolorio/ocio_capi.cpp
===================================================================
--- trunk/blender/intern/opencolorio/ocio_capi.cpp	2012-09-19 12:43:39 UTC (rev 50744)
+++ trunk/blender/intern/opencolorio/ocio_capi.cpp	2012-09-19 15:01:36 UTC (rev 50745)
@@ -302,6 +302,11 @@
 	return true;
 }
 
+int OCIO_colorSpaceIsData(ConstColorSpaceRcPtr *cs)
+{
+	return ((*cs)->isData());
+}
+
 void OCIO_colorSpaceRelease(ConstColorSpaceRcPtr *cs)
 {
 	MEM_DELETE(cs, ConstColorSpaceRcPtr);

Modified: trunk/blender/intern/opencolorio/ocio_capi.h
===================================================================
--- trunk/blender/intern/opencolorio/ocio_capi.h	2012-09-19 12:43:39 UTC (rev 50744)
+++ trunk/blender/intern/opencolorio/ocio_capi.h	2012-09-19 15:01:36 UTC (rev 50745)
@@ -73,6 +73,7 @@
 int OCIO_configGetIndexForColorSpace(ConstConfigRcPtr *config, const char *name);
 
 int OCIO_colorSpaceIsInvertible(ConstColorSpaceRcPtr *cs);
+int OCIO_colorSpaceIsData(ConstColorSpaceRcPtr *cs);
 
 void OCIO_colorSpaceRelease(ConstColorSpaceRcPtr *cs);
 

Modified: trunk/blender/intern/opencolorio/ocio_capi_stub.cpp
===================================================================
--- trunk/blender/intern/opencolorio/ocio_capi_stub.cpp	2012-09-19 12:43:39 UTC (rev 50744)
+++ trunk/blender/intern/opencolorio/ocio_capi_stub.cpp	2012-09-19 15:01:36 UTC (rev 50745)
@@ -174,6 +174,11 @@
 	return 1;
 }
 
+int OCIO_colorSpaceIsData(ConstColorSpaceRcPtr *cs)
+{
+	return 0;
+}
+
 void OCIO_colorSpaceRelease(ConstColorSpaceRcPtr *cs)
 {
 }

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2012-09-19 12:43:39 UTC (rev 50744)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2012-09-19 15:01:36 UTC (rev 50745)
@@ -4596,10 +4596,13 @@
 {
 	ImBuf *ibuf = BKE_image_get_ibuf(image, s->sima ? &s->sima->iuser : NULL);
 	float pos[2];
+	int is_data;
 
 	if (!ibuf)
 		return 0;
 
+	is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
+
 	pos[0] = uv[0] * ibuf->x;
 	pos[1] = uv[1] * ibuf->y;
 
@@ -4608,7 +4611,7 @@
 	/* OCIO_TODO: float buffers are now always linear, so always use color correction
 	 *            this should probably be changed when texture painting color space is supported
 	 */
-	if (BKE_brush_painter_paint(painter, imapaint_paint_op, pos, time, pressure, s, TRUE)) {
+	if (BKE_brush_painter_paint(painter, imapaint_paint_op, pos, time, pressure, s, is_data == FALSE)) {
 		if (update)
 			imapaint_image_update(s->scene, s->sima, image, ibuf, texpaint);
 		return 1;

Modified: trunk/blender/source/blender/imbuf/IMB_imbuf_types.h
===================================================================
--- trunk/blender/source/blender/imbuf/IMB_imbuf_types.h	2012-09-19 12:43:39 UTC (rev 50744)
+++ trunk/blender/source/blender/imbuf/IMB_imbuf_types.h	2012-09-19 15:01:36 UTC (rev 50745)
@@ -131,6 +131,7 @@
 	struct ColorSpace *float_colorspace;         /* color space of float buffer, used by sequencer only */
 	unsigned int *display_buffer_flags;          /* array of per-display display buffers dirty flags */
 	struct ColormanageCache *colormanage_cache;  /* cache used by color management */
+	int colormanage_flag;
 
 	/* information for compressed textures */
 	struct DDSData dds_data;
@@ -260,4 +261,8 @@
 extern const char *imb_ext_movie[];
 extern const char *imb_ext_audio[];
 
+enum {
+	IMB_COLORMANAGE_IS_DATA = (1 << 0)
+};
+
 #endif

Modified: trunk/blender/source/blender/imbuf/intern/IMB_colormanagement_intern.h
===================================================================
--- trunk/blender/source/blender/imbuf/intern/IMB_colormanagement_intern.h	2012-09-19 12:43:39 UTC (rev 50744)
+++ trunk/blender/source/blender/imbuf/intern/IMB_colormanagement_intern.h	2012-09-19 15:01:36 UTC (rev 50745)
@@ -48,6 +48,7 @@
 	struct ConstProcessorRcPtr *from_scene_linear;
 
 	int is_invertible;
+	int is_data;
 } ColorSpace;
 
 typedef struct ColorManagedDisplay {
@@ -79,7 +80,7 @@
 struct ColorManagedView *colormanage_view_get_indexed(int index);
 struct ColorManagedView *colormanage_view_get_named(const char *name);
 
-struct ColorSpace *colormanage_colorspace_add(const char *name, const char *description, int is_invertible);
+struct ColorSpace *colormanage_colorspace_add(const char *name, const char *description, int is_invertible, int is_data);
 struct ColorSpace *colormanage_colorspace_get_named(const char *name);
 struct ColorSpace *colormanage_colorspace_get_roled(int role);
 struct ColorSpace *colormanage_colorspace_get_indexed(int index);

Modified: trunk/blender/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/colormanagement.c	2012-09-19 12:43:39 UTC (rev 50744)
+++ trunk/blender/source/blender/imbuf/intern/colormanagement.c	2012-09-19 15:01:36 UTC (rev 50745)
@@ -450,15 +450,16 @@
 	for (index = 0 ; index < tot_colorspace; index++) {
 		ConstColorSpaceRcPtr *ocio_colorspace;
 		const char *description;
-		int is_invertible;
+		int is_invertible, is_data;
 
 		name = OCIO_configGetColorSpaceNameByIndex(config, index);
 
 		ocio_colorspace = OCIO_configGetColorSpace(config, name);
 		description = OCIO_colorSpaceGetDescription(ocio_colorspace);
 		is_invertible = OCIO_colorSpaceIsInvertible(ocio_colorspace);
+		is_data = OCIO_colorSpaceIsData(ocio_colorspace);
 
-		colormanage_colorspace_add(name, description, is_invertible);
+		colormanage_colorspace_add(name, description, is_invertible, is_data);
 
 		OCIO_colorSpaceRelease(ocio_colorspace);
 	}
@@ -847,9 +848,15 @@
 void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace)
 {
 	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);
 
@@ -1049,6 +1056,7 @@
 	int channels;
 	float dither;
 	int predivide;
+	int is_data;
 
 	const char *byte_colorspace;
 	const char *float_colorspace;
@@ -1078,6 +1086,7 @@
 	int predivide = ibuf->flags & IB_cm_predivide;
 	int channels = ibuf->channels;
 	float dither = ibuf->dither;
+	int is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
 
 	int offset = channels * start_line * ibuf->x;
 
@@ -1105,6 +1114,7 @@
 	handle->channels = channels;
 	handle->dither = dither;
 	handle->predivide = predivide;
+	handle->is_data = is_data;
 
 	handle->byte_colorspace = init_data->byte_colorspace;
 	handle->float_colorspace = init_data->float_colorspace;
@@ -1189,11 +1199,19 @@
 	int height = handle->tot_line;
 	float dither = handle->dither;
 	int predivide = handle->predivide;
+	int is_data = handle->is_data;
 
 	float *linear_buffer = display_buffer_apply_get_linear_buffer(handle);
 
-	/* apply processor */
-	IMB_colormanagement_processor_apply(cm_processor, linear_buffer, width, height, channels, predivide);
+	if (is_data) {
+		/* special case for data buffers - no color space conversions,
+		 * only generate byte buffers
+		 */
+	}
+	else {
+		/* apply processor */
+		IMB_colormanagement_processor_apply(cm_processor, linear_buffer, width, height, channels, predivide);
+	}
 
 	/* copy result to output buffers */
 	if (display_buffer_byte) {
@@ -1938,7 +1956,7 @@
 	}
 }
 
-ColorSpace *colormanage_colorspace_add(const char *name, const char *description, int is_invertible)
+ColorSpace *colormanage_colorspace_add(const char *name, const char *description, int is_invertible, int is_data)
 {
 	ColorSpace *colorspace, *prev_space;
 	int counter = 1;
@@ -1954,6 +1972,7 @@
 	}
 
 	colorspace->is_invertible = is_invertible;
+	colorspace->is_data = is_data;
 
 	for (prev_space = global_colorspaces.first; prev_space; prev_space = prev_space->next) {
 		if (BLI_strcasecmp(prev_space->name, colorspace->name) > 0)
@@ -2141,6 +2160,7 @@
 	float *display_buffer_float = NULL;
 	int width = xmax - xmin;
 	int height = ymax - ymin;
+	int is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
 
 	if (dither != 0.0f) {
 		display_buffer_float = MEM_callocN(channels * width * height * sizeof(float), "display buffer for dither");
@@ -2161,10 +2181,12 @@
 				IMB_colormanagement_colorspace_to_scene_linear_v3(pixel, rect_colorspace);
 			}
 
-			if (predivide)
-				IMB_colormanagement_processor_apply_v4(cm_processor, pixel);
-			else
-				IMB_colormanagement_processor_apply_v4(cm_processor, pixel);
+			if (!is_data) {
+				if (predivide)
+					IMB_colormanagement_processor_apply_v4(cm_processor, pixel);
+				else
+					IMB_colormanagement_processor_apply_v4(cm_processor, pixel);
+			}
 
 			if (display_buffer_float) {
 				int index = ((y - ymin) * width + (x - xmin)) * channels;




More information about the Bf-blender-cvs mailing list