~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_hueSatVal.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: CMP_hueSatVal.c,v 1.4 2007/04/04 13:58:10 jesterking Exp $
 
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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
                if(hsv[1]>1.0) hsv[1]= 1.0; else if(hsv[1]<0.0) hsv[1]= 0.0;
 
56
                hsv[2]*= nhs->val;
 
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);
 
59
                
 
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];
 
63
                out[3]= in[3];
 
64
        }
 
65
        else {
 
66
                QUATCOPY(out, in);
 
67
        }
 
68
}
 
69
 
 
70
static void node_composit_exec_hue_sat(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
71
{
 
72
        /* stack order in: Fac, Image */
 
73
        /* stack order out: Image */
 
74
        if(out[0]->hasoutput==0) return;
 
75
        
 
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);
 
79
        }
 
80
        else {
 
81
                /* make output size of input image */
 
82
                CompBuf *cbuf= dupalloc_compbuf(in[1]->data);
 
83
                CompBuf *stackbuf=typecheck_compbuf(cbuf,CB_RGBA);
 
84
                
 
85
                composit2_pixel_processor(node, stackbuf, stackbuf, in[1]->vec, in[0]->data, in[0]->vec, do_hue_sat_fac, CB_RGBA, CB_VAL);
 
86
 
 
87
                out[0]->data= stackbuf;
 
88
 
 
89
                /* get rid of intermediary cbuf if it's extra */                
 
90
                if(stackbuf!=cbuf)
 
91
                        free_compbuf(cbuf);
 
92
        }
 
93
}
 
94
 
 
95
static void node_composit_init_hue_sat(bNode* node)
 
96
{
 
97
   NodeHueSat *nhs= MEM_callocN(sizeof(NodeHueSat), "node hue sat");
 
98
   node->storage= nhs;
 
99
   nhs->hue= 0.5f;
 
100
   nhs->sat= 1.0f;
 
101
   nhs->val= 1.0f;
 
102
}
 
103
 
 
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,
 
114
        /* butfunc     */       NULL,
 
115
        /* initfunc    */       node_composit_init_hue_sat,
 
116
        /* freestoragefunc    */        node_free_standard_storage,
 
117
        /* copystoragefunc    */        node_copy_standard_storage,
 
118
        /* id          */       NULL
 
119
        
 
120
};
 
121
 
 
122