2
* $Id: CMP_rotate.c 12931 2007-12-17 18:20:48Z theeth $
4
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20
* The Original Code is Copyright (C) 2006 Blender Foundation.
21
* All rights reserved.
23
* The Original Code is: all of this file.
25
* Contributor(s): none yet.
27
* ***** END GPL LICENSE BLOCK *****
30
#include "../CMP_util.h"
32
/* **************** Rotate ******************** */
34
static bNodeSocketType cmp_node_rotate_in[]= {
35
{ SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
36
{ SOCK_VALUE, 1, "Degr", 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
39
static bNodeSocketType cmp_node_rotate_out[]= {
40
{ SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
44
/* function assumes out to be zero'ed, only does RGBA */
45
static void bilinear_interpolation_rotate(CompBuf *in, float *out, float u, float v)
47
float *row1, *row2, *row3, *row4, a, b;
48
float a_b, ma_b, a_mb, ma_mb;
49
float empty[4]= {0.0f, 0.0f, 0.0f, 0.0f};
57
/* sample area entirely outside image? */
58
if(x2<0 || x1>in->x-1 || y2<0 || y1>in->y-1)
61
/* sample including outside of edges of image */
62
if(x1<0 || y1<0) row1= empty;
63
else row1= in->rect + in->x * y1 * in->type + in->type*x1;
65
if(x1<0 || y2>in->y-1) row2= empty;
66
else row2= in->rect + in->x * y2 * in->type + in->type*x1;
68
if(x2>in->x-1 || y1<0) row3= empty;
69
else row3= in->rect + in->x * y1 * in->type + in->type*x2;
71
if(x2>in->x-1 || y2>in->y-1) row4= empty;
72
else row4= in->rect + in->x * y2 * in->type + in->type*x2;
76
a_b= a*b; ma_b= (1.0f-a)*b; a_mb= a*(1.0f-b); ma_mb= (1.0f-a)*(1.0f-b);
78
out[0]= ma_mb*row1[0] + a_mb*row3[0] + ma_b*row2[0]+ a_b*row4[0];
79
out[1]= ma_mb*row1[1] + a_mb*row3[1] + ma_b*row2[1]+ a_b*row4[1];
80
out[2]= ma_mb*row1[2] + a_mb*row3[2] + ma_b*row2[2]+ a_b*row4[2];
81
out[3]= ma_mb*row1[3] + a_mb*row3[3] + ma_b*row2[3]+ a_b*row4[3];
84
/* only supports RGBA nodes now */
85
static void node_composit_exec_rotate(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
88
if(out[0]->hasoutput==0)
92
CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
93
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* note, this returns zero'd image */
94
float *ofp, rad, u, v, s, c, centx, centy, miny, maxy, minx, maxx;
97
rad= (M_PI*in[1]->vec[0])/180.0f;
105
maxx= -centx + (float)cbuf->x;
107
maxy= -centy + (float)cbuf->y;
109
for(y=miny; y<maxy; y++) {
111
ofp= stackbuf->rect + 4*yo*stackbuf->x;
113
for(x=minx; x<maxx; x++, ofp+=4) {
114
u= c*x + y*s + centx;
115
v= -s*x + c*y + centy;
117
bilinear_interpolation_rotate(cbuf, ofp, u, v);
120
/* rotate offset vector too, but why negative rad, ehh?? Has to be replaced with [3][3] matrix once (ton) */
123
centx= (float)cbuf->xof; centy= (float)cbuf->yof;
124
stackbuf->xof= (int)( c*centx + s*centy);
125
stackbuf->yof= (int)(-s*centx + c*centy);
127
/* pass on output and free */
128
out[0]->data= stackbuf;
129
if(cbuf!=in[0]->data)
135
bNodeType cmp_node_rotate= {
136
/* *next,*prev */ NULL, NULL,
137
/* type code */ CMP_NODE_ROTATE,
139
/* width+range */ 140, 100, 320,
140
/* class+opts */ NODE_CLASS_DISTORT, NODE_OPTIONS,
141
/* input sock */ cmp_node_rotate_in,
142
/* output sock */ cmp_node_rotate_out,
144
/* execfunc */ node_composit_exec_rotate,
147
/* freestoragefunc */ NULL,
148
/* copystoragefunc */ NULL,