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

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_sepcombYCCA.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_sepcombYCCA.c,v 1.5 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
/* **************** SEPARATE YCCA ******************** */
 
34
static bNodeSocketType cmp_node_sepycca_in[]= {
 
35
        {  SOCK_RGBA, 1, "Image",        0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
 
36
        {  -1, 0, ""   }
 
37
};
 
38
static bNodeSocketType cmp_node_sepycca_out[]= {
 
39
        {  SOCK_VALUE, 0, "Y",        0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
40
        {  SOCK_VALUE, 0, "Cb",       0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
41
        {  SOCK_VALUE, 0, "Cr",       0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
42
        {  SOCK_VALUE, 0, "A",        0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
43
        {  -1, 0, ""   }
 
44
};
 
45
 
 
46
static void do_sepycca(bNode *node, float *out, float *in)
 
47
{
 
48
        float y, cb, cr;
 
49
        
 
50
        rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr);
 
51
        
 
52
        /*divided by 255 to normalize for viewing in */
 
53
        out[0]= y/255.0;
 
54
        out[1]= cb/255.0;
 
55
        out[2]= cr/255.0;
 
56
        out[3]= in[3];
 
57
}
 
58
 
 
59
static void node_composit_exec_sepycca(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
60
{
 
61
        /* input no image? then only color operation */
 
62
        if(in[0]->data==NULL) {
 
63
                float y, cb, cr;
 
64
        
 
65
                rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr);
 
66
        
 
67
                /*divided by 255 to normalize for viewing in */
 
68
                out[0]->vec[0] = y/255.0;
 
69
                out[1]->vec[0] = cb/255.0;
 
70
                out[2]->vec[0] = cr/255.0;
 
71
                out[3]->vec[0] = in[0]->vec[3];
 
72
        }
 
73
        else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) {
 
74
                /* make copy of buffer so input buffer doesn't get corrupted */
 
75
                CompBuf *cbuf= dupalloc_compbuf(in[0]->data);
 
76
                CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA);
 
77
        
 
78
                /* convert the RGB stackbuf to an HSV representation */
 
79
                composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca, CB_RGBA);
 
80
        
 
81
                /* separate each of those channels */
 
82
                if(out[0]->hasoutput)
 
83
                        out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R);
 
84
                if(out[1]->hasoutput)
 
85
                        out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G);
 
86
                if(out[2]->hasoutput)
 
87
                        out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B);
 
88
                if(out[3]->hasoutput)
 
89
                        out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A);
 
90
 
 
91
                /*not used anymore */
 
92
                if(cbuf2!=cbuf)
 
93
                        free_compbuf(cbuf2);
 
94
                free_compbuf(cbuf);
 
95
        }
 
96
}
 
97
 
 
98
bNodeType cmp_node_sepycca= {
 
99
        /* *next,*prev */       NULL, NULL,
 
100
        /* type code   */       CMP_NODE_SEPYCCA,
 
101
        /* name        */       "Separate YCbCrA",
 
102
        /* width+range */       80, 40, 140,
 
103
        /* class+opts  */       NODE_CLASS_CONVERTOR, 0,
 
104
        /* input sock  */       cmp_node_sepycca_in,
 
105
        /* output sock */       cmp_node_sepycca_out,
 
106
        /* storage     */       "",
 
107
        /* execfunc    */       node_composit_exec_sepycca,
 
108
        /* butfunc     */       NULL,
 
109
        /* initfunc    */       NULL,
 
110
        /* freestoragefunc    */        NULL,
 
111
        /* copystoragefunc    */        NULL,
 
112
        /* id          */       NULL
 
113
};
 
114
 
 
115
 
 
116
/* **************** COMBINE YCCA ******************** */
 
117
static bNodeSocketType cmp_node_combycca_in[]= {
 
118
        {       SOCK_VALUE, 1, "Y",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
119
        {       SOCK_VALUE, 1, "Cb",                    0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
120
        {       SOCK_VALUE, 1, "Cr",                    0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
121
        {       SOCK_VALUE, 1, "A",                     1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
122
        {       -1, 0, ""       }
 
123
};
 
124
static bNodeSocketType cmp_node_combycca_out[]= {
 
125
        {       SOCK_RGBA, 0, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
 
126
        {       -1, 0, ""       }
 
127
};
 
128
 
 
129
static void do_comb_ycca(bNode *node, float *out, float *in1, float *in2, float *in3, float *in4)
 
130
{
 
131
        float r,g,b;
 
132
        float y, cb, cr;
 
133
 
 
134
        /*need to un-normalize the data*/
 
135
        y=in1[0]*255;
 
136
        cb=in2[0]*255;
 
137
        cr=in3[0]*255;
 
138
 
 
139
        ycc_to_rgb(y,cb,cr, &r, &g, &b);
 
140
        
 
141
        out[0] = r;
 
142
        out[1] = g;
 
143
        out[2] = b;
 
144
        out[3] = in4[0];
 
145
}
 
146
 
 
147
static void node_composit_exec_combycca(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
148
{
 
149
        /* stack order out: 1 ycca channels */
 
150
        /* stack order in: 4 value channels */
 
151
        
 
152
        /* input no image? then only color operation */
 
153
        if((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) {
 
154
                out[0]->vec[0] = in[0]->vec[0];
 
155
                out[0]->vec[1] = in[1]->vec[0];
 
156
                out[0]->vec[2] = in[2]->vec[0];
 
157
                out[0]->vec[3] = in[3]->vec[0];
 
158
        }
 
159
        else {
 
160
                /* make output size of first available input image */
 
161
                CompBuf *cbuf;
 
162
                CompBuf *stackbuf;
 
163
 
 
164
                /* allocate a CompBuf the size of the first available input */
 
165
                if (in[0]->data) cbuf = in[0]->data;
 
166
                else if (in[1]->data) cbuf = in[1]->data;
 
167
                else if (in[2]->data) cbuf = in[2]->data;
 
168
                else cbuf = in[3]->data;
 
169
                
 
170
                stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
 
171
                
 
172
                composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, 
 
173
                                                                  in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, 
 
174
                                                                  do_comb_ycca, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
 
175
 
 
176
                out[0]->data= stackbuf;
 
177
        }       
 
178
}
 
179
 
 
180
bNodeType cmp_node_combycca= {
 
181
        /* *next,*prev */       NULL, NULL,
 
182
        /* type code   */       CMP_NODE_COMBYCCA,
 
183
        /* name        */       "Combine YCbCrA",
 
184
        /* width+range */       80, 40, 140,
 
185
        /* class+opts  */       NODE_CLASS_CONVERTOR, NODE_OPTIONS,
 
186
        /* input sock  */       cmp_node_combycca_in,
 
187
        /* output sock */       cmp_node_combycca_out,
 
188
        /* storage     */       "",
 
189
        /* execfunc    */       node_composit_exec_combycca,
 
190
        /* butfunc     */       NULL,
 
191
        /* initfunc    */       NULL,
 
192
        /* freestoragefunc    */        NULL,
 
193
        /* copystoragefunc    */        NULL,
 
194
        /* id          */       NULL
 
195
};
 
196
 
 
197