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

« back to all changes in this revision

Viewing changes to source/blender/nodes/composite/nodes/node_composite_splitViewer.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:
33
33
#include "node_composite_util.h"
34
34
 
35
35
/* **************** SPLIT VIEWER ******************** */
36
 
static bNodeSocketTemplate cmp_node_splitviewer_in[]= {
37
 
        {       SOCK_RGBA, 1, "Image",          0.0f, 0.0f, 0.0f, 1.0f},
38
 
        {       SOCK_RGBA, 1, "Image",          0.0f, 0.0f, 0.0f, 1.0f},
 
36
static bNodeSocketTemplate cmp_node_splitviewer_in[] = {
 
37
        {       SOCK_RGBA, 1, N_("Image"),              0.0f, 0.0f, 0.0f, 1.0f},
 
38
        {       SOCK_RGBA, 1, N_("Image"),              0.0f, 0.0f, 0.0f, 1.0f},
39
39
        {       -1, 0, ""       }
40
40
};
41
41
 
42
 
static void do_copy_split_rgba(bNode *UNUSED(node), float *out, float *in1, float *in2, float *fac)
43
 
{
44
 
        if (*fac==0.0f) {
45
 
                copy_v4_v4(out, in1);
46
 
        }
47
 
        else {
48
 
                copy_v4_v4(out, in2);
49
 
        }
50
 
}
51
 
 
52
 
static void node_composit_exec_splitviewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
53
 
{
54
 
        /* image assigned to output */
55
 
        /* stack order input sockets: image image */
56
 
        
57
 
        if (in[0]->data==NULL || in[1]->data==NULL)
58
 
                return;
59
 
        
60
 
        if (node->id && (node->flag & NODE_DO_OUTPUT)) {        /* only one works on out */
61
 
                Image *ima= (Image *)node->id;
62
 
                RenderData *rd= data;
63
 
                ImBuf *ibuf;
64
 
                CompBuf *cbuf, *buf1, *buf2, *mask;
65
 
                int x, y;
66
 
                float offset;
67
 
                void *lock;
68
 
                
69
 
                buf1= typecheck_compbuf(in[0]->data, CB_RGBA);
70
 
                buf2= typecheck_compbuf(in[1]->data, CB_RGBA);
71
 
                
72
 
                BKE_image_user_calc_frame(node->storage, rd->cfra, 0);
73
 
                
74
 
                /* always returns for viewer image, but we check nevertheless */
75
 
                ibuf= BKE_image_acquire_ibuf(ima, node->storage, &lock);
76
 
                if (ibuf==NULL) {
77
 
                        printf("node_composit_exec_viewer error\n");
78
 
                        BKE_image_release_ibuf(ima, lock);
79
 
                        return;
80
 
                }
81
 
                
82
 
                /* free all in ibuf */
83
 
                imb_freerectImBuf(ibuf);
84
 
                imb_freerectfloatImBuf(ibuf);
85
 
                IMB_freezbuffloatImBuf(ibuf);
86
 
                
87
 
                /* make ibuf, and connect to ima */
88
 
                ibuf->x= buf1->x;
89
 
                ibuf->y= buf1->y;
90
 
                imb_addrectfloatImBuf(ibuf);
91
 
                
92
 
                ima->ok= IMA_OK_LOADED;
93
 
 
94
 
                /* output buf */
95
 
                cbuf= alloc_compbuf(buf1->x, buf1->y, CB_RGBA, 0);      /* no alloc*/
96
 
                cbuf->rect= ibuf->rect_float;
97
 
                
98
 
                /* mask buf */
99
 
                mask= alloc_compbuf(buf1->x, buf1->y, CB_VAL, 1);
100
 
                
101
 
                
102
 
                /* Check which offset mode is selected and limit offset if needed */
103
 
                if (node->custom2 == 0) {
104
 
                        offset = buf1->x / 100.0f * node->custom1;
105
 
                        CLAMP(offset, 0, buf1->x);
106
 
                }
107
 
                else {
108
 
                        offset = buf1->y / 100.0f * node->custom1;
109
 
                        CLAMP(offset, 0, buf1->y);
110
 
                }
111
 
                
112
 
                if (node->custom2 == 0) {
113
 
                        for (y=0; y<buf1->y; y++) {
114
 
                                float *fac= mask->rect + y*buf1->x;
115
 
                                for (x=offset; x>0; x--, fac++)
116
 
                                        *fac= 1.0f;
117
 
                        }
118
 
                }
119
 
                else {
120
 
                        for (y=0; y<offset; y++) {
121
 
                                float *fac= mask->rect + y*buf1->x;
122
 
                                for (x=buf1->x; x>0; x--, fac++)
123
 
                                        *fac= 1.0f;
124
 
                        }
125
 
                }
126
 
                
127
 
                composit3_pixel_processor(node, cbuf, buf1, in[0]->vec, buf2, in[1]->vec, mask, NULL, do_copy_split_rgba, CB_RGBA, CB_RGBA, CB_VAL);
128
 
                
129
 
                BKE_image_release_ibuf(ima, lock);
130
 
                
131
 
                generate_preview(data, node, cbuf);
132
 
                free_compbuf(cbuf);
133
 
                free_compbuf(mask);
134
 
                
135
 
                if (in[0]->data != buf1) 
136
 
                        free_compbuf(buf1);
137
 
                if (in[1]->data != buf2) 
138
 
                        free_compbuf(buf2);
139
 
        }
140
 
}
141
 
 
142
 
static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
 
42
static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
143
43
{
144
44
        ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
145
45
        node->storage= iuser;
153
53
{
154
54
        static bNodeType ntype;
155
55
 
156
 
        node_type_base(ttype, &ntype, CMP_NODE_SPLITVIEWER, "SplitViewer", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS);
 
56
        node_type_base(ttype, &ntype, CMP_NODE_SPLITVIEWER, "Split Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS);
157
57
        node_type_socket_templates(&ntype, cmp_node_splitviewer_in, NULL);
158
58
        node_type_size(&ntype, 140, 100, 320);
159
59
        node_type_init(&ntype, node_composit_init_splitviewer);
160
60
        node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
161
 
        node_type_exec(&ntype, node_composit_exec_splitviewer);
 
61
 
162
62
        /* Do not allow muting for this node. */
163
 
        node_type_internal_connect(&ntype, NULL);
 
63
        node_type_internal_links(&ntype, NULL);
164
64
 
165
65
        nodeRegisterType(ttype, &ntype);
166
66
}