~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/nodes/composite/nodes/node_composite_scale.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
6
6
 * as published by the Free Software Foundation; either version 2
7
 
 * of the License, or (at your option) any later version. 
 
7
 * of the License, or (at your option) any later version.
8
8
 *
9
9
 * This program is distributed in the hope that it will be useful,
10
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34
34
 
35
35
/* **************** Scale  ******************** */
36
36
 
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},
41
 
        {       -1, 0, ""       }
42
 
};
43
 
static bNodeSocketTemplate cmp_node_scale_out[]= {
44
 
        {       SOCK_RGBA, 0, "Image"},
45
 
        {       -1, 0, ""       }
46
 
};
47
 
 
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)
51
 
{
52
 
        if (out[0]->hasoutput==0)
53
 
                return;
54
 
        
55
 
        if (in[0]->data) {
56
 
                RenderData *rd= data;
57
 
                CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
58
 
                ImBuf *ibuf;
59
 
                int newx, newy;
60
 
                
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);
64
 
                }
65
 
                else if (node->custom1==CMP_SCALE_SCENEPERCENT) {
66
 
                        newx = cbuf->x * (rd->size / 100.0f);
67
 
                        newy = cbuf->y * (rd->size / 100.0f);
68
 
                }
69
 
                else if (node->custom1==CMP_SCALE_RENDERPERCENT) {
70
 
                        newx= (rd->xsch * rd->size)/100;
71
 
                        newy= (rd->ysch * rd->size)/100;
72
 
                }
73
 
                else {  /* CMP_SCALE_ABSOLUTE */
74
 
                        newx= MAX2((int)in[1]->vec[0], 1);
75
 
                        newy= MAX2((int)in[2]->vec[0], 1);
76
 
                }
77
 
                newx= MIN2(newx, CMP_SCALE_MAX);
78
 
                newy= MIN2(newy, CMP_SCALE_MAX);
79
 
 
80
 
                ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
81
 
                if (ibuf) {
82
 
                        ibuf->rect_float= cbuf->rect;
83
 
                        IMB_scaleImBuf(ibuf, newx, newy);
84
 
                        
85
 
                        if (ibuf->rect_float == cbuf->rect) {
86
 
                                /* no scaling happened. */
87
 
                                stackbuf= pass_on_compbuf(in[0]->data);
88
 
                        }
89
 
                        else {
90
 
                                stackbuf= alloc_compbuf(newx, newy, CB_RGBA, 0);
91
 
                                stackbuf->rect= ibuf->rect_float;
92
 
                                stackbuf->malloc= 1;
93
 
                        }
94
 
 
95
 
                        ibuf->rect_float= NULL;
96
 
                        ibuf->mall &= ~IB_rectfloat;
97
 
                        IMB_freeImBuf(ibuf);
98
 
                        
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);
102
 
                }
103
 
                else {
104
 
                        stackbuf= dupalloc_compbuf(cbuf);
105
 
                        printf("Scaling to %dx%d failed\n", newx, newy);
106
 
                }
107
 
                
108
 
                out[0]->data= stackbuf;
109
 
                if (cbuf!=in[0]->data)
110
 
                        free_compbuf(cbuf);
111
 
        }
112
 
        else if (node->custom1==CMP_SCALE_ABSOLUTE) {
113
 
                CompBuf *stackbuf;
114
 
                int a, x, y;
115
 
                float *fp;
116
 
 
117
 
                x = MAX2((int)in[1]->vec[0], 1);
118
 
                y = MAX2((int)in[2]->vec[0], 1);
119
 
 
120
 
                stackbuf = alloc_compbuf(x, y, CB_RGBA, 1);
121
 
                fp = stackbuf->rect;
122
 
 
123
 
                a = stackbuf->x * stackbuf->y;
124
 
                while (a--) {
125
 
                        copy_v4_v4(fp, in[0]->vec);
126
 
                        fp += 4;
127
 
                }
128
 
 
129
 
                out[0]->data= stackbuf;
130
 
        }
131
 
}
 
37
static bNodeSocketTemplate cmp_node_scale_in[] = {
 
38
        {   SOCK_RGBA, 1, N_("Image"),          1.0f, 1.0f, 1.0f, 1.0f},
 
39
        {   SOCK_FLOAT, 1, N_("X"),             1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_FACTOR},
 
40
        {   SOCK_FLOAT, 1, N_("Y"),             1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_FACTOR},
 
41
        {   -1, 0, ""   }
 
42
};
 
43
static bNodeSocketTemplate cmp_node_scale_out[] = {
 
44
        {   SOCK_RGBA, 0, N_("Image")},
 
45
        {   -1, 0, ""   }
 
46
};
132
47
 
133
48
void register_node_type_cmp_scale(bNodeTreeType *ttype)
134
49
{
137
52
        node_type_base(ttype, &ntype, CMP_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, NODE_OPTIONS);
138
53
        node_type_socket_templates(&ntype, cmp_node_scale_in, cmp_node_scale_out);
139
54
        node_type_size(&ntype, 140, 100, 320);
140
 
        node_type_exec(&ntype, node_composit_exec_scale);
141
55
 
142
56
        nodeRegisterType(ttype, &ntype);
143
57
}