[Bf-blender-cvs] [301d7d2] master: Fix T39430, incorrect color management in paint cursor when using texture nodes.

Antony Riakiotakis noreply at git.blender.org
Sun Apr 13 16:20:50 CEST 2014


Commit: 301d7d2f63f3e9e5560500c225f9ae437075418f
Author: Antony Riakiotakis
Date:   Sun Apr 13 17:20:06 2014 +0300
https://developer.blender.org/rB301d7d2f63f3e9e5560500c225f9ae437075418f

Fix T39430, incorrect color management in paint cursor when using
texture nodes.

Adopt a similar system to texture sampling for painting.

===================================================================

M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_utils.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index 81177dd..97c2a5b 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -54,6 +54,8 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "IMB_imbuf_types.h"
+
 #include "ED_view3d.h"
 
 #include "paint_intern.h"
@@ -159,6 +161,8 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
 
 	if (refresh) {
 		struct ImagePool *pool = NULL;
+		bool convert_to_linear = false;
+		ImBuf *tex_ibuf;
 		/* stencil is rotated later */
 		const float rotation = (mtex->brush_map_mode != MTEX_MAP_MODE_STENCIL) ?
 		                       -mtex->rot : 0;
@@ -218,6 +222,16 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
 			thread_num = 0;
 #endif
 
+			if (mtex->tex->type == TEX_IMAGE && mtex->tex->ima) {
+				tex_ibuf = BKE_image_pool_acquire_ibuf(mtex->tex->ima, &mtex->tex->iuser, pool);
+				/* For consistency, sampling always returns color in linear space */
+				if (tex_ibuf && tex_ibuf->rect_float == NULL) {
+					convert_to_linear = true;
+				}
+				BKE_image_pool_release_ibuf(mtex->tex->ima, tex_ibuf, pool);
+			}
+
+
 			for (i = 0; i < size; i++) {
 
 				// largely duplicated from tex_strength
@@ -256,7 +270,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
 					if (col) {
 						float rgba[4];
 
-						paint_get_tex_pixel_col(mtex, x, y, rgba, pool, thread_num);
+						paint_get_tex_pixel_col(mtex, x, y, rgba, pool, thread_num, convert_to_linear, tex_ibuf);
 
 						buffer[index * 4]     = rgba[0] * 255;
 						buffer[index * 4 + 1] = rgba[1] * 255;
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index cae7859..0c3cdc7 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -37,6 +37,7 @@ struct bContext;
 struct bglMats;
 struct Brush;
 struct ImagePool;
+struct ImBuf;
 struct ListBase;
 struct Mesh;
 struct MTex;
@@ -199,7 +200,7 @@ void paint_calc_redraw_planes(float planes[4][4],
 
 float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius);
 float paint_get_tex_pixel(struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread);
-void paint_get_tex_pixel_col(struct MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread);
+void paint_get_tex_pixel_col(struct MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert, struct ImBuf *ibuf);
 void brush_drawcursor_texpaint_uvsculpt(struct bContext *C, int x, int y, void *customdata);
 
 void paint_sample_color(const struct bContext *C, struct ARegion *ar, int x, int y);
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index e06ee4c..2eb3975 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -49,6 +49,7 @@
 #include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_image.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
 
@@ -58,6 +59,9 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "IMB_colormanagement.h"
+#include "IMB_imbuf_types.h"
+
 #include "RE_shader_ext.h"
 #include "RE_render_ext.h"
 
@@ -175,7 +179,7 @@ float paint_get_tex_pixel(MTex *mtex, float u, float v, struct ImagePool *pool,
 	return intensity;
 }
 
-void paint_get_tex_pixel_col(MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread)
+void paint_get_tex_pixel_col(MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert_to_linear, ImBuf *ibuf)
 {
 	float co[3] = {u, v, 0.0f};
 	int hasrgb;
@@ -189,6 +193,12 @@ void paint_get_tex_pixel_col(MTex *mtex, float u, float v, float rgba[4], struct
 		rgba[2] = intensity;
 		rgba[3] = 1.0f;
 	}
+
+	if (convert_to_linear)
+		IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, ibuf->rect_colorspace);
+
+	linearrgb_to_srgb_v3_v3(rgba, rgba);
+
 	CLAMP(rgba[0], 0.0f, 1.0f);
 	CLAMP(rgba[1], 0.0f, 1.0f);
 	CLAMP(rgba[2], 0.0f, 1.0f);




More information about the Bf-blender-cvs mailing list