diff options
author | Juho Vepsalainen <bebraw@gmail.com> | 2008-01-07 18:44:45 +0300 |
---|---|---|
committer | Juho Vepsalainen <bebraw@gmail.com> | 2008-01-07 18:44:45 +0300 |
commit | adc68be1a87781112667005455e13f4f1514a7f2 (patch) | |
tree | 357b74931b5594dbe3ebeee306e1521d0eb2310f /source | |
parent | 011e0a93dde724650a6ec6315110c4d6bc615913 (diff) |
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!
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesdna/DNA_node_types.h | 8 | ||||
-rw-r--r-- | source/blender/nodes/intern/CMP_nodes/CMP_blur.c | 15 | ||||
-rw-r--r-- | source/blender/src/drawnode.c | 63 |
3 files changed, 70 insertions, 16 deletions
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index ceab9a1c9c1..a600e2b995b 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -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 { diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_blur.c b/source/blender/nodes/intern/CMP_nodes/CMP_blur.c index 8ef4af4d219..3d6b3dd2955 100644 --- a/source/blender/nodes/intern/CMP_nodes/CMP_blur.c +++ b/source/blender/nodes/intern/CMP_nodes/CMP_blur.c @@ -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; diff --git a/source/blender/src/drawnode.c b/source/blender/src/drawnode.c index 491ecb6e741..a69021a66b4 100644 --- a/source/blender/src/drawnode.c +++ b/source/blender/src/drawnode.c @@ -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; |