~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: CMP_alphaOver.c,v 1.5 2007/04/04 13:58:09 jesterking Exp $
 
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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==1.0f && over[3]>=1.0f) {
 
51
                QUATCOPY(out, over);
 
52
        }
 
53
        else {
 
54
                float mul= 1.0f - *fac*over[3];
 
55
 
 
56
                out[0]= (mul*src[0]) + *fac*over[0];
 
57
                out[1]= (mul*src[1]) + *fac*over[1];
 
58
                out[2]= (mul*src[2]) + *fac*over[2];
 
59
                out[3]= (mul*src[3]) + *fac*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==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
 
 
85
static void node_composit_exec_alphaover(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
86
{
 
87
        /* stack order in: col col */
 
88
        /* stack order out: col */
 
89
        if(out[0]->hasoutput==0) 
 
90
                return;
 
91
        
 
92
        /* input no image? then only color operation */
 
93
        if(in[1]->data==NULL) {
 
94
                do_alphaover_premul(node, out[0]->vec, in[1]->vec, in[2]->vec, in[0]->vec);
 
95
        }
 
96
        else {
 
97
                /* make output size of input image */
 
98
                CompBuf *cbuf= in[1]->data;
 
99
                CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
 
100
                
 
101
                if(node->custom1)
 
102
                        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);
 
103
                else
 
104
                        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);
 
105
                
 
106
                out[0]->data= stackbuf;
 
107
        }
 
108
}
 
109
 
 
110
bNodeType cmp_node_alphaover= {
 
111
        /* *next,*prev */       NULL, NULL,
 
112
        /* type code   */       CMP_NODE_ALPHAOVER,
 
113
        /* name        */       "AlphaOver",
 
114
        /* width+range */       80, 40, 120,
 
115
        /* class+opts  */       NODE_CLASS_OP_COLOR, NODE_OPTIONS,
 
116
        /* input sock  */       cmp_node_alphaover_in,
 
117
        /* output sock */       cmp_node_alphaover_out,
 
118
        /* storage     */       "",
 
119
        /* execfunc    */       node_composit_exec_alphaover,
 
120
        /* butfunc     */       NULL,
 
121
        /* initfunc    */       NULL,
 
122
        /* freestoragefunc    */        NULL,
 
123
        /* copystoragefunc    */        NULL,
 
124
        /* id          */       NULL
 
125
        
 
126
};
 
127
 
 
128