Blender  V2.59
CMP_sepcombYCCA.c
Go to the documentation of this file.
00001 /*
00002  * $Id: CMP_sepcombYCCA.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 YCCA ******************** */
00039 static bNodeSocketType cmp_node_sepycca_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_sepycca_out[]= {
00044         {  SOCK_VALUE, 0, "Y",        0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00045         {  SOCK_VALUE, 0, "Cb",       0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00046         {  SOCK_VALUE, 0, "Cr",       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_sepycca_601(bNode *UNUSED(node), float *out, float *in)
00052 {
00053         float y, cb, cr;
00054         
00055         rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_ITU_BT601);
00056         
00057         /*divided by 255 to normalize for viewing in */
00058         out[0]= y/255.0;
00059         out[1]= cb/255.0;
00060         out[2]= cr/255.0;
00061         out[3]= in[3];
00062 }
00063 
00064 static void do_sepycca_709(bNode *UNUSED(node), float *out, float *in)
00065 {
00066         float y, cb, cr;
00067         
00068         rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_ITU_BT709);
00069         
00070         /*divided by 255 to normalize for viewing in */
00071         out[0]= y/255.0;
00072         out[1]= cb/255.0;
00073         out[2]= cr/255.0;
00074         out[3]= in[3];
00075 }
00076 
00077 static void do_sepycca_jfif(bNode *UNUSED(node), float *out, float *in)
00078 {
00079         float y, cb, cr;
00080         
00081         rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_JFIF_0_255);
00082         
00083         /*divided by 255 to normalize for viewing in */
00084         out[0]= y/255.0;
00085         out[1]= cb/255.0;
00086         out[2]= cr/255.0;
00087         out[3]= in[3];
00088 }
00089 
00090 static void node_composit_exec_sepycca(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00091 {
00092         /* input no image? then only color operation */
00093         if(in[0]->data==NULL) {
00094                 float y, cb, cr;
00095         
00096                 switch(node->custom1)
00097                 {
00098                 case 1:
00099                         rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_ITU_BT709);
00100                         break;
00101                 case 2:
00102                         rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_JFIF_0_255);
00103                         break;
00104                 case 0:
00105                 default:
00106                         rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_ITU_BT601);
00107                         break;
00108                 }
00109         
00110                 /*divided by 255 to normalize for viewing in */
00111                 out[0]->vec[0] = y/255.0;
00112                 out[1]->vec[0] = cb/255.0;
00113                 out[2]->vec[0] = cr/255.0;
00114                 out[3]->vec[0] = in[0]->vec[3];
00115         }
00116         else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) {
00117                 /* make copy of buffer so input buffer doesn't get corrupted */
00118                 CompBuf *cbuf= dupalloc_compbuf(in[0]->data);
00119                 CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA);
00120         
00121                 /* convert the RGB stackbuf to an HSV representation */
00122                 switch(node->custom1)
00123                 {
00124                 case 1:
00125                         composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_709, CB_RGBA);
00126                         break;
00127                 case 2:
00128                         composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_jfif, CB_RGBA);
00129                         break;
00130                 case 0:
00131                 default:
00132                         composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_601, CB_RGBA);
00133                         break;
00134                 }
00135         
00136                 /* separate each of those channels */
00137                 if(out[0]->hasoutput)
00138                         out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R);
00139                 if(out[1]->hasoutput)
00140                         out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G);
00141                 if(out[2]->hasoutput)
00142                         out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B);
00143                 if(out[3]->hasoutput)
00144                         out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A);
00145 
00146                 /*not used anymore */
00147                 if(cbuf2!=cbuf)
00148                         free_compbuf(cbuf2);
00149                 free_compbuf(cbuf);
00150         }
00151 }
00152 
00153 void register_node_type_cmp_sepycca(ListBase *lb)
00154 {
00155         static bNodeType ntype;
00156 
00157         node_type_base(&ntype, CMP_NODE_SEPYCCA, "Separate YCbCrA", NODE_CLASS_CONVERTOR, NODE_OPTIONS,
00158                 cmp_node_sepycca_in, cmp_node_sepycca_out);
00159         node_type_size(&ntype, 80, 40, 140);
00160         node_type_exec(&ntype, node_composit_exec_sepycca);
00161 
00162         nodeRegisterType(lb, &ntype);
00163 }
00164 
00165 
00166 
00167 /* **************** COMBINE YCCA ******************** */
00168 static bNodeSocketType cmp_node_combycca_in[]= {
00169         {       SOCK_VALUE, 1, "Y",                     0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00170         {       SOCK_VALUE, 1, "Cb",                    0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00171         {       SOCK_VALUE, 1, "Cr",                    0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00172         {       SOCK_VALUE, 1, "A",                     1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00173         {       -1, 0, ""       }
00174 };
00175 static bNodeSocketType cmp_node_combycca_out[]= {
00176         {       SOCK_RGBA, 0, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
00177         {       -1, 0, ""       }
00178 };
00179 
00180 static void do_comb_ycca_601(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
00181 {
00182         float r,g,b;
00183         float y, cb, cr;
00184 
00185         /*need to un-normalize the data*/
00186         y=in1[0]*255;
00187         cb=in2[0]*255;
00188         cr=in3[0]*255;
00189 
00190         ycc_to_rgb(y,cb,cr, &r, &g, &b, BLI_YCC_ITU_BT601);
00191         
00192         out[0] = r;
00193         out[1] = g;
00194         out[2] = b;
00195         out[3] = in4[0];
00196 }
00197 
00198 static void do_comb_ycca_709(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
00199 {
00200         float r,g,b;
00201         float y, cb, cr;
00202 
00203         /*need to un-normalize the data*/
00204         y=in1[0]*255;
00205         cb=in2[0]*255;
00206         cr=in3[0]*255;
00207 
00208         ycc_to_rgb(y,cb,cr, &r, &g, &b, BLI_YCC_ITU_BT709);
00209         
00210         out[0] = r;
00211         out[1] = g;
00212         out[2] = b;
00213         out[3] = in4[0];
00214 }
00215 
00216 static void do_comb_ycca_jfif(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
00217 {
00218         float r,g,b;
00219         float y, cb, cr;
00220 
00221         /*need to un-normalize the data*/
00222         y=in1[0]*255;
00223         cb=in2[0]*255;
00224         cr=in3[0]*255;
00225 
00226         ycc_to_rgb(y,cb,cr, &r, &g, &b, BLI_YCC_JFIF_0_255);
00227         
00228         out[0] = r;
00229         out[1] = g;
00230         out[2] = b;
00231         out[3] = in4[0];
00232 }
00233 
00234 static void node_composit_exec_combycca(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00235 {
00236         /* stack order out: 1 ycca channels */
00237         /* stack order in: 4 value channels */
00238         
00239         /* input no image? then only color operation */
00240         if((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) {
00241                 float y = in[0]->vec[0] * 255;
00242                 float cb = in[1]->vec[0] * 255;
00243                 float cr = in[2]->vec[0] * 255;
00244                 
00245                 switch(node->custom1)
00246                 {
00247                 case 1:
00248                         ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_ITU_BT709);
00249                         break;
00250                 case 2:
00251                         ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_JFIF_0_255);
00252                         break;
00253                 case 0:
00254                 default:
00255                         ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_ITU_BT601);
00256                         break;
00257                 }
00258                 
00259                 out[0]->vec[3] = in[3]->vec[0];
00260         }
00261         else {
00262                 /* make output size of first available input image */
00263                 CompBuf *cbuf;
00264                 CompBuf *stackbuf;
00265 
00266                 /* allocate a CompBuf the size of the first available input */
00267                 if (in[0]->data) cbuf = in[0]->data;
00268                 else if (in[1]->data) cbuf = in[1]->data;
00269                 else if (in[2]->data) cbuf = in[2]->data;
00270                 else cbuf = in[3]->data;
00271                 
00272                 stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
00273                 
00274                 
00275                 switch(node->custom1)
00276                 {
00277                 case 1:
00278                         composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, 
00279                                                   in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, 
00280                                                   do_comb_ycca_709, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
00281                         break;
00282                 
00283                 case 2:
00284                         composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, 
00285                                                   in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, 
00286                                                   do_comb_ycca_jfif, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
00287                         break;
00288                 case 0:
00289                 default:
00290                         composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, 
00291                                                   in[2]->data, in[2]->vec, in[3]->data, in[3]->vec, 
00292                                                   do_comb_ycca_601, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
00293                         break;
00294                 }
00295 
00296                 out[0]->data= stackbuf;
00297         }       
00298 }
00299 
00300 void register_node_type_cmp_combycca(ListBase *lb)
00301 {
00302         static bNodeType ntype;
00303 
00304         node_type_base(&ntype, CMP_NODE_COMBYCCA, "Combine YCbCrA", NODE_CLASS_CONVERTOR, NODE_OPTIONS,
00305                 cmp_node_combycca_in, cmp_node_combycca_out);
00306         node_type_size(&ntype, 80, 40, 140);
00307         node_type_exec(&ntype, node_composit_exec_combycca);
00308 
00309         nodeRegisterType(lb, &ntype);
00310 }
00311 
00312 
00313