converted more mixed tab/space indentations to tabs. only whitespace changes.
[blender.git] / source / blender / nodes / intern / CMP_nodes / CMP_hueSatVal.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2006 Blender Foundation.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file blender/nodes/intern/CMP_nodes/CMP_hueSatVal.c
31  *  \ingroup cmpnodes
32  */
33
34
35 #include "../CMP_util.h"
36
37
38 /* **************** Hue Saturation ******************** */
39 static bNodeSocketType cmp_node_hue_sat_in[]= {
40         {       SOCK_VALUE, 1, "Fac",                   1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
41         {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
42         {       -1, 0, ""       }
43 };
44 static bNodeSocketType cmp_node_hue_sat_out[]= {
45         {       SOCK_RGBA, 0, "Image",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
46         {       -1, 0, ""       }
47 };
48
49 static void do_hue_sat_fac(bNode *node, float *out, float *in, float *fac)
50 {
51         NodeHueSat *nhs= node->storage;
52         
53         if(*fac!=0.0f && (nhs->hue!=0.5f || nhs->sat!=1.0 || nhs->val!=1.0)) {
54                 float col[3], hsv[3], mfac= 1.0f - *fac;
55                 
56                 rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2);
57                 hsv[0]+= (nhs->hue - 0.5f);
58                 if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0;
59                 hsv[1]*= nhs->sat;
60                 hsv[2]*= nhs->val;
61                 hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
62                 
63                 out[0]= mfac*in[0] + *fac*col[0];
64                 out[1]= mfac*in[1] + *fac*col[1];
65                 out[2]= mfac*in[2] + *fac*col[2];
66                 out[3]= in[3];
67         }
68         else {
69                 QUATCOPY(out, in);
70         }
71 }
72
73 static void node_composit_exec_hue_sat(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
74 {
75         /* stack order in: Fac, Image */
76         /* stack order out: Image */
77         if(out[0]->hasoutput==0) return;
78         
79         /* input no image? then only color operation */
80         if(in[1]->data==NULL) {
81                 do_hue_sat_fac(node, out[0]->vec, in[1]->vec, in[0]->vec);
82         }
83         else {
84                 /* make output size of input image */
85                 CompBuf *cbuf= dupalloc_compbuf(in[1]->data);
86                 CompBuf *stackbuf=typecheck_compbuf(cbuf,CB_RGBA);
87                 
88                 composit2_pixel_processor(node, stackbuf, stackbuf, in[1]->vec, in[0]->data, in[0]->vec, do_hue_sat_fac, CB_RGBA, CB_VAL);
89
90                 out[0]->data= stackbuf;
91
92                 /* get rid of intermediary cbuf if it's extra */                
93                 if(stackbuf!=cbuf)
94                         free_compbuf(cbuf);
95         }
96 }
97
98 static void node_composit_init_hue_sat(bNode* node)
99 {
100         NodeHueSat *nhs= MEM_callocN(sizeof(NodeHueSat), "node hue sat");
101         node->storage= nhs;
102         nhs->hue= 0.5f;
103         nhs->sat= 1.0f;
104         nhs->val= 1.0f;
105 }
106
107 void register_node_type_cmp_hue_sat(ListBase *lb)
108 {
109         static bNodeType ntype;
110
111         node_type_base(&ntype, CMP_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, NODE_OPTIONS,
112                 cmp_node_hue_sat_in, cmp_node_hue_sat_out);
113         node_type_size(&ntype, 150, 80, 250);
114         node_type_init(&ntype, node_composit_init_hue_sat);
115         node_type_storage(&ntype, "NodeHueSat", node_free_standard_storage, node_copy_standard_storage);
116         node_type_exec(&ntype, node_composit_exec_hue_sat);
117
118         nodeRegisterType(lb, &ntype);
119 }
120
121
122