Initial commit. Not in build system so shouldn't interfere with anything at this...
[blender-staging.git] / source / blender / nodes / intern / CMP_nodes / CMP_flip.c
1 /**
2  * $Id$
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 /* **************** Flip  ******************** */
33 static bNodeSocketType cmp_node_flip_in[]= {
34         {       SOCK_RGBA, 1, "Image",              0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
35         {       -1, 0, ""       }
36 };
37
38 static bNodeSocketType cmp_node_flip_out[]= {
39         {       SOCK_RGBA, 0, "Image",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
40         {       -1, 0, ""       }
41 };
42
43 static void node_composit_exec_flip(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
44 {
45         if(in[0]->data) {
46                 CompBuf *cbuf= in[0]->data;
47                 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1);      /* note, this returns zero'd image */
48                 int i, src_pix, src_width, src_height, srcydelt, outydelt, x, y;
49                 float *srcfp, *outfp;
50                 
51                 src_pix= cbuf->type;
52                 src_width= cbuf->x;
53                 src_height= cbuf->y;
54                 srcfp= cbuf->rect;
55                 outfp= stackbuf->rect;
56                 srcydelt= src_width*src_pix;
57                 outydelt= srcydelt;
58                 
59                 if(node->custom1) {             /*set up output pointer for y flip*/
60                         outfp+= (src_height-1)*outydelt;
61                         outydelt= -outydelt;
62                 }
63
64                 for(y=0; y<src_height; y++) {
65                         if(node->custom1 == 1) {        /* no x flip so just copy line*/
66                                 memcpy(outfp, srcfp, sizeof(float) * src_pix * src_width);
67                                 srcfp+=srcydelt;
68                         }
69                         else {
70                                 outfp += (src_width-1)*src_pix;
71                                 for(x=0; x<src_width; x++) {
72                                         for(i=0; i<src_pix; i++) {
73                                                 outfp[i]= srcfp[i];
74                                         }
75                                         outfp -= src_pix;
76                                         srcfp += src_pix;
77                                 }
78                                 outfp += src_pix;
79                         }
80                         outfp += outydelt;
81                 }
82
83                 out[0]->data= stackbuf;
84
85         }
86 }
87
88 static int node_composit_buts_flip(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr) 
89 {
90    if(block) {
91       uiBut *bt;
92
93       /* flip x\y */
94       bt=uiDefButS(block, MENU, B_NODE_EXEC+node->nr, "Flip X %x0|Flip Y %x1|Flip X & Y %x2",
95          butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, 
96          &node->custom1, 0, 0, 0, 0, "");
97       uiButSetFunc(bt, node_but_title_cb, node, bt);
98    }
99    return 20;   
100 }
101
102 bNodeType cmp_node_flip= {
103         /* type code   */       CMP_NODE_FLIP,
104         /* name        */       "Flip",
105         /* width+range */       140, 100, 320,
106         /* class+opts  */       NODE_CLASS_DISTORT, NODE_OPTIONS,
107         /* input sock  */       cmp_node_flip_in,
108         /* output sock */       cmp_node_flip_out,
109         /* storage     */       "",
110         /* execfunc    */       node_composit_exec_flip,
111    /* butfunc     */ node_composit_buts_flip
112 };