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

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_valToRgb.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_valToRgb.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
/* **************** VALTORGB ******************** */
 
34
static bNodeSocketType cmp_node_valtorgb_in[]= {
 
35
        {       SOCK_VALUE, 1, "Fac",                   0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
 
36
        {       -1, 0, ""       }
 
37
};
 
38
static bNodeSocketType cmp_node_valtorgb_out[]= {
 
39
        {       SOCK_RGBA, 0, "Image",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
40
        {       SOCK_VALUE, 0, "Alpha",                 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
 
41
        {       -1, 0, ""       }
 
42
};
 
43
 
 
44
static void do_colorband_composit(bNode *node, float *out, float *in)
 
45
{
 
46
        do_colorband(node->storage, in[0], out);
 
47
}
 
48
 
 
49
static void node_composit_exec_valtorgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
50
{
 
51
        /* stack order in: fac */
 
52
        /* stack order out: col, alpha */
 
53
        
 
54
        if(out[0]->hasoutput==0 && out[1]->hasoutput==0) 
 
55
                return;
 
56
        
 
57
        if(node->storage) {
 
58
                /* input no image? then only color operation */
 
59
                if(in[0]->data==NULL) {
 
60
                        do_colorband(node->storage, in[0]->vec[0], out[0]->vec);
 
61
                }
 
62
                else {
 
63
                        /* make output size of input image */
 
64
                        CompBuf *cbuf= in[0]->data;
 
65
                        CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
 
66
                        
 
67
                        composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_colorband_composit, CB_VAL);
 
68
                        
 
69
                        out[0]->data= stackbuf;
 
70
                        
 
71
                        if(out[1]->hasoutput)
 
72
                                out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A);
 
73
 
 
74
                }
 
75
        }
 
76
}
 
77
 
 
78
static void node_composit_init_valtorgb(bNode* node)
 
79
{
 
80
   node->storage= add_colorband(1);
 
81
}
 
82
 
 
83
bNodeType cmp_node_valtorgb= {
 
84
        /* *next,*prev */       NULL, NULL,
 
85
        /* type code   */       CMP_NODE_VALTORGB,
 
86
        /* name        */       "ColorRamp",
 
87
        /* width+range */       240, 200, 300,
 
88
        /* class+opts  */       NODE_CLASS_CONVERTOR, NODE_OPTIONS,
 
89
        /* input sock  */       cmp_node_valtorgb_in,
 
90
        /* output sock */       cmp_node_valtorgb_out,
 
91
        /* storage     */       "ColorBand",
 
92
        /* execfunc    */       node_composit_exec_valtorgb,
 
93
        /* butfunc     */       NULL,
 
94
        /* initfunc    */       node_composit_init_valtorgb,
 
95
        /* freestoragefunc    */        node_free_standard_storage,
 
96
        /* copystoragefunc    */        node_copy_standard_storage,
 
97
        /* id          */       NULL
 
98
        
 
99
};
 
100
 
 
101
 
 
102
/* **************** RGBTOBW ******************** */
 
103
static bNodeSocketType cmp_node_rgbtobw_in[]= {
 
104
        {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
 
105
        {       -1, 0, ""       }
 
106
};
 
107
static bNodeSocketType cmp_node_rgbtobw_out[]= {
 
108
        {       SOCK_VALUE, 0, "Val",                   0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
109
        {       -1, 0, ""       }
 
110
};
 
111
 
 
112
static void do_rgbtobw(bNode *node, float *out, float *in)
 
113
{
 
114
        out[0]= in[0]*0.35f + in[1]*0.45f + in[2]*0.2f;
 
115
}
 
116
 
 
117
static void node_composit_exec_rgbtobw(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
118
{
 
119
        /* stack order out: bw */
 
120
        /* stack order in: col */
 
121
        
 
122
        if(out[0]->hasoutput==0)
 
123
                return;
 
124
        
 
125
        /* input no image? then only color operation */
 
126
        if(in[0]->data==NULL) {
 
127
                do_rgbtobw(node, out[0]->vec, in[0]->vec);
 
128
        }
 
129
        else {
 
130
                /* make output size of input image */
 
131
                CompBuf *cbuf= in[0]->data;
 
132
                CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
 
133
                
 
134
                composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_rgbtobw, CB_RGBA);
 
135
                
 
136
                out[0]->data= stackbuf;
 
137
        }
 
138
}
 
139
 
 
140
bNodeType cmp_node_rgbtobw= {
 
141
        /* *next,*prev */       NULL, NULL,
 
142
        /* type code   */       CMP_NODE_RGBTOBW,
 
143
        /* name        */       "RGB to BW",
 
144
        /* width+range */       80, 40, 120,
 
145
        /* class+opts  */       NODE_CLASS_CONVERTOR, 0,
 
146
        /* input sock  */       cmp_node_rgbtobw_in,
 
147
        /* output sock */       cmp_node_rgbtobw_out,
 
148
        /* storage     */       "",
 
149
        /* execfunc    */       node_composit_exec_rgbtobw,
 
150
        /* butfunc     */       NULL,
 
151
        /* freestoragefunc    */        NULL,
 
152
        /* copystoragefunc    */        NULL,
 
153
        /* id          */       NULL
 
154
        
 
155
};
 
156
 
 
157