[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13155] trunk/blender/source/blender: Blur Node to support Relative (percent) values

Juho Vepsalainen bebraw at gmail.com
Mon Jan 7 16:44:45 CET 2008


Revision: 13155
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13155
Author:   bebraw
Date:     2008-01-07 16:44:45 +0100 (Mon, 07 Jan 2008)

Log Message:
-----------
Blur Node to support Relative (percent) values
This commit makes it possible to use relative values when using a Blur node. There
is a new toggle in the node that can be used to enable the feature.

Thanks to David Millan Escriva for contribution!

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_blur.c
    trunk/blender/source/blender/src/drawnode.c

Modified: trunk/blender/source/blender/makesdna/DNA_node_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_node_types.h	2008-01-07 13:55:48 UTC (rev 13154)
+++ trunk/blender/source/blender/makesdna/DNA_node_types.h	2008-01-07 15:44:45 UTC (rev 13155)
@@ -196,11 +196,13 @@
 } NodeImageAnim;
 
 typedef struct NodeBlurData {
-	short sizex, sizey, samples, maxspeed, minspeed, pad1;
-	float fac;
+	short sizex, sizey;
+	short samples, maxspeed, minspeed, relative;
+	float fac, percentx, percenty;
 	short filtertype;
 	char bokeh, gamma;
-	int pad2;
+	int pad;
+	int image_in_width, image_in_height; /* needed for absolute/relative conversions */
 } NodeBlurData;
 
 typedef struct NodeDBlurData {

Modified: trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_blur.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_blur.c	2008-01-07 13:55:48 UTC (rev 13154)
+++ trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_blur.c	2008-01-07 15:44:45 UTC (rev 13155)
@@ -22,7 +22,8 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Campbell Barton, Alfredo de Greef, David Millan Escriva,
+ * Juho Vepsäläinen
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -556,16 +557,20 @@
 static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 {
 	CompBuf *new, *img= in[0]->data;
+	NodeBlurData *nbd= node->storage;
 	
-	if(img==NULL || out[0]->hasoutput==0)
-		return;
+	if(img==NULL) return;
 	
+	/* store image in size that is needed for absolute/relative conversions on ui level */
+	nbd->image_in_width= img->x;
+	nbd->image_in_height= img->y;
+	
+	if(out[0]->hasoutput==0) return;
+	
 	if (((NodeBlurData *)node->storage)->filtertype == R_FILTER_FAST_GAUSS) {
 		CompBuf *new, *img = in[0]->data;
 		/*from eeshlo's original patch, removed to fit in with the existing blur node */
 		/*const float sx = in[1]->vec[0], sy = in[2]->vec[0];*/
-	
-		NodeBlurData *nbd= node->storage;
 		const float sx = ((float)nbd->sizex)/2.0f, sy = ((float)nbd->sizey)/2.0f;
 		int c;
 

Modified: trunk/blender/source/blender/src/drawnode.c
===================================================================
--- trunk/blender/source/blender/src/drawnode.c	2008-01-07 13:55:48 UTC (rev 13154)
+++ trunk/blender/source/blender/src/drawnode.c	2008-01-07 15:44:45 UTC (rev 13155)
@@ -22,7 +22,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): David Millan Escriva, Juho Vepsäläinen
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -1047,12 +1047,41 @@
 	return 19;
 }
 
+static void node_blur_relative_cb(void *node, void *poin2)
+{
+	bNode *nodev= node;
+	NodeBlurData *nbd= nodev->storage;
+	if(nbd->image_in_width != 0){
+		if(nbd->relative){ /* convert absolute values to relative */
+			nbd->percentx= (float)(nbd->sizex)/nbd->image_in_width;
+			nbd->percenty= (float)(nbd->sizey)/nbd->image_in_height;
+		}else{ /* convert relative values to absolute */
+			nbd->sizex= (int)(nbd->percentx*nbd->image_in_width);
+			nbd->sizey= (int)(nbd->percenty*nbd->image_in_height);
+		}
+	}
+	allqueue(REDRAWNODE, 0);
+}
+static void node_blur_update_sizex_cb(void *node, void *poin2)
+{
+	bNode *nodev= node;
+	NodeBlurData *nbd= nodev->storage;
+
+	nbd->sizex= (int)(nbd->percentx*nbd->image_in_width);
+}
+static void node_blur_update_sizey_cb(void *node, void *poin2)
+{
+	bNode *nodev= node;
+	NodeBlurData *nbd= nodev->storage;
+
+	nbd->sizey= (int)(nbd->percenty*nbd->image_in_height);
+}
 static int node_composit_buts_blur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
 {
 	if(block) {
 		NodeBlurData *nbd= node->storage;
 		uiBut *bt;
-		short dy= butr->ymin+38;
+		short dy= butr->ymin+58;
 		short dx= (butr->xmax-butr->xmin)/2;
 		char str[256];
 		
@@ -1074,12 +1103,30 @@
 			uiBlockBeginAlign(block);
 		}
 		dy-=19;
-		bt=uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "X:",
-					 butr->xmin, dy, dx, 19, 
-					 &nbd->sizex, 0, 256, 0, 0, "");
-		bt=uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Y:",
-					 butr->xmin+dx, dy, dx, 19, 
-					 &nbd->sizey, 0, 256, 0, 0, "");
+		bt= uiDefButS(block, TOG, B_NOP, "Relative",
+				  butr->xmin, dy, dx*2, 19,
+				  &nbd->relative, 0, 0, 0, 0, "Use relative (percent) values to define blur radius");
+		uiButSetFunc(bt, node_blur_relative_cb, node, NULL);
+
+		dy-=19;
+		if(nbd->relative) {
+			bt= uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "X:",
+						 butr->xmin, dy, dx, 19, 
+						 &nbd->percentx, 0.0f, 1.0f, 0, 0, "");
+			uiButSetFunc(bt, node_blur_update_sizex_cb, node, NULL);
+			bt= uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Y:",
+						 butr->xmin+dx, dy, dx, 19, 
+						 &nbd->percenty, 0.0f, 1.0f, 0, 0, "");
+			uiButSetFunc(bt, node_blur_update_sizey_cb, node, NULL);
+		}
+		else {
+			uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "X:",
+						 butr->xmin, dy, dx, 19, 
+						 &nbd->sizex, 0, 256, 0, 0, "");
+			uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Y:",
+						 butr->xmin+dx, dy, dx, 19, 
+						 &nbd->sizey, 0, 256, 0, 0, "");
+		}
 		uiBlockEndAlign(block);
 	}
 	return 57;





More information about the Bf-blender-cvs mailing list