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