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!
This commit is contained in:
2008-01-07 15:44:45 +00:00
parent 011e0a93dd
commit adc68be1a8
3 changed files with 70 additions and 16 deletions

View File

@@ -196,11 +196,13 @@ typedef struct NodeImageAnim {
} 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 {

View File

@@ -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 blur_with_reference(bNode *node, CompBuf *new, CompBuf *img, CompBuf
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;

View File

@@ -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 @@ static int node_composit_buts_renderlayers(uiBlock *block, bNodeTree *ntree, bNo
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 @@ static int node_composit_buts_blur(uiBlock *block, bNodeTree *ntree, bNode *node
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;