[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49424] branches/soc-2012-bratwurst: User request from blenderartists: Invert brush colour.

Antony Riakiotakis kalast at gmail.com
Tue Jul 31 18:25:40 CEST 2012


Revision: 49424
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49424
Author:   psy-fi
Date:     2012-07-31 16:25:40 +0000 (Tue, 31 Jul 2012)
Log Message:
-----------
User request from blenderartists: Invert brush colour.
=======================================================
To invert the brush either select the invert option under the colour
picker or press Ctrl when stroking. Doing both will do normal drawing.
There is a known issue with fixed brushes on image editor which will be
addressed next.
The inversion happens after applying the texture to the brush colour, so
the total colour of the brush gets inverted.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_image.py
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
    branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
    branches/soc-2012-bratwurst/source/blender/blenlib/BLI_math_color.h
    branches/soc-2012-bratwurst/source/blender/blenlib/intern/math_color.c
    branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_2D.c
    branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_2D.h
    branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_ops.c
    branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_sculpt_paint.c

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_image.py	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_image.py	2012-07-31 16:25:40 UTC (rev 49424)
@@ -682,6 +682,7 @@
             col = layout.column()
             col.template_color_wheel(brush, "color", value_slider=True)
             col.prop(brush, "color", text="")
+            col.prop(toolsettings, "invert_color")
 
             row = col.row(align=True)
             self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-07-31 16:25:40 UTC (rev 49424)
@@ -637,6 +637,7 @@
             col = layout.column()
             col.template_color_wheel(brush, "color", value_slider=True)
             col.prop(brush, "color", text="")
+            col.prop(settings, "invert_color")
 
             row = col.row(align=True)
             self.prop_unified_size(row, context, brush, "use_locked_size", icon='LOCKED')

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-07-31 16:25:40 UTC (rev 49424)
@@ -70,7 +70,7 @@
 void BKE_brush_sample_tex(const struct Scene *scene, struct Brush *brush, const float xy[2], float rgba[4], const int thread, float angle);
 float BKE_brush_sample_masktex(const struct Scene *scene, struct Brush *brush, const float xy[2], const int thread, float angle);
 void BKE_brush_imbuf_new(const struct Scene *scene, struct Brush *brush, short flt, short texfalloff, int size,
-                         struct ImBuf **imbuf, float angle, int use_color_correction);
+                         struct ImBuf **imbuf, float angle, int use_color_correction, short invert);
 
 /* painting */
 struct BrushPainter;

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-07-31 16:25:40 UTC (rev 49424)
@@ -579,7 +579,7 @@
 }
 
 /* TODO, use define for 'texfall' arg */
-void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, float angle, int use_color_correction)
+void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, float angle, int use_color_correction, short invert)
 {
 	ImBuf *ibuf;
 	float xy[2], rgba[4], *dstf;
@@ -612,17 +612,20 @@
 				xy[0] = x + xoff;
 				xy[1] = y + yoff;
 
-				/* texfall = 0, 1 seem unused from a qiock search */
+				/* texfall = 0, 1 seem unused from a quick search */
 				if (texfall == 0) {
 					copy_v3_v3(dstf, brush_rgb);
 					dstf[3] = alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
+					if(invert) rgb_invert(dstf);
 				}
 				else if (texfall == 1) {
 					BKE_brush_sample_tex(scene, brush, xy, dstf, 0, angle);
+					if(invert) rgb_invert(dstf);
 				}
 				else {
 					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, angle);
 					mul_v3_v3v3(dstf, rgba, brush_rgb);
+					if(invert) rgb_invert(dstf);
 					dstf[3] = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius)
 					        *BKE_brush_sample_masktex(scene, brush, xy, 0, angle);
 				}
@@ -651,6 +654,7 @@
 				else if (texfall == 1) {
 					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, angle);
 					rgba_float_to_uchar(dst, rgba);
+					if(invert) rgb_invert_uchar(dst);
 				}
 				else if (texfall == 2) {
 					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, angle);
@@ -659,6 +663,7 @@
 					        *BKE_brush_sample_masktex(scene, brush, xy, 0, angle);
 
 					rgb_float_to_uchar(dst, rgba);
+					if(invert) rgb_invert_uchar(dst);
 
 					dst[3] = FTOCHAR(alpha_f);
 				}
@@ -671,6 +676,7 @@
 					dst[1] = crgb[1];
 					dst[2] = crgb[2];
 					dst[3] = FTOCHAR(alpha_f);
+					if(invert) rgb_invert_uchar(dst);
 				}
 			}
 		}

Modified: branches/soc-2012-bratwurst/source/blender/blenlib/BLI_math_color.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenlib/BLI_math_color.h	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/source/blender/blenlib/BLI_math_color.h	2012-07-31 16:25:40 UTC (rev 49424)
@@ -112,6 +112,8 @@
 void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]);
 
 void xyz_to_lab(float x, float y, float z, float *l, float *a, float *b);
+void rgb_invert(float col[3]);
+void rgb_invert_uchar(unsigned char col[3]);
 
 /***************** lift/gamma/gain / ASC-CDL conversion *****************/
 

