2
* $Id: CMP_sepcombYCCA.c,v 1.5 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
/* **************** 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},
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},
46
static void do_sepycca(bNode *node, float *out, float *in)
50
rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr);
52
/*divided by 255 to normalize for viewing in */
59
static void node_composit_exec_sepycca(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
61
/* input no image? then only color operation */
62
if(in[0]->data==NULL) {
65
rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr);
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];
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);
78
/* convert the RGB stackbuf to an HSV representation */
79
composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca, CB_RGBA);
81
/* separate each of those channels */
83
out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R);
85
out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G);
87
out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B);
89
out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A);
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,
107
/* execfunc */ node_composit_exec_sepycca,
110
/* freestoragefunc */ NULL,
111
/* copystoragefunc */ NULL,
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},
124
static bNodeSocketType cmp_node_combycca_out[]= {
125
{ SOCK_RGBA, 0, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
129
static void do_comb_ycca(bNode *node, float *out, float *in1, float *in2, float *in3, float *in4)
134
/*need to un-normalize the data*/
139
ycc_to_rgb(y,cb,cr, &r, &g, &b);
147
static void node_composit_exec_combycca(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
149
/* stack order out: 1 ycca channels */
150
/* stack order in: 4 value channels */
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];
160
/* make output size of first available input image */
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;
170
stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
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);
176
out[0]->data= stackbuf;
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,
189
/* execfunc */ node_composit_exec_combycca,
192
/* freestoragefunc */ NULL,
193
/* copystoragefunc */ NULL,