diff options
author | Robert Holcomb <bob_holcomb@hotmail.com> | 2007-04-13 07:23:39 +0400 |
---|---|---|
committer | Robert Holcomb <bob_holcomb@hotmail.com> | 2007-04-13 07:23:39 +0400 |
commit | f7738575c94eaf215a95a1169ff3ea16d96862e6 (patch) | |
tree | b28ffd6bd4d61b6cab7b24077856ce08595bbab5 /source | |
parent | 6ec705e54b17de42d3297f48bb0fbfb23074d310 (diff) |
Added brightness/contrast node
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 2 | ||||
-rw-r--r-- | source/blender/nodes/CMP_node.h | 2 | ||||
-rw-r--r-- | source/blender/nodes/intern/CMP_nodes/CMP_brightness.c | 113 |
4 files changed, 119 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index cde75f2091f..95d26aa0abd 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -294,6 +294,8 @@ void set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, str #define CMP_NODE_MATH 247 #define CMP_NODE_LUMA_MATTE 248 +#define CMP_NODE_BRIGHTCONTRAST 249 + /* filter types */ #define CMP_FILT_SOFT 0 #define CMP_FILT_SHARP 1 diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index b3eabe126bb..93b629e0ef3 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -2361,6 +2361,8 @@ static void registerCompositNodes(ListBase *ntypelist) nodeRegisterType(ntypelist, &cmp_node_flip); nodeRegisterType(ntypelist, &cmp_node_displace); nodeRegisterType(ntypelist, &cmp_node_mapuv); + + nodeRegisterType(ntypelist, &cmp_node_brightcontrast); } static void registerShaderNodes(ListBase *ntypelist) diff --git a/source/blender/nodes/CMP_node.h b/source/blender/nodes/CMP_node.h index 8335538e448..77e70a3c126 100644 --- a/source/blender/nodes/CMP_node.h +++ b/source/blender/nodes/CMP_node.h @@ -93,6 +93,8 @@ extern bNodeType cmp_node_flip; extern bNodeType cmp_node_displace; extern bNodeType cmp_node_mapuv; +extern bNodeType cmp_node_brightcontrast; + #endif diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_brightness.c b/source/blender/nodes/intern/CMP_nodes/CMP_brightness.c new file mode 100644 index 00000000000..bb411a47d34 --- /dev/null +++ b/source/blender/nodes/intern/CMP_nodes/CMP_brightness.c @@ -0,0 +1,113 @@ +/** +* $Id$ +* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* The Original Code is Copyright (C) 2006 Blender Foundation. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): none yet. +* +* ***** END GPL LICENSE BLOCK ***** + +*/ + +#include "../CMP_util.h" + + +/* **************** Brigh and contrsast ******************** */ + +static bNodeSocketType cmp_node_brightcontrsast_in[]= { + { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { SOCK_VALUE, 1, "bright", 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f}, + { SOCK_VALUE, 1, "contrast", 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f}, + { -1, 0, "" } +}; +static bNodeSocketType cmp_node_brightcontrsast_out[]= { + { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void do_brightnesscontrast(bNode *node, float *out, float *in) +{ + float i; + int c; + float a, b, contrast, brightness, delta, v; + contrast = node->custom2; + brightness = (float)(node->custom1); + brightness = (brightness) / 100.0f; + delta = contrast / 200.0f; + a = 1.0f - delta * 2.0f; + /* + * The algorithm is by Werner D. Streidt + * (http://visca.com/ffactory/archives/5-99/msg00021.html) + * Extracted of OpenCV demhist.c + */ + if( contrast > 0 ) +{ + a = 1.0f / a; + b = a * (brightness - delta); + } + else + { + delta *= -1; + b = a * (brightness + delta); + } + + for(c=0; c<3; c++){ + i = in[c]; + v = a*i + b; + out[c] = v; + } +} + +static void node_composit_exec_brightcontrsast(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + if(out[0]->hasoutput==0) + return; + + if(in[0]->data) { + CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); + node->custom1 = in[1]->vec[0]; + node->custom2 = in[2]->vec[0]; + stackbuf= dupalloc_compbuf(cbuf); + composit1_pixel_processor(node, stackbuf, cbuf, in[0]->vec, do_brightnesscontrast, CB_RGBA); + out[0]->data = stackbuf; + if(cbuf != in[0]->data) + free_compbuf(cbuf); + } +} + +bNodeType cmp_node_brighcontrast= { + /* *next,*prev */ NULL, NULL, + /* type code */ CMP_NODE_BRIGHTCONTRAST, + /* name */ "Bright/Contrast", + /* width+range */ 140, 100, 320, + /* class+opts */ NODE_CLASS_OP_COLOR, NODE_OPTIONS, + /* input sock */ cmp_node_brightcontrsast_in, + /* output sock */ cmp_node_brightcontrsast_out, + /* storage */ "", + /* execfunc */ node_composit_exec_brightcontrsast, + /* butfunc */ NULL, + /* initfunc */ NULL, + /* freestoragefunc */ NULL, + /* copysotragefunc */ NULL, + /* id */ NULL +}; + |