Blender V2.61 - r43446

node_composite_brightness.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  * 
00018  * The Original Code is Copyright (C) 2006 Blender Foundation.
00019  * All rights reserved.
00020  * 
00021  * The Original Code is: all of this file.
00022  * 
00023  * Contributor(s): none yet.
00024  * 
00025  * ***** END GPL LICENSE BLOCK *****
00026 
00027 */
00028 
00034 #include "node_composite_util.h"
00035 
00036 
00037 /* **************** Brigh and contrsast  ******************** */
00038 
00039 static bNodeSocketTemplate cmp_node_brightcontrast_in[]= {
00040     {   SOCK_RGBA, 1, "Image",          1.0f, 1.0f, 1.0f, 1.0f},
00041     {   SOCK_FLOAT, 1, "Bright",        0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
00042     {   SOCK_FLOAT, 1, "Contrast",      0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
00043     {   -1, 0, ""   }
00044 };
00045 static bNodeSocketTemplate cmp_node_brightcontrast_out[]= {
00046     {   SOCK_RGBA, 0, "Image"},
00047     {   -1, 0, ""   }
00048 };
00049 
00050 static void do_brightnesscontrast(bNode *UNUSED(node), float *out, float *in, float *in_brightness, float *in_contrast)
00051 {
00052     float i;
00053     int c;
00054     float a, b, v;
00055     float brightness = (*in_brightness) / 100.0f;
00056     float contrast = *in_contrast;
00057     float delta = contrast / 200.0f;
00058     a = 1.0f - delta * 2.0f;
00059     /*
00060     * The algorithm is by Werner D. Streidt
00061     * (http://visca.com/ffactory/archives/5-99/msg00021.html)
00062     * Extracted of OpenCV demhist.c
00063     */
00064     if( contrast > 0 )
00065 {
00066         a = 1.0f / a;
00067         b = a * (brightness - delta);
00068     }
00069     else
00070     {
00071         delta *= -1;
00072         b = a * (brightness + delta);
00073     }
00074     
00075     for(c=0; c<3; c++){        
00076         i = in[c];
00077         v = a*i + b;
00078         out[c] = v;
00079     }
00080 }
00081 
00082 static void node_composit_exec_brightcontrast(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00083 {
00084     if(out[0]->hasoutput==0)
00085         return;
00086     
00087     if(in[0]->data) {
00088         CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
00089         stackbuf= dupalloc_compbuf(cbuf);
00090         composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, do_brightnesscontrast, CB_RGBA, CB_VAL, CB_VAL);
00091         out[0]->data = stackbuf;
00092         if(cbuf != in[0]->data)
00093             free_compbuf(cbuf);
00094     }
00095 }
00096 
00097 void register_node_type_cmp_brightcontrast(bNodeTreeType *ttype)
00098 {
00099     static bNodeType ntype;
00100     
00101     node_type_base(ttype, &ntype, CMP_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
00102     node_type_socket_templates(&ntype, cmp_node_brightcontrast_in, cmp_node_brightcontrast_out);
00103     node_type_size(&ntype, 140, 100, 320);
00104     node_type_exec(&ntype, node_composit_exec_brightcontrast);
00105     
00106     nodeRegisterType(ttype, &ntype);
00107 }