Blender V2.61 - r43446

node_composite_rotate.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 /* **************** Rotate  ******************** */
00036 
00037 static bNodeSocketTemplate cmp_node_rotate_in[]= {
00038     {   SOCK_RGBA, 1, "Image",          1.0f, 1.0f, 1.0f, 1.0f},
00039     {   SOCK_FLOAT, 1, "Degr",          0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_ANGLE},
00040     {   -1, 0, ""   }
00041 };
00042 static bNodeSocketTemplate cmp_node_rotate_out[]= {
00043     {   SOCK_RGBA, 0, "Image"},
00044     {   -1, 0, ""   }
00045 };
00046 
00047 /* only supports RGBA nodes now */
00048 static void node_composit_exec_rotate(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00049 {
00050 
00051     if(out[0]->hasoutput==0)
00052         return;
00053 
00054     if(in[0]->data) {
00055         CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
00056         CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* note, this returns zero'd image */
00057         float rad, u, v, s, c, centx, centy, miny, maxy, minx, maxx;
00058         int x, y, yo, xo;
00059         ImBuf *ibuf, *obuf;
00060 
00061         rad= in[1]->vec[0];
00062 
00063 
00064         s= sin(rad);
00065         c= cos(rad);
00066         centx= cbuf->x/2;
00067         centy= cbuf->y/2;
00068 
00069         minx= -centx;
00070         maxx= -centx + (float)cbuf->x;
00071         miny= -centy;
00072         maxy= -centy + (float)cbuf->y;
00073 
00074 
00075         ibuf=IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
00076         obuf=IMB_allocImBuf(stackbuf->x, stackbuf->y, 32, 0);
00077 
00078         if(ibuf && obuf){
00079             ibuf->rect_float=cbuf->rect;
00080             obuf->rect_float=stackbuf->rect;
00081 
00082             for(y=miny; y<maxy; y++) {
00083                 yo= y+(int)centy;
00084 
00085                 for(x=minx; x<maxx;x++) {
00086                     u=c*x + y*s + centx;
00087                     v=-s*x + c*y + centy;
00088                     xo= x+(int)centx;
00089 
00090                     switch(node->custom1) {
00091                     case 0:
00092                         neareast_interpolation(ibuf, obuf, u, v, xo, yo);
00093                         break ;
00094                     case 1:
00095                         bilinear_interpolation(ibuf, obuf, u, v, xo, yo);
00096                         break;
00097                     case 2:
00098                         bicubic_interpolation(ibuf, obuf, u, v, xo, yo);
00099                         break;
00100                     }
00101 
00102                 }
00103             }
00104 
00105             /* rotate offset vector too, but why negative rad, ehh?? Has to be replaced with [3][3] matrix once (ton) */
00106             s= sin(-rad);
00107             c= cos(-rad);
00108             centx= (float)cbuf->xof; centy= (float)cbuf->yof;
00109             stackbuf->xof= (int)( c*centx + s*centy);
00110             stackbuf->yof= (int)(-s*centx + c*centy);
00111 
00112             IMB_freeImBuf(ibuf);
00113             IMB_freeImBuf(obuf);
00114         }
00115 
00116         /* pass on output and free */
00117         out[0]->data= stackbuf;
00118         if(cbuf!=in[0]->data) {
00119             free_compbuf(cbuf);
00120         }
00121     }
00122 }
00123 
00124 static void node_composit_init_rotate(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
00125 {
00126     node->custom1= 1; /* Bilinear Filter*/
00127 }
00128 
00129 void register_node_type_cmp_rotate(bNodeTreeType *ttype)
00130 {
00131     static bNodeType ntype;
00132 
00133     node_type_base(ttype, &ntype, CMP_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, NODE_OPTIONS);
00134     node_type_socket_templates(&ntype, cmp_node_rotate_in, cmp_node_rotate_out);
00135     node_type_size(&ntype, 140, 100, 320);
00136     node_type_init(&ntype, node_composit_init_rotate);
00137     node_type_exec(&ntype, node_composit_exec_rotate);
00138 
00139     nodeRegisterType(ttype, &ntype);
00140 }