Blender V2.61 - r43446

node_composite_flip.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2006 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "node_composite_util.h"
00034 
00035 /* **************** Flip  ******************** */
00036 static bNodeSocketTemplate cmp_node_flip_in[]= {
00037     {   SOCK_RGBA, 1, "Image",          1.0f, 1.0f, 1.0f, 1.0f},
00038     {   -1, 0, ""   }
00039 };
00040 
00041 static bNodeSocketTemplate cmp_node_flip_out[]= {
00042     {   SOCK_RGBA, 0, "Image"},
00043     {   -1, 0, ""   }
00044 };
00045 
00046 static void node_composit_exec_flip(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00047 {
00048     if(in[0]->data) {
00049         CompBuf *cbuf= in[0]->data;
00050         CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1);  /* note, this returns zero'd image */
00051         int i, src_pix, src_width, src_height, srcydelt, outydelt, x, y;
00052         float *srcfp, *outfp;
00053         
00054         src_pix= cbuf->type;
00055         src_width= cbuf->x;
00056         src_height= cbuf->y;
00057         srcfp= cbuf->rect;
00058         outfp= stackbuf->rect;
00059         srcydelt= src_width*src_pix;
00060         outydelt= srcydelt;
00061         
00062         if(node->custom1) {     /*set up output pointer for y flip*/
00063             outfp+= (src_height-1)*outydelt;
00064             outydelt= -outydelt;
00065         }
00066 
00067         for(y=0; y<src_height; y++) {
00068             if(node->custom1 == 1) {    /* no x flip so just copy line*/
00069                 memcpy(outfp, srcfp, sizeof(float) * src_pix * src_width);
00070                 srcfp+=srcydelt;
00071             }
00072             else {
00073                 outfp += (src_width-1)*src_pix;
00074                 for(x=0; x<src_width; x++) {
00075                     for(i=0; i<src_pix; i++) {
00076                         outfp[i]= srcfp[i];
00077                     }
00078                     outfp -= src_pix;
00079                     srcfp += src_pix;
00080                 }
00081                 outfp += src_pix;
00082             }
00083             outfp += outydelt;
00084         }
00085 
00086         out[0]->data= stackbuf;
00087 
00088     }
00089 }
00090 
00091 void register_node_type_cmp_flip(bNodeTreeType *ttype)
00092 {
00093     static bNodeType ntype;
00094 
00095     node_type_base(ttype, &ntype, CMP_NODE_FLIP, "Flip", NODE_CLASS_DISTORT, NODE_OPTIONS);
00096     node_type_socket_templates(&ntype, cmp_node_flip_in, cmp_node_flip_out);
00097     node_type_size(&ntype, 140, 100, 320);
00098     node_type_exec(&ntype, node_composit_exec_flip);
00099 
00100     nodeRegisterType(ttype, &ntype);
00101 }