~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_alphaOver.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: CMP_alphaOver.c 26841 2010-02-12 13:34:04Z campbellbarton $
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
 
/* **************** ALPHAOVER ******************** */
33
 
static bNodeSocketType cmp_node_alphaover_in[]= {
34
 
        {       SOCK_VALUE, 1, "Fac",                   1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f},
35
 
        {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
36
 
        {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
37
 
        {       -1, 0, ""       }
38
 
};
39
 
static bNodeSocketType cmp_node_alphaover_out[]= {
40
 
        {       SOCK_RGBA, 0, "Image",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
41
 
        {       -1, 0, ""       }
42
 
};
43
 
 
44
 
static void do_alphaover_premul(bNode *node, float *out, float *src, float *over, float *fac)
45
 
{
46
 
        
47
 
        if(over[3]<=0.0f) {
48
 
                QUATCOPY(out, src);
49
 
        }
50
 
        else if(fac[0]==1.0f && over[3]>=1.0f) {
51
 
                QUATCOPY(out, over);
52
 
        }
53
 
        else {
54
 
                float mul= 1.0f - fac[0]*over[3];
55
 
 
56
 
                out[0]= (mul*src[0]) + fac[0]*over[0];
57
 
                out[1]= (mul*src[1]) + fac[0]*over[1];
58
 
                out[2]= (mul*src[2]) + fac[0]*over[2];
59
 
                out[3]= (mul*src[3]) + fac[0]*over[3];
60
 
        }       
61
 
}
62
 
 
63
 
/* result will be still premul, but the over part is premulled */
64
 
static void do_alphaover_key(bNode *node, float *out, float *src, float *over, float *fac)
65
 
{
66
 
        
67
 
        if(over[3]<=0.0f) {
68
 
                QUATCOPY(out, src);
69
 
        }
70
 
        else if(fac[0]==1.0f && over[3]>=1.0f) {
71
 
                QUATCOPY(out, over);
72
 
        }
73
 
        else {
74
 
                float premul= fac[0]*over[3];
75
 
                float mul= 1.0f - premul;
76
 
 
77
 
                out[0]= (mul*src[0]) + premul*over[0];
78
 
                out[1]= (mul*src[1]) + premul*over[1];
79
 
                out[2]= (mul*src[2]) + premul*over[2];
80
 
                out[3]= (mul*src[3]) + fac[0]*over[3];
81
 
        }
82
 
}
83
 
 
84
 
/* result will be still premul, but the over part is premulled */
85
 
static void do_alphaover_mixed(bNode *node, float *out, float *src, float *over, float *fac)
86
 
{
87
 
        
88
 
        if(over[3]<=0.0f) {
89
 
                QUATCOPY(out, src);
90
 
        }
91
 
        else if(fac[0]==1.0f && over[3]>=1.0f) {
92
 
                QUATCOPY(out, over);
93
 
        }
94
 
        else {
95
 
                NodeTwoFloats *ntf= node->storage;
96
 
                float addfac= 1.0f - ntf->x + over[3]*ntf->x;
97
 
                float premul= fac[0]*addfac;
98
 
                float mul= 1.0f - fac[0]*over[3];
99
 
                
100
 
                out[0]= (mul*src[0]) + premul*over[0];
101
 
                out[1]= (mul*src[1]) + premul*over[1];
102
 
                out[2]= (mul*src[2]) + premul*over[2];
103
 
                out[3]= (mul*src[3]) + fac[0]*over[3];
104
 
        }
105
 
}
106
 
 
107
 
 
108
 
 
109
 
 
110
 
static void node_composit_exec_alphaover(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
111
 
{
112
 
        /* stack order in: col col */
113
 
        /* stack order out: col */
114
 
        if(out[0]->hasoutput==0) 
115
 
                return;
116
 
        
117
 
        /* input no image? then only color operation */
118
 
        if(in[1]->data==NULL && in[2]->data==NULL) {
119
 
                do_alphaover_premul(node, out[0]->vec, in[1]->vec, in[2]->vec, in[0]->vec);
120
 
        }
121
 
        else {
122
 
                /* make output size of input image */
123
 
                CompBuf *cbuf= in[1]->data?in[1]->data:in[2]->data;
124
 
                CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
125
 
                NodeTwoFloats *ntf= node->storage;
126
 
                
127
 
                if(ntf->x != 0.0f)
128
 
                        composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_mixed, CB_RGBA, CB_RGBA, CB_VAL);
129
 
                else if(node->custom1)
130
 
                        composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_key, CB_RGBA, CB_RGBA, CB_VAL);
131
 
                else
132
 
                        composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_premul, CB_RGBA, CB_RGBA, CB_VAL);
133
 
                
134
 
                out[0]->data= stackbuf;
135
 
        }
136
 
}
137
 
 
138
 
static void node_alphaover_init(bNode* node)
139
 
{
140
 
   node->storage= MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats");
141
 
}
142
 
 
143
 
bNodeType cmp_node_alphaover= {
144
 
        /* *next,*prev */       NULL, NULL,
145
 
        /* type code   */       CMP_NODE_ALPHAOVER,
146
 
        /* name        */       "AlphaOver",
147
 
        /* width+range */       80, 40, 120,
148
 
        /* class+opts  */       NODE_CLASS_OP_COLOR, NODE_OPTIONS,
149
 
        /* input sock  */       cmp_node_alphaover_in,
150
 
        /* output sock */       cmp_node_alphaover_out,
151
 
        /* storage     */       "NodeTwoFloats",
152
 
        /* execfunc    */       node_composit_exec_alphaover,
153
 
        /* butfunc     */       NULL,
154
 
        /* initfunc    */       node_alphaover_init,
155
 
        /* freestoragefunc    */        node_free_standard_storage,
156
 
        /* copystoragefunc    */        node_copy_standard_storage,
157
 
        /* id          */       NULL
158
 
        
159
 
};
160
 
 
161