2
* $Id: CMP_hueSatVal.c,v 1.4 2007/04/04 13:58:10 jesterking Exp $
4
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* The Original Code is Copyright (C) 2006 Blender Foundation.
21
* All rights reserved.
23
* The Original Code is: all of this file.
25
* Contributor(s): none yet.
27
* ***** END GPL LICENSE BLOCK *****
30
#include "../CMP_util.h"
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},
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},
44
static void do_hue_sat_fac(bNode *node, float *out, float *in, float *fac)
46
NodeHueSat *nhs= node->storage;
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;
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;
55
if(hsv[1]>1.0) hsv[1]= 1.0; else if(hsv[1]<0.0) hsv[1]= 0.0;
57
if(hsv[2]>1.0) hsv[2]= 1.0; else if(hsv[2]<0.0) hsv[2]= 0.0;
58
hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
60
out[0]= mfac*in[0] + *fac*col[0];
61
out[1]= mfac*in[1] + *fac*col[1];
62
out[2]= mfac*in[2] + *fac*col[2];
70
static void node_composit_exec_hue_sat(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
72
/* stack order in: Fac, Image */
73
/* stack order out: Image */
74
if(out[0]->hasoutput==0) return;
76
/* input no image? then only color operation */
77
if(in[1]->data==NULL) {
78
do_hue_sat_fac(node, out[0]->vec, in[1]->vec, in[0]->vec);
81
/* make output size of input image */
82
CompBuf *cbuf= dupalloc_compbuf(in[1]->data);
83
CompBuf *stackbuf=typecheck_compbuf(cbuf,CB_RGBA);
85
composit2_pixel_processor(node, stackbuf, stackbuf, in[1]->vec, in[0]->data, in[0]->vec, do_hue_sat_fac, CB_RGBA, CB_VAL);
87
out[0]->data= stackbuf;
89
/* get rid of intermediary cbuf if it's extra */
95
static void node_composit_init_hue_sat(bNode* node)
97
NodeHueSat *nhs= MEM_callocN(sizeof(NodeHueSat), "node hue sat");
104
bNodeType cmp_node_hue_sat= {
105
/* *next,*prev */ NULL, NULL,
106
/* type code */ CMP_NODE_HUE_SAT,
107
/* name */ "Hue Saturation Value",
108
/* width+range */ 150, 80, 250,
109
/* class+opts */ NODE_CLASS_OP_COLOR, NODE_OPTIONS,
110
/* input sock */ cmp_node_hue_sat_in,
111
/* output sock */ cmp_node_hue_sat_out,
112
/* storage */ "NodeHueSat",
113
/* execfunc */ node_composit_exec_hue_sat,
115
/* initfunc */ node_composit_init_hue_sat,
116
/* freestoragefunc */ node_free_standard_storage,
117
/* copystoragefunc */ node_copy_standard_storage,