[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60181] branches/soc-2013-paint/source/ blender/editors/sculpt_paint: Hook custom blur radius and type into 2d painting.

Antony Riakiotakis kalast at gmail.com
Tue Sep 17 03:34:59 CEST 2013


Revision: 60181
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60181
Author:   psy-fi
Date:     2013-09-17 01:34:56 +0000 (Tue, 17 Sep 2013)
Log Message:
-----------
Hook custom blur radius and type into 2d painting. Really nice result :)

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-09-17 00:56:24 UTC (rev 60180)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-09-17 01:34:56 UTC (rev 60181)
@@ -491,10 +491,12 @@
 
 /* paint blur kernels */
 
-BlurKernel *paint_new_blur_kernel(int pixel_len, BlurKernelType type)
+BlurKernel *paint_new_blur_kernel(Brush *br)
 {
 	int i, j;
 	BlurKernel *kernel = MEM_mallocN(sizeof(BlurKernel), "blur kernel");
+	int pixel_len = br->blur_kernel_radius;
+	BlurKernelType type = br->blur_mode;
 
 	kernel->side = pixel_len * 2 + 1;
 	kernel->side_squared = kernel->side * kernel->side;
@@ -503,13 +505,12 @@
 	switch (type) {
 		case KERNEL_BOX:
 			for (i = 0; i < kernel->side_squared; i++)
-				kernel->wdata[i] = 1.0/(float)kernel->side_squared;
+				kernel->wdata[i] = 1.0;
 			break;
 
 		case KERNEL_GAUSSIAN:
 		{
 			float standard_dev = pixel_len / 3.0; /* at standard deviation of 3.0 kernel is at about zero */
-			float weight_sum = 0.0; /* for kernel normalization */
 			int i_term = pixel_len + 1;
 
 			/* make the necessary adjustment to the value for use in the normal distribution formula */
@@ -525,20 +526,13 @@
 					float value = exp((idist * idist + jdist * jdist) / standard_dev);
 
 					kernel->wdata[i + j * kernel->side] =
-					kernel->wdata[(kernel->side - j) + i * kernel->side] =
-					kernel->wdata[(kernel->side - i) + (kernel->side - j) * kernel->side] =
-					kernel->wdata[j + (kernel->side - i) * kernel->side] =
+					kernel->wdata[(kernel->side - j - 1) + i * kernel->side] =
+					kernel->wdata[(kernel->side - i - 1) + (kernel->side - j - 1) * kernel->side] =
+					kernel->wdata[j + (kernel->side - i - 1) * kernel->side] =
 						value;
-
-					weight_sum += value;
 				}
 			}
 
-			weight_sum *= 4.0;
-			weight_sum += 1.0; /* central */
-
-			weight_sum /= kernel->side_squared;
-
 			break;
 		}
 

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-09-17 00:56:24 UTC (rev 60180)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-09-17 01:34:56 UTC (rev 60181)
@@ -142,6 +142,8 @@
 	int do_facesel;
 
 	bool need_redraw;
+
+	BlurKernel *blurkernel;
 } ImagePaintState;
 
 
@@ -789,7 +791,7 @@
 	}
 }
 
-static int paint_2d_ibuf_add_if(ImBuf *ibuf, unsigned int x, unsigned int y, float *outrgb, short torus)
+static float paint_2d_ibuf_add_if(ImBuf *ibuf, unsigned int x, unsigned int y, float *outrgb, short torus, float w)
 {
 	float inrgb[4];
 
@@ -802,20 +804,23 @@
 		paint_2d_ibuf_rgb_get(ibuf, x, y, 0, inrgb);
 	}
 
+	mul_v4_fl(inrgb, w);
 	add_v4_v4(outrgb, inrgb);
 
-	return 1;
+	return w;
 }
 
 static void paint_2d_lift_soften(ImagePaintState *s, ImBuf *ibuf, ImBuf *ibufb, int *pos, const short is_torus)
 {
 	bool sharpen = (s->painter->cache.invert ^ ((s->brush->flag & BRUSH_DIR_IN) != 0));
 	float threshold = s->brush->sharp_threshold;
-	int x, y, count, xi, yi, xo, yo;
+	int x, y, xi, yi, xo, yo, xk, yk;
+	float count;
 	int out_off[2], in_off[2], dim[2];
 	int diff_pos[2];
 	float outrgb[4];
 	float rgba[4];
+	BlurKernel *kernel = s->blurkernel;
 
 	dim[0] = ibufb->x;
 	dim[1] = ibufb->y;
@@ -840,21 +845,19 @@
 			xi = in_off[0] + x;
 			yi = in_off[1] + y;
 
-			count = 0;
+			count = 0.0;
 			paint_2d_ibuf_rgb_get(ibuf, xi, yi, is_torus, rgba);
 			zero_v4(outrgb);
-			count += paint_2d_ibuf_add_if(ibuf, xi - 1, yi - 1, outrgb, is_torus);
-			count += paint_2d_ibuf_add_if(ibuf, xi - 1, yi, outrgb, is_torus);
-			count += paint_2d_ibuf_add_if(ibuf, xi - 1, yi + 1, outrgb, is_torus);
 
-			count += paint_2d_ibuf_add_if(ibuf, xi, yi - 1, outrgb, is_torus);
-			count += paint_2d_ibuf_add_if(ibuf, xi, yi + 1, outrgb, is_torus);
+			for (yk = 0; yk < kernel->side; yk++) {
+				for (xk = 0; xk < kernel->side; xk++) {
+					count += paint_2d_ibuf_add_if(ibuf, xi - (xk - kernel->pixel_len),
+					                               yi - (yk - kernel->pixel_len), outrgb, is_torus,
+					                               kernel->wdata[xk + yk * kernel->side]);
+				}
+			}
 
-			count += paint_2d_ibuf_add_if(ibuf, xi + 1, yi - 1, outrgb, is_torus);
-			count += paint_2d_ibuf_add_if(ibuf, xi + 1, yi, outrgb, is_torus);
-			count += paint_2d_ibuf_add_if(ibuf, xi + 1, yi + 1, outrgb, is_torus);
-
-			if (count > 0) {
+			if (count > 0.0) {
 				mul_v4_fl(outrgb, 1.0f / (float)count);
 
 				if (sharpen) {
@@ -1129,6 +1132,11 @@
 	BKE_image_release_ibuf(s->image, s->canvas, NULL);
 	BKE_image_release_ibuf(s->brush->clone.image, s->clonecanvas, NULL);
 
+	if (s->blurkernel) {
+		paint_delete_blur_kernel(s->blurkernel);
+		MEM_freeN(s->blurkernel);
+	}
+
 	if (s->do_masking)
 		image_undo_remove_masks();
 }
@@ -1215,6 +1223,10 @@
 		return NULL;
 	}
 
+	if (brush->imagepaint_tool == PAINT_TOOL_SOFTEN) {
+		s->blurkernel = paint_new_blur_kernel(brush);
+	}
+
 	paint_brush_init_tex(s->brush);
 
 	/* create painter */

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-09-17 00:56:24 UTC (rev 60180)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-09-17 01:34:56 UTC (rev 60181)
@@ -280,7 +280,7 @@
 
 enum BlurKernelType;
 /* can be extended to other blur kernels later */
-BlurKernel *paint_new_blur_kernel(int pixel_len, enum BlurKernelType type);
+BlurKernel *paint_new_blur_kernel(struct Brush *br);
 void paint_delete_blur_kernel(BlurKernel *);
 
 #endif /* __PAINT_INTERN_H__ */




More information about the Bf-blender-cvs mailing list