[Bf-blender-cvs] [ebc064f] master: Gooseberry request: Dithering support for byte images when painting on projection painting (2D will be separate commit).

Antony Riakiotakis noreply at git.blender.org
Thu Jan 29 19:24:09 CET 2015


Commit: ebc064f5c0c9bc5a5f67c82ea564bf170d135bd0
Author: Antony Riakiotakis
Date:   Thu Jan 29 19:23:45 2015 +0100
Branches: master
https://developer.blender.org/rBebc064f5c0c9bc5a5f67c82ea564bf170d135bd0

Gooseberry request: Dithering support for byte images when painting on
projection painting (2D will be separate commit).

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenlib/BLI_math_color.h
M	source/blender/blenlib/intern/math_color_inline.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/imbuf/intern/divers.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 2ce64d0..18a38c8 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1722,6 +1722,7 @@ class VIEW3D_PT_tools_projectpaint(View3DPaintPanel, Panel):
         sub.prop(ipaint, "normal_angle", text="")
 
         layout.prop(ipaint, "seam_bleed")
+        layout.prop(ipaint, "dither")
         self.unified_paint_settings(layout, context)
 
 
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 5c14ac5..560ebe3 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -141,6 +141,10 @@ void xyz_to_lab(float x, float y, float z, float *l, float *a, float *b);
 
 MINLINE int compare_rgb_uchar(const unsigned char a[3], const unsigned char b[3], const int limit);
 
+MINLINE float dither_random_value(float s, float t);
+MINLINE void float_to_byte_dither_v3(unsigned char b[3], const float f[3], float dither, float s, float t);
+
+
 #define rgba_char_args_set_fl(col, r, g, b, a) \
 	rgba_char_args_set(col, (r) * 255, (g) * 255, (b) * 255, (a) * 255)
 
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index 9233749..dc62d04 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -31,6 +31,8 @@
 #include "BLI_math_color.h"
 #include "BLI_utildefines.h"
 
+#include "math.h"
+
 #ifndef __MATH_COLOR_INLINE_C__
 #define __MATH_COLOR_INLINE_C__
 
@@ -269,6 +271,24 @@ MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char
 	return 0;
 }
 
+MINLINE float dither_random_value(float s, float t)
+{
+	static float vec[2] = {12.9898f, 78.233f};
+	float value;
+
+	value = sinf(s * vec[0] + t * vec[1]) * 43758.5453f;
+	return value - floorf(value);
+}
+
+MINLINE void float_to_byte_dither_v3(unsigned char b[3], const float f[3], float dither, float s, float t)
+{
+	float dither_value = dither_random_value(s, t) * 0.005f * dither;
+
+	b[0] = FTOCHAR(dither_value + f[0]);
+	b[1] = FTOCHAR(dither_value + f[1]);
+	b[2] = FTOCHAR(dither_value + f[2]);
+}
+
 /**************** Alpha Transformations *****************/
 
 MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index cbfa53d..6bc597f 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -203,6 +203,7 @@ typedef struct ProjPaintState {
 	/* the paint color. It can change depending of inverted mode or not */
 	float paint_color[3];
 	float paint_color_linear[3];
+	float dither;
 
 	Brush *brush;
 	short tool, blend, mode;
@@ -4156,7 +4157,7 @@ static void do_projectpaint_soften(ProjPaintState *ps, ProjPixel *projPixel, flo
 	}
 }
 
-static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, const float texrgb[3], float mask)
+static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, const float texrgb[3], float mask, float dither, float u, float v)
 {
 	float rgb[3];
 	unsigned char rgba_ub[4];
@@ -4170,7 +4171,7 @@ static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, const
 		copy_v3_v3(rgb, ps->paint_color);
 	}
 
-	rgb_float_to_uchar(rgba_ub, rgb);
+	float_to_byte_dither_v3(rgba_ub, rgb, dither, u, v);
 	rgba_ub[3] = f_to_char(mask);
 
 	if (ps->do_masking) {
@@ -4351,7 +4352,8 @@ static void *do_projectpaint_thread(void *ph_v)
 						}
 						else {
 							linearrgb_to_srgb_v3_v3(color_f, color_f);
-							rgba_float_to_uchar(projPixel->newColor.ch, color_f);
+							float_to_byte_dither_v3(projPixel->newColor.ch, color_f, ps->dither, projPixel->x_px, projPixel->y_px);
+							projPixel->newColor.ch[3] = FTOCHAR(color_f[3]);
 							IMB_blend_color_byte(projPixel->pixel.ch_pt,  projPixel->origColor.ch_pt,
 							                     projPixel->newColor.ch, ps->blend);
 						}
@@ -4547,7 +4549,7 @@ static void *do_projectpaint_thread(void *ph_v)
 									break;
 								default:
 									if (is_floatbuf) do_projectpaint_draw_f(ps, projPixel, texrgb, mask);
-									else             do_projectpaint_draw(ps, projPixel, texrgb, mask);
+									else             do_projectpaint_draw(ps, projPixel, texrgb, mask, ps->dither, projPixel->x_px, projPixel->y_px);
 									break;
 							}
 						}
@@ -4851,6 +4853,8 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int
 	if (ps->normal_angle_range <= 0.0f)
 		ps->do_mask_normal = false;  /* no need to do blending */
 
+	ps->dither = settings->imapaint.dither;
+	
 	return;
 }
 
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index 81aef4a..59d0812 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -122,16 +122,6 @@ static void clear_dither_context(DitherContext *di)
 	MEM_freeN(di);
 }
 
-MINLINE float dither_random_value(float s, float t)
-{
-	static float vec[2] = {12.9898f, 78.233f};
-	float st[2];
-	float value;
-	copy_v2_fl2(st, s, t);
-
-	value = sinf(dot_v2v2(st, vec)) * 43758.5453f;
-	return value - floorf(value);
-}
 
 /************************* Generic Buffer Conversion *************************/
 
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 8acfd23..fabfa76 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -849,7 +849,7 @@ typedef struct ImagePaintSettings {
 	struct Image *clone;       /* clone layer for image mode for projective texture painting */
 	struct Image *canvas;      /* canvas when the explicit system is used for painting */
 	float stencil_col[3];
-	float pad1;
+	float dither;              /* dither amount used when painting on byte images */
 } ImagePaintSettings;
 
 /* ------------------------------------------- */
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 3b19e45..0a282ee 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -709,6 +709,11 @@ static void rna_def_image_paint(BlenderRNA *brna)
 	RNA_def_property_float_sdna(prop, NULL, "stencil_col");
 	RNA_def_property_ui_text(prop, "Stencil Color", "Stencil color in the viewport");
 	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, "rna_ImaPaint_viewport_update");
+
+	prop = RNA_def_property(srna, "dither", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0, 2.0);
+	RNA_def_property_ui_text(prop, "Dither", "Amount of dithering when painting on byte images");
+	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
 	
 	prop = RNA_def_property(srna, "use_clone_layer", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_LAYER_CLONE);




More information about the Bf-blender-cvs mailing list