doxygen: prevent GPL license block from being parsed as doxygen comment.
[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 #include "../CMP_util.h"
31
32
33 /* **************** Hue Saturation ******************** */
34 static bNodeSocketType cmp_node_hue_sat_in[]= {
35         {       SOCK_VALUE, 1, "Fac",                   1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
36         {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
37         {       -1, 0, ""       }
38 };
39 static bNodeSocketType cmp_node_hue_sat_out[]= {
40         {       SOCK_RGBA, 0, "Image",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
41         {       -1, 0, ""       }
42 };
43
44 static void do_hue_sat_fac(bNode *node, float *out, float *in, float *fac)
45 {
46         NodeHueSat *nhs= node->storage;
47         
48         if(*fac!=0.0f && (nhs->hue!=0.5f || nhs->sat!=1.0 || nhs->val!=1.0)) {
49                 float col[3], hsv[3], mfac= 1.0f - *fac;
50                 
51                 rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2);
52                 hsv[0]+= (nhs->hue - 0.5f);
53                 if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0;
54                 hsv[1]*= nhs->sat;
55                 hsv[2]*= nhs->val;
56                 hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
57                 
58                 out[0]= mfac*in[0] + *fac*col[0];
59                 out[1]= mfac*in[1] + *fac*col[1];
60                 out[2]= mfac*in[2] + *fac*col[2];
61                 out[3]= in[3];
62         }
63         else {
64                 QUATCOPY(out, in);
65         }
66 }
67
68 static void node_composit_exec_hue_sat(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
69 {
70         /* stack order in: Fac, Image */
71         /* stack order out: Image */
72         if(out[0]->hasoutput==0) return;
73         
74         /* input no image? then only color operation */
75         if(in[1]->data==NULL) {
76                 do_hue_sat_fac(node, out[0]->vec, in[1]->vec, in[0]->vec);
77         }
78         else {
79                 /* make output size of input image */
80                 CompBuf *cbuf= dupalloc_compbuf(in[1]->data);
81                 CompBuf *stackbuf=typecheck_compbuf(cbuf,CB_RGBA);
82                 
83                 composit2_pixel_processor(node, stackbuf, stackbuf, in[1]->vec, in[0]->data, in[0]->vec, do_hue_sat_fac, CB_RGBA, CB_VAL);
84
85                 out[0]->data= stackbuf;
86
87                 /* get rid of intermediary cbuf if it's extra */                
88                 if(stackbuf!=cbuf)
89                         free_compbuf(cbuf);
90         }
91 }
92
93 static void node_composit_init_hue_sat(bNode* node)
94 {
95    NodeHueSat *nhs= MEM_callocN(sizeof(NodeHueSat), "node hue sat");
96    node->storage= nhs;
97    nhs->hue= 0.5f;
98    nhs->sat= 1.0f;
99    nhs->val= 1.0f;
100 }
101
102 void register_node_type_cmp_hue_sat(ListBase *lb)
103 {
104         static bNodeType ntype;
105
106         node_type_base(&ntype, CMP_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, NODE_OPTIONS,
107                 cmp_node_hue_sat_in, cmp_node_hue_sat_out);
108         node_type_size(&ntype, 150, 80, 250);
109         node_type_init(&ntype, node_composit_init_hue_sat);
110         node_type_storage(&ntype, "NodeHueSat", node_free_standard_storage, node_copy_standard_storage);
111         node_type_exec(&ntype, node_composit_exec_hue_sat);
112
113         nodeRegisterType(lb, &ntype);
114 }
115
116
117