doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / nodes / intern / CMP_nodes / CMP_scale.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 /* **************** Scale  ******************** */
33
34 #define CMP_SCALE_MAX   12000
35
36 static bNodeSocketType cmp_node_scale_in[]= {
37         {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
38         {       SOCK_VALUE, 1, "X",                             1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX},
39         {       SOCK_VALUE, 1, "Y",                             1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX},
40         {       -1, 0, ""       }
41 };
42 static bNodeSocketType cmp_node_scale_out[]= {
43         {       SOCK_RGBA, 0, "Image",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
44         {       -1, 0, ""       }
45 };
46
47 /* only supports RGBA nodes now */
48 /* node->custom1 stores if input values are absolute or relative scale */
49 static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
50 {
51         if(out[0]->hasoutput==0)
52                 return;
53         
54         if(in[0]->data) {
55                 RenderData *rd= data;
56                 CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
57                 ImBuf *ibuf;
58                 int newx, newy;
59                 
60                 if(node->custom1==CMP_SCALE_RELATIVE) {
61                         newx= MAX2((int)(in[1]->vec[0]*cbuf->x), 1);
62                         newy= MAX2((int)(in[2]->vec[0]*cbuf->y), 1);
63                 }
64                 else if(node->custom1==CMP_SCALE_SCENEPERCENT) {
65                         newx = cbuf->x * (rd->size / 100.0f);
66                         newy = cbuf->y * (rd->size / 100.0f);
67                 }
68                 else if (node->custom1==CMP_SCALE_RENDERPERCENT) {
69                         newx= (rd->xsch * rd->size)/100;
70                         newy= (rd->ysch * rd->size)/100;
71                 } else {        /* CMP_SCALE_ABSOLUTE */
72                         newx= MAX2((int)in[1]->vec[0], 1);
73                         newy= MAX2((int)in[2]->vec[0], 1);
74                 }
75                 newx= MIN2(newx, CMP_SCALE_MAX);
76                 newy= MIN2(newy, CMP_SCALE_MAX);
77
78                 ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
79                 if(ibuf) {
80                         ibuf->rect_float= cbuf->rect;
81                         IMB_scaleImBuf(ibuf, newx, newy);
82                         
83                         if(ibuf->rect_float == cbuf->rect) {
84                                 /* no scaling happened. */
85                                 stackbuf= pass_on_compbuf(in[0]->data);
86                         }
87                         else {
88                                 stackbuf= alloc_compbuf(newx, newy, CB_RGBA, 0);
89                                 stackbuf->rect= ibuf->rect_float;
90                                 stackbuf->malloc= 1;
91                         }
92
93                         ibuf->rect_float= NULL;
94                         ibuf->mall &= ~IB_rectfloat;
95                         IMB_freeImBuf(ibuf);
96                         
97                         /* also do the translation vector */
98                         stackbuf->xof = (int)(((float)newx/(float)cbuf->x) * (float)cbuf->xof);
99                         stackbuf->yof = (int)(((float)newy/(float)cbuf->y) * (float)cbuf->yof);
100                 }
101                 else {
102                         stackbuf= dupalloc_compbuf(cbuf);
103                         printf("Scaling to %dx%d failed\n", newx, newy);
104                 }
105                 
106                 out[0]->data= stackbuf;
107                 if(cbuf!=in[0]->data)
108                         free_compbuf(cbuf);
109         }
110 };
111
112 void register_node_type_cmp_scale(ListBase *lb)
113 {
114         static bNodeType ntype;
115
116         node_type_base(&ntype, CMP_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, NODE_OPTIONS,
117                 cmp_node_scale_in, cmp_node_scale_out);
118         node_type_size(&ntype, 140, 100, 320);
119         node_type_exec(&ntype, node_composit_exec_scale);
120
121         nodeRegisterType(lb, &ntype);
122 }
123
124
125
126
127
128
129