Blender  V2.59
CMP_sepcombYUVA.c
Go to the documentation of this file.
00001 /*
00002  * $Id: CMP_sepcombYUVA.c 35237 2011-02-27 20:13:22Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2006 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #include "../CMP_util.h"
00036 
00037 
00038 /* **************** SEPARATE YUVA ******************** */
00039 static bNodeSocketType cmp_node_sepyuva_in[]= {
00040         {  SOCK_RGBA, 1, "Image",        0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
00041         {  -1, 0, ""   }
00042 };
00043 static bNodeSocketType cmp_node_sepyuva_out[]= {
00044         {  SOCK_VALUE, 0, "Y",        0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00045         {  SOCK_VALUE, 0, "U",        0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00046         {  SOCK_VALUE, 0, "V",        0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00047         {  SOCK_VALUE, 0, "A",        0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00048         {  -1, 0, ""   }
00049 };
00050 
00051 static void do_sepyuva(bNode *UNUSED(node), float *out, float *in)
00052 {
00053         float y, u, v;
00054         
00055         rgb_to_yuv(in[0], in[1], in[2], &y, &u, &v);
00056         
00057         out[0]= y;
00058         out[1]= u;
00059         out[2]= v;
00060         out[3]= in[3];
00061 }
00062 
00063 static void node_composit_exec_sepyuva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00064 {
00065         /* stack order out: bw channels */
00066         /* stack order in: col */
00067         
00068         /* input no image? then only color operation */
00069         if(in[0]->data==NULL) {
00070                 float y, u, v;
00071         
00072                 rgb_to_yuv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &u, &v);
00073         
00074                 out[0]->vec[0] = y;
00075                 out[1]->vec[0] = u;
00076                 out[2]->vec[0] = v;
00077                 out[3]->vec[0] = in[0]->vec[3];
00078         }
00079         else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) {
00080                 /* make copy of buffer so input image doesn't get corrupted */
00081                 CompBuf *cbuf= dupalloc_compbuf(in[0]->data);
00082                 CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA);
00083         
00084                 /* convert the RGB stackbuf to an YUV representation */
00085                 composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepyuva, CB_RGBA);
00086         
00087                 /* separate each of those channels */
00088                 if(out[0]->hasoutput)
00089                         out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R);
00090                 if(out[1]->hasoutput)
00091                         out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G);
00092                 if(out[2]->hasoutput)
00093                         out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B);
00094                 if(out[3]->hasoutput)
00095                         out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A);
00096 
00097                 /*not used anymore */
00098                 if(cbuf2!=cbuf)
00099                         free_compbuf(cbuf2);
00100                 free_compbuf(cbuf);
00101         }
00102 }
00103 
00104 void register_node_type_cmp_sepyuva(ListBase *lb)
00105 {
00106         static bNodeType ntype;
00107 
00108         node_type_base(&ntype, CMP_NODE_SEPYUVA, "Separate YUVA", NODE_CLASS_CONVERTOR, 0,
00109                 cmp_node_sepyuva_in, cmp_node_sepyuva_out);
00110         node_type_size(&ntype, 80, 40, 140);
00111         node_type_exec(&ntype, node_composit_exec_sepyuva);
00112 
00113         nodeRegisterType(lb, &ntype);
00114 }
00115 
00116 
00117 
00118 /* **************** COMBINE YUVA ******************** */
00119 static bNodeSocketType cmp_node_combyuva_in[]= {
00120         {       SOCK_VALUE, 1, "Y",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00121         {       SOCK_VALUE, 1, "U",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00122         {       SOCK_VALUE, 1, "V",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00123         {       SOCK_VALUE, 1, "A",                     1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00124         {       -1, 0, ""       }
00125 };
00126 static bNodeSocketType cmp_node_combyuva_out[]= {
00127         {       SOCK_RGBA, 0, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
00128         {       -1, 0, ""       }
00129 };
00130 
00131 static void do_comb_yuva(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
00132 {
00133         float r,g,b;
00134         yuv_to_rgb(in1[0], in2[0], in3[0], &r, &g, &b);
00135         
00136         out[0] = r;
00137         out[1] = g;
00138         out[2] = b;
00139         out[3] = in4[0];
00140 }
00141 
00142 static void node_composit_exec_combyuva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00143 {
00144         /* stack order out: 1 rgba channels */
00145         /* stack order in: 4 value channels */
00146         
00147         /* input no image? then only color operation */
00148         if((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) {
00149                 out[0]->vec[0] = in[0]->vec[0];
00150                 out[0]->vec[1] = in[1]->vec[0];
00151                 out[0]->vec[2] = in[2]->vec[0];
00152                 out[0]->vec[3] = in[3]->vec[0];
00153         }
00154         else {
00155                 /* make output size of first available input image */
00156                 CompBuf *cbuf;
00157                 CompBuf *stackbuf;
00158 
00159                 /* allocate a CompBuf the size of the first available input */
00160                 if (in[0]->data) cbuf = in[0]->data;
00161                 else if (in[1]->data) cbuf = in[1]->data;
00162                 else if (in[2]->data) cbuf = in[2]->data;
00163                 else cbuf = in[3]->data;
00164                 
00165                 stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
00166                 
00167                 composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, 
00168                                                                   in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, 
00169                                                                   do_comb_yuva, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
00170 
00171                 out[0]->data= stackbuf;
00172         }       
00173 }
00174 
00175 void register_node_type_cmp_combyuva(ListBase *lb)
00176 {
00177         static bNodeType ntype;
00178 
00179         node_type_base(&ntype, CMP_NODE_COMBYUVA, "Combine YUVA", NODE_CLASS_CONVERTOR, NODE_OPTIONS,
00180                 cmp_node_combyuva_in, cmp_node_combyuva_out);
00181         node_type_size(&ntype, 80, 40, 140);
00182         node_type_exec(&ntype, node_composit_exec_combyuva);
00183 
00184         nodeRegisterType(lb, &ntype);
00185 }
00186 
00187