[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55367] trunk/blender/source/blender: Fix #34672: Image sampling line didn' t use color management for byte buffers

Sergey Sharybin sergey.vfx at gmail.com
Mon Mar 18 12:34:06 CET 2013


Revision: 55367
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55367
Author:   nazgul
Date:     2013-03-18 11:34:05 +0000 (Mon, 18 Mar 2013)
Log Message:
-----------
Fix #34672: Image sampling line didn't use color management for byte buffers

This makes it so sample line (for all image editor, sequencer and compositor)
displaying managed color for byte buffers as well. It was simply not implemented
before.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_image.h
    trunk/blender/source/blender/editors/space_image/image_draw.c
    trunk/blender/source/blender/editors/space_image/image_ops.c
    trunk/blender/source/blender/editors/space_node/node_view.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_view.c
    trunk/blender/source/blender/imbuf/IMB_colormanagement.h
    trunk/blender/source/blender/imbuf/intern/colormanagement.c

Modified: trunk/blender/source/blender/editors/include/ED_image.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_image.h	2013-03-18 09:05:15 UTC (rev 55366)
+++ trunk/blender/source/blender/editors/include/ED_image.h	2013-03-18 11:34:05 UTC (rev 55367)
@@ -79,7 +79,7 @@
 void ED_image_update_frame(const struct Main *mainp, int cfra);
 
 void ED_image_draw_info(struct Scene *scene, struct ARegion *ar, int color_manage, int use_default_view, int channels, int x, int y,
-                        const unsigned char cp[4], const float fp[4], int *zp, float *zpf);
+                        const unsigned char cp[4], const float fp[4], const float linearcol[4], int *zp, float *zpf);
 
 #endif /* __ED_IMAGE_H__ */
 

Modified: trunk/blender/source/blender/editors/space_image/image_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_draw.c	2013-03-18 09:05:15 UTC (rev 55366)
+++ trunk/blender/source/blender/editors/space_image/image_draw.c	2013-03-18 11:34:05 UTC (rev 55367)
@@ -162,7 +162,7 @@
 
 /* used by node view too */
 void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_default_view, int channels, int x, int y,
-                        const unsigned char cp[4], const float fp[4], int *zp, float *zpf)
+                        const unsigned char cp[4], const float fp[4], const float linearcol[4], int *zp, float *zpf)
 {
 	char str[256];
 	float dx = 6;
@@ -258,15 +258,23 @@
 			dx += BLF_width(blf_mono_font, str);
 		}
 
-		if (color_manage && channels == 4) {
-			float pixel[4];
+		if (color_manage) {
+			float rgba[4];
 
+			copy_v3_v3(rgba, linearcol);
+			if (channels == 3)
+				rgba[3] = 1.0f;
+			else
+				rgba[3] = linearcol[3];
+
+			(void)color_manage;
+
 			if (use_default_view)
-				IMB_colormanagement_pixel_to_display_space_v4(pixel, fp,  NULL, &scene->display_settings);
+				IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba,  NULL, &scene->display_settings);
 			else
-				IMB_colormanagement_pixel_to_display_space_v4(pixel, fp,  &scene->view_settings, &scene->display_settings);
+				IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba,  &scene->view_settings, &scene->display_settings);
 
-			BLI_snprintf(str, sizeof(str), "  |  CM  R:%-.4f  G:%-.4f  B:%-.4f", pixel[0], pixel[1], pixel[2]);
+			BLI_snprintf(str, sizeof(str), "  |  CM  R:%-.4f  G:%-.4f  B:%-.4f", rgba[0], rgba[1], rgba[2]);
 			BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
 			BLF_draw_ascii(blf_mono_font, str, sizeof(str));
 			dx += BLF_width(blf_mono_font, str);
@@ -287,26 +295,11 @@
 		col[3] = 1.0f;
 	}
 	else if (channels == 3) {
-		if (fp) {
-			copy_v3_v3(col, fp);
-		}
-		else if (cp) {
-			rgb_uchar_to_float(col, cp);
-		}
-		else {
-			zero_v3(col);
-		}
+		copy_v3_v3(col, linearcol);
 		col[3] = 1.0f;
 	}
 	else if (channels == 4) {
-		if (fp)
-			copy_v4_v4(col, fp);
-		else if (cp) {
-			rgba_uchar_to_float(col, cp);
-		}
-		else {
-			zero_v4(col);
-		}
+		copy_v4_v4(col, linearcol);
 	}
 	else {
 		BLI_assert(0);

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2013-03-18 09:05:15 UTC (rev 55366)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2013-03-18 11:34:05 UTC (rev 55367)
@@ -2079,6 +2079,7 @@
 
 	unsigned char col[4];
 	float colf[4];
+	float linearcol[4];
 	int z;
 	float zf;
 
@@ -2099,7 +2100,7 @@
 		Scene *scene = CTX_data_scene(C);
 
 		ED_image_draw_info(scene, ar, info->color_manage, info->use_default_view, info->channels,
-		                   info->x, info->y, info->colp, info->colfp, info->zp, info->zfp);
+		                   info->x, info->y, info->colp, info->colfp, info->linearcol, info->zp, info->zfp);
 	}
 }
 
@@ -2198,7 +2199,10 @@
 			info->colf[3] = (float)cp[3] / 255.0f;
 			info->colfp = info->colf;
 
-			info->color_manage = FALSE;
+			copy_v4_v4(info->linearcol, info->colf);
+			IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace);
+
+			info->color_manage = TRUE;
 		}
 		if (ibuf->rect_float) {
 			fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
@@ -2209,6 +2213,8 @@
 			info->colf[3] = fp[3];
 			info->colfp = info->colf;
 
+			copy_v4_v4(info->linearcol, info->colf);
+
 			info->color_manage = TRUE;
 		}
 

Modified: trunk/blender/source/blender/editors/space_node/node_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_view.c	2013-03-18 09:05:15 UTC (rev 55366)
+++ trunk/blender/source/blender/editors/space_node/node_view.c	2013-03-18 11:34:05 UTC (rev 55367)
@@ -56,6 +56,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
@@ -335,6 +336,7 @@
 
 	unsigned char col[4];
 	float colf[4];
+	float linearcol[4];
 	
 	int z;
 	float zf;
@@ -353,7 +355,7 @@
 
 	if (info->draw) {
 		ED_image_draw_info(scene, ar, info->color_manage, FALSE, info->channels,
-		                   info->x, info->y, info->col, info->colf,
+		                   info->x, info->y, info->col, info->colf, info->linearcol,
 		                   info->zp, info->zfp);
 	}
 }
@@ -469,7 +471,10 @@
 			info->colf[2] = (float)cp[2] / 255.0f;
 			info->colf[3] = (float)cp[3] / 255.0f;
 
-			info->color_manage = FALSE;
+			copy_v4_v4(info->linearcol, info->colf);
+			IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace);
+
+			info->color_manage = TRUE;
 		}
 		if (ibuf->rect_float) {
 			fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));

Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_view.c	2013-03-18 09:05:15 UTC (rev 55366)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_view.c	2013-03-18 11:34:05 UTC (rev 55367)
@@ -31,6 +31,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_math.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_scene_types.h"
@@ -66,6 +67,7 @@
 
 	unsigned char col[4];
 	float colf[4];
+	float linearcol[4];
 
 	unsigned char *colp;
 	float *colfp;
@@ -81,7 +83,8 @@
 
 	if (info->draw) {
 		ED_image_draw_info(scene, ar, info->color_manage, FALSE, info->channels,
-		                   info->x, info->y, info->colp, info->colfp, NULL, NULL);
+		                   info->x, info->y, info->colp, info->colfp,
+		                   info->linearcol, NULL, NULL);
 	}
 }
 
@@ -134,7 +137,10 @@
 			info->colf[3] = (float)cp[3] / 255.0f;
 			info->colfp = info->colf;
 
-			info->color_manage = FALSE;
+			copy_v4_v4(info->linearcol, info->colf);
+			IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace);
+
+			info->color_manage = TRUE;
 		}
 		if (ibuf->rect_float) {
 			fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));

Modified: trunk/blender/source/blender/imbuf/IMB_colormanagement.h
===================================================================
--- trunk/blender/source/blender/imbuf/IMB_colormanagement.h	2013-03-18 09:05:15 UTC (rev 55366)
+++ trunk/blender/source/blender/imbuf/IMB_colormanagement.h	2013-03-18 11:34:05 UTC (rev 55367)
@@ -70,6 +70,8 @@
 void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace);
 
 void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace);
+void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], int predivide, struct ColorSpace *colorspace);
+
 void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct ColorSpace *colorspace);
 
 void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, int predivide);

Modified: trunk/blender/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/colormanagement.c	2013-03-18 09:05:15 UTC (rev 55366)
+++ trunk/blender/source/blender/imbuf/intern/colormanagement.c	2013-03-18 11:34:05 UTC (rev 55367)
@@ -1583,6 +1583,26 @@
 		OCIO_processorApplyRGB(processor, pixel);
 }
 
+void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], int predivide, ColorSpace *colorspace)
+{
+	OCIO_ConstProcessorRcPtr *processor;
+
+	if (!colorspace) {
+		/* should never happen */
+		printf("%s: perform conversion from unknown color space\n", __func__);
+		return;
+	}
+
+	processor = colorspace_to_scene_linear_processor(colorspace);
+
+	if (processor) {
+		if (predivide)
+			OCIO_processorApplyRGBA_predivide(processor, pixel);
+		else
+			OCIO_processorApplyRGBA(processor, pixel);
+	}
+}
+
 void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, int predivide)
 {
 	OCIO_ConstProcessorRcPtr *processor;




More information about the Bf-blender-cvs mailing list