2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2006 Blender Foundation.
19
* All rights reserved.
21
* The Original Code is: all of this file.
23
* Contributor(s): none yet.
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file blender/nodes/composite/nodes/node_composite_scale.c
33
#include "node_composite_util.h"
35
/* **************** Scale ******************** */
37
static bNodeSocketTemplate cmp_node_scale_in[]= {
38
{ SOCK_RGBA, 1, "Image", 1.0f, 1.0f, 1.0f, 1.0f},
39
{ SOCK_FLOAT, 1, "X", 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_FACTOR},
40
{ SOCK_FLOAT, 1, "Y", 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_FACTOR},
43
static bNodeSocketTemplate cmp_node_scale_out[]= {
44
{ SOCK_RGBA, 0, "Image"},
48
/* only supports RGBA nodes now */
49
/* node->custom1 stores if input values are absolute or relative scale */
50
static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
52
if (out[0]->hasoutput==0)
57
CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
61
if (node->custom1==CMP_SCALE_RELATIVE) {
62
newx= MAX2((int)(in[1]->vec[0]*cbuf->x), 1);
63
newy= MAX2((int)(in[2]->vec[0]*cbuf->y), 1);
65
else if (node->custom1==CMP_SCALE_SCENEPERCENT) {
66
newx = cbuf->x * (rd->size / 100.0f);
67
newy = cbuf->y * (rd->size / 100.0f);
69
else if (node->custom1==CMP_SCALE_RENDERPERCENT) {
70
newx= (rd->xsch * rd->size)/100;
71
newy= (rd->ysch * rd->size)/100;
73
else { /* CMP_SCALE_ABSOLUTE */
74
newx= MAX2((int)in[1]->vec[0], 1);
75
newy= MAX2((int)in[2]->vec[0], 1);
77
newx= MIN2(newx, CMP_SCALE_MAX);
78
newy= MIN2(newy, CMP_SCALE_MAX);
80
ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
82
ibuf->rect_float= cbuf->rect;
83
IMB_scaleImBuf(ibuf, newx, newy);
85
if (ibuf->rect_float == cbuf->rect) {
86
/* no scaling happened. */
87
stackbuf= pass_on_compbuf(in[0]->data);
90
stackbuf= alloc_compbuf(newx, newy, CB_RGBA, 0);
91
stackbuf->rect= ibuf->rect_float;
95
ibuf->rect_float= NULL;
96
ibuf->mall &= ~IB_rectfloat;
99
/* also do the translation vector */
100
stackbuf->xof = (int)(((float)newx/(float)cbuf->x) * (float)cbuf->xof);
101
stackbuf->yof = (int)(((float)newy/(float)cbuf->y) * (float)cbuf->yof);
104
stackbuf= dupalloc_compbuf(cbuf);
105
printf("Scaling to %dx%d failed\n", newx, newy);
108
out[0]->data= stackbuf;
109
if (cbuf!=in[0]->data)
112
else if (node->custom1==CMP_SCALE_ABSOLUTE) {
117
x = MAX2((int)in[1]->vec[0], 1);
118
y = MAX2((int)in[2]->vec[0], 1);
120
stackbuf = alloc_compbuf(x, y, CB_RGBA, 1);
123
a = stackbuf->x * stackbuf->y;
125
copy_v4_v4(fp, in[0]->vec);
129
out[0]->data= stackbuf;
133
void register_node_type_cmp_scale(bNodeTreeType *ttype)
135
static bNodeType ntype;
137
node_type_base(ttype, &ntype, CMP_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, NODE_OPTIONS);
138
node_type_socket_templates(&ntype, cmp_node_scale_in, cmp_node_scale_out);
139
node_type_size(&ntype, 140, 100, 320);
140
node_type_exec(&ntype, node_composit_exec_scale);
142
nodeRegisterType(ttype, &ntype);