Modified: branches/soc-2012-bratwurst/source/blender/blenlib/intern/math_color.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenlib/intern/math_color.c	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/source/blender/blenlib/intern/math_color.c	2012-07-31 16:25:40 UTC (rev 49424)
@@ -655,6 +655,21 @@
 	*b = 200.0f * (fy - fz);
 }
 
+void rgb_invert(float col[3])
+{
+	/* clamp to avoid negative values especially for hdr */
+	col[0] = 1.0 - maxf(col[0], 1.0);
+	col[1] = 1.0 - maxf(col[1], 1.0);
+	col[2] = 1.0 - maxf(col[2], 1.0);
+}
+
+void rgb_invert_uchar(unsigned char col[3])
+{
+	col[0] = 255 - col[0];
+	col[1] = 255 - col[1];
+	col[2] = 255 - col[2];
+}
+
 void rgb_to_lab(float r, float g, float b, float *ll, float *la, float *lb)
 {
 	float x, y, z;

Modified: branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_2D.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_2D.c	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_2D.c	2012-07-31 16:25:40 UTC (rev 49424)
@@ -255,6 +255,7 @@
 	const int diameter = 2 * BKE_brush_size_randomized_get(scene, brush);
 	const float alpha = BKE_brush_alpha_get(scene, brush);
 	const float rotation = -special_rotation + brush->mtex.rot;
+	const short invert = painter->invert;
 
 	if (diameter != cache->lastsize ||
 	    alpha != cache->lastalpha ||
@@ -274,11 +275,11 @@
 		size = (cache->size) ? cache->size : diameter;
 
 		if (brush->flag & BRUSH_FIXED_TEX) {
-			BKE_brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, rotation, use_color_correction);
+			BKE_brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, rotation, use_color_correction, invert);
 			brush_painter_fixed_tex_partial_update(painter, pos);
 		}
 		else
-			BKE_brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, rotation, use_color_correction);
+			BKE_brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, rotation, use_color_correction, invert);
 
 		cache->lastsize = diameter;
 		cache->lastalpha = alpha;

Modified: branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_2D.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_2D.h	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_2D.h	2012-07-31 16:25:40 UTC (rev 49424)
@@ -71,6 +71,7 @@
 	float startspacing;
 
 	float areamousepos[2]; /* guaranteed to hold the mouse position */
+	short invert;
 
 	BrushPainterCache cache;
 };

Modified: branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c	2012-07-31 16:04:47 UTC (rev 49423)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c	2012-07-31 16:25:40 UTC (rev 49424)
@@ -341,6 +341,7 @@
 	int bucketMax[2];
 	int context_bucket_x, context_bucket_y; /* must lock threads while accessing these */
 	float rotation;
+	short invert;
 } ProjPaintState;
 
 typedef union pixelPointer {
@@ -3795,6 +3796,8 @@
 		rgba_ub[3] = 255;
 	}
 	
+	if (ps->invert) rgb_invert_uchar(rgba_ub);
+
 	if (ps->is_airbrush == 0 && mask < 1.0f) {
 		projPixel->newColor.uint = IMB_blend_color(projPixel->newColor.uint, *((unsigned int *)rgba_ub), (int)(alpha * 255), ps->blend);
 		blend_color_mix(projPixel->pixel.ch_pt,  projPixel->origColor.ch, projPixel->newColor.ch, (int)(mask * 255));
@@ -3826,6 +3829,8 @@
 		}
 		rgba[3] = 1.0;
 	}
+
+	if (ps->invert) rgb_invert(rgba);
 	
 	if (ps->is_airbrush == 0 && mask < 1.0f) {
 		IMB_blend_color_float(projPixel->newColor.f, projPixel->newColor.f, rgba, alpha, ps->blend);
@@ -4873,10 +4878,13 @@
 	ToolSettings *settings = scene->toolsettings;
 	Brush *brush = paint_brush(&settings->imapaint.paint);
 	PaintOperation *pop = MEM_callocN(sizeof(PaintOperation), "PaintOperation"); /* caller frees */
+	short invert = RNA_boolean_get(op->ptr, "invert") ? IMAGEPAINT_INVERT : 0;
 
 	pop->first = 1;
 	op->customdata = pop;
 	
+	invert = invert ^ (settings->imapaint.flag & IMAGEPAINT_INVERT);
+
 	/* XXX: Soften tool does not support projection painting atm, so just disable
 	 *      projection for this brush */
 	if (brush->imagepaint_tool == PAINT_TOOL_SOFTEN) {
@@ -4967,6 +4975,7 @@
 		paint_brush_init_tex(pop->ps.brush);
 
 		pop->ps.source = PROJ_SRC_VIEW;
+		pop->ps.invert = invert;
 
 		if (pop->ps.ob == NULL || !(pop->ps.ob->lay & pop->ps.v3d->lay))
 			return 0;
@@ -4988,6 +4997,7 @@
 
 	/* create painter */
 	pop->painter = BKE_brush_painter_new(scene, pop->s.brush);
+	pop->painter->invert = invert;
 
 	return 1;
 }
@@ -5230,6 +5240,7 @@
 
 	/* properties */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list