[Bf-blender-cvs] [6f15304] master: Reduce overhead when sampling texture images for brushes. The tests can be cached and reused.

Antony Riakiotakis noreply at git.blender.org
Sun Apr 13 18:03:34 CEST 2014


Commit: 6f153046e0ffec912883ab24b9fda823e9fbeb38
Author: Antony Riakiotakis
Date:   Sun Apr 13 19:03:14 2014 +0300
https://developer.blender.org/rB6f153046e0ffec912883ab24b9fda823e9fbeb38

Reduce overhead when sampling texture images for brushes. The tests can
be cached and reused.

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

M	source/blender/blenkernel/intern/brush.c
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_stroke.c
M	source/blender/editors/sculpt_paint/paint_utils.c
M	source/blender/makesdna/DNA_scene_types.h

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

diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index c34b237..8e611a1 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -634,15 +634,9 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
 		rgba[2] = intensity;
 		rgba[3] = 1.0f;
 	}
-	else {
-		if (br->mtex.tex->type == TEX_IMAGE && br->mtex.tex->ima) {
-			ImBuf *tex_ibuf = BKE_image_pool_acquire_ibuf(br->mtex.tex->ima, &br->mtex.tex->iuser, pool);
-			/* For consistency, sampling always returns color in linear space */
-			if (tex_ibuf && tex_ibuf->rect_float == NULL) {
-				IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, tex_ibuf->rect_colorspace);
-			}
-			BKE_image_pool_release_ibuf(br->mtex.tex->ima, tex_ibuf, pool);
-		}
+	/* For consistency, sampling always returns color in linear space */
+	else if (ups->do_linear_conversion) {
+		IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, ups->colorspace);
 	}
 
 	return intensity;
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index 97c1a99..b1e4696 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -162,7 +162,7 @@ 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;
+		struct ColorSpace *colorspace;
 		/* stencil is rotated later */
 		const float rotation = (mtex->brush_map_mode != MTEX_MAP_MODE_STENCIL) ?
 		                       -mtex->rot : 0;
@@ -223,10 +223,11 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
 #endif
 
 			if (mtex->tex->type == TEX_IMAGE && mtex->tex->ima) {
-				tex_ibuf = BKE_image_pool_acquire_ibuf(mtex->tex->ima, &mtex->tex->iuser, pool);
+				ImBuf *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;
+					colorspace = tex_ibuf->rect_colorspace;
 				}
 				BKE_image_pool_release_ibuf(mtex->tex->ima, tex_ibuf, pool);
 			}
@@ -270,7 +271,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, convert_to_linear, tex_ibuf);
+						paint_get_tex_pixel_col(mtex, x, y, rgba, pool, thread_num, convert_to_linear, colorspace);
 
 						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 bdb1c88..d8f7a3d 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -37,7 +37,7 @@ struct bContext;
 struct bglMats;
 struct Brush;
 struct ImagePool;
-struct ImBuf;
+struct ColorSpace;
 struct ListBase;
 struct Mesh;
 struct MTex;
@@ -200,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, bool convert, struct ImBuf *ibuf);
+void paint_get_tex_pixel_col(struct MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert, struct ColorSpace *colorspace);
 
 void paint_sample_color(const struct bContext *C, struct ARegion *ar, int x, int y);
 void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index a8f3a6c..d3b6d8c 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -47,6 +47,7 @@
 #include "BKE_paint.h"
 #include "BKE_brush.h"
 #include "BKE_colortools.h"
+#include "BKE_image.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -57,6 +58,8 @@
 #include "ED_screen.h"
 #include "ED_view3d.h"
 
+#include "IMB_imbuf_types.h"
+
 #include "paint_intern.h"
 
 #include <float.h>
@@ -172,6 +175,18 @@ static void paint_brush_update(bContext *C, Brush *brush, PaintMode mode,
 		copy_v2_v2(ups->tex_mouse, mouse);
 		copy_v2_v2(ups->mask_tex_mouse, mouse);
 		stroke->cached_size_pressure = pressure;
+
+		/* check here if color sampling the main brush should do color conversion. This is done here
+		 * to avoid locking up to get the image buffer during sampling */
+		if (brush->mtex.tex && brush->mtex.tex->type == TEX_IMAGE && brush->mtex.tex->ima) {
+			ImBuf *tex_ibuf = BKE_image_pool_acquire_ibuf(brush->mtex.tex->ima, &brush->mtex.tex->iuser, NULL);
+			if (tex_ibuf && tex_ibuf->rect_float == NULL) {
+				ups->do_linear_conversion = true;
+				ups->colorspace = tex_ibuf->rect_colorspace;
+			}
+			BKE_image_pool_release_ibuf(brush->mtex.tex->ima, tex_ibuf, NULL);
+		}
+
 		stroke->brush_init = true;
 	}
 
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index 2eb3975..7316c58 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -179,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, bool convert_to_linear, ImBuf *ibuf)
+void paint_get_tex_pixel_col(MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert_to_linear, struct ColorSpace *colorspace)
 {
 	float co[3] = {u, v, 0.0f};
 	int hasrgb;
@@ -195,7 +195,7 @@ void paint_get_tex_pixel_col(MTex *mtex, float u, float v, float rgba[4], struct
 	}
 
 	if (convert_to_linear)
-		IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, ibuf->rect_colorspace);
+		IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, colorspace);
 
 	linearrgb_to_srgb_v3_v3(rgba, rgba);
 
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index aada838..e36ce7d 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -60,6 +60,7 @@ struct Editing;
 struct SceneStats;
 struct bGPdata;
 struct MovieClip;
+struct ColorSpace;
 
 /* ************************************************************* */
 /* Scene Data */
@@ -932,7 +933,9 @@ typedef struct UnifiedPaintSettings {
 
 	float brush_rotation;
 
-	// all this below is used to communicate with the cursor drawing routine
+	/*********************************************************************************
+	 *  all data below are used to communicate with cursor drawing and tex sampling  *
+	 *********************************************************************************/
 	int draw_anchored;
 	int   anchored_size;
 	float anchored_initial_mouse[2];
@@ -949,9 +952,14 @@ typedef struct UnifiedPaintSettings {
 	/* position of mouse, used to sample the mask texture */
 	float mask_tex_mouse[2];
 
+	/* ColorSpace cache to avoid locking up during sampling */
+	int do_linear_conversion;
+	struct ColorSpace *colorspace;
+
 	/* radius of brush, premultiplied with pressure.
 	 * In case of anchored brushes contains that radius */
 	float pixel_radius;
+	int pad2;
 } UnifiedPaintSettings;
 
 typedef enum {




More information about the Bf-blender-cvs mailing list