[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60180] branches/soc-2013-paint: * UI options for configurable blur kernel: size, type (box, gaussian)

Antony Riakiotakis kalast at gmail.com
Tue Sep 17 02:56:25 CEST 2013


Revision: 60180
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60180
Author:   psy-fi
Date:     2013-09-17 00:56:24 +0000 (Tue, 17 Sep 2013)
Log Message:
-----------
* UI options for configurable blur kernel: size, type (box, gaussian)
* added a function that calculates the blur kernel.

Still not hooked to the paint systems.

Modified Paths:
--------------
    branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py
    branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-09-17 00:24:46 UTC (rev 60179)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-09-17 00:56:24 UTC (rev 60180)
@@ -767,9 +767,13 @@
                     row.prop(brush, "use_space_attenuation", toggle=True, text="", icon='UNLOCKED')
 
             if brush.image_tool == 'SOFTEN':
+                col = layout.column(align=True)
+                col.row().prop(brush, "direction", expand=True)
                 col.separator()
-                col.row().prop(brush, "direction", expand=True)
-                col.row().prop(brush, "sharp_threshold")
+                col.prop(brush, "sharp_threshold")
+                col.prop(brush, "blur_kernel_radius")
+                col.separator()
+                col.prop(brush, "blur_mode")
             
             if brush.image_tool == 'CLONE':
                 col.separator()

Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-09-17 00:24:46 UTC (rev 60179)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-09-17 00:56:24 UTC (rev 60180)
@@ -778,9 +778,13 @@
                     row.prop(brush, "use_space_attenuation", toggle=True, text="", icon='UNLOCKED')
 
             if brush.image_tool == 'SOFTEN':
+                col = layout.column(align=True)
+                col.row().prop(brush, "direction", expand=True)
                 col.separator()
-                col.row().prop(brush, "direction", expand=True)
-                col.row().prop(brush, "sharp_threshold")
+                col.prop(brush, "sharp_threshold")
+                col.prop(brush, "blur_kernel_radius")
+                col.separator()
+                col.prop(brush, "blur_mode")
 
             # use_accumulate
             if capabilities.has_accumulate:

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:24:46 UTC (rev 60179)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-09-17 00:56:24 UTC (rev 60180)
@@ -489,6 +489,76 @@
 	}
 }
 
+/* paint blur kernels */
+
+BlurKernel *paint_new_blur_kernel(int pixel_len, BlurKernelType type)
+{
+	int i, j;
+	BlurKernel *kernel = MEM_mallocN(sizeof(BlurKernel), "blur kernel");
+
+	kernel->side = pixel_len * 2 + 1;
+	kernel->side_squared = kernel->side * kernel->side;
+	kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
+
+	switch (type) {
+		case KERNEL_BOX:
+			for (i = 0; i < kernel->side_squared; i++)
+				kernel->wdata[i] = 1.0/(float)kernel->side_squared;
+			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 */
+			standard_dev = standard_dev * standard_dev * 2;
+
+			kernel->wdata[pixel_len + pixel_len * kernel->side] = 1.0;
+			/* fill in all four quadrants at once */
+			for (i = 0; i < i_term; i++) {
+				for (j = 0; j < pixel_len; j++) {
+					float idist = pixel_len - i;
+					float jdist = pixel_len - j;
+
+					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] =
+						value;
+
+					weight_sum += value;
+				}
+			}
+
+			weight_sum *= 4.0;
+			weight_sum += 1.0; /* central */
+
+			weight_sum /= kernel->side_squared;
+
+			break;
+		}
+
+		default:
+			printf("unidentified kernel type, aborting\n");
+			MEM_freeN(kernel->wdata);
+			MEM_freeN(kernel);
+			return NULL;
+			break;
+	}
+
+	return kernel;
+}
+
+void paint_delete_blur_kernel(BlurKernel *kernel)
+{
+	if (kernel->wdata)
+		MEM_freeN(kernel->wdata);
+}
+
 /************************ image paint poll ************************/
 
 static Brush *image_paint_brush(bContext *C)

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:24:46 UTC (rev 60179)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-09-17 00:56:24 UTC (rev 60180)
@@ -270,4 +270,17 @@
 
 void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot);
 
+/* image painting blur kernel */
+typedef struct {
+	float *wdata; /* actual kernel */
+	int side; /* kernel side */
+	int side_squared; /* data side */
+	int pixel_len; /* pixels around center that kernel is wide */
+} BlurKernel;
+
+enum BlurKernelType;
+/* can be extended to other blur kernels later */
+BlurKernel *paint_new_blur_kernel(int pixel_len, enum BlurKernelType type);
+void paint_delete_blur_kernel(BlurKernel *);
+
 #endif /* __PAINT_INTERN_H__ */

Modified: branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h	2013-09-17 00:24:46 UTC (rev 60179)
+++ branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h	2013-09-17 00:56:24 UTC (rev 60180)
@@ -109,13 +109,17 @@
 
 	float texture_sample_bias;
 
+	/* overlay */
 	int texture_overlay_alpha;
 	int mask_overlay_alpha;
 	int cursor_overlay_alpha;
 
 	float unprojected_radius;
 
+	/* soften/sharpen */
 	float sharp_threshold;
+	int blur_kernel_radius;
+	int blur_mode;
 	int pad;
 
 	float add_col[3];
@@ -270,6 +274,12 @@
 	BRUSH_MASK_SMOOTH = 1
 } BrushMaskTool;
 
+/* blur kernel types, Brush.blur_mode */
+typedef enum BlurKernelType {
+	KERNEL_GAUSSIAN,
+	KERNEL_BOX
+} BlurKernelType;
+
 #define MAX_BRUSH_PIXEL_RADIUS 200
 
 #endif

Modified: branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c	2013-09-17 00:24:46 UTC (rev 60179)
+++ branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c	2013-09-17 00:56:24 UTC (rev 60180)
@@ -773,6 +773,12 @@
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem brush_blur_mode_items[] = {
+		{KERNEL_BOX, "BOX", 0, "Box", ""},
+		{KERNEL_GAUSSIAN, "GAUSSIAN", 0, "Gaussian", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	static EnumPropertyItem brush_gradient_items[] = {
 		{BRUSH_GRADIENT_PRESSURE, "PRESSURE", 0, "Pressure", ""},
 		{BRUSH_GRADIENT_SPACING_REPEAT, "SPACING_REPEAT", 0, "Repeat", ""},
@@ -1038,6 +1044,18 @@
 	RNA_def_property_ui_text(prop, "Sharp Threshold", "Threshold below which, no sharpening is done");
 	RNA_def_property_update(prop, 0, "rna_Brush_update");
 
+	prop = RNA_def_property(srna, "blur_kernel_radius", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "blur_kernel_radius");
+	RNA_def_property_range(prop, 1, 10000);
+	RNA_def_property_ui_range(prop, 1, 50, 1, -1);
+	RNA_def_property_ui_text(prop, "Kernel Radius", "Radius of kernel used for soften and sharpen in pixels");
+	RNA_def_property_update(prop, 0, "rna_Brush_update");
+
+	prop = RNA_def_property(srna, "blur_mode", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_items(prop, brush_blur_mode_items);
+	RNA_def_property_ui_text(prop, "Blur Mode", "");
+	RNA_def_property_update(prop, 0, "rna_Brush_update");
+
 	/* flag */
 	prop = RNA_def_property(srna, "use_airbrush", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_AIRBRUSH);




More information about the Bf-blender-cvs mailing list