2
* $Id: CMP_alphaOver.c,v 1.5 2007/04/04 13:58:09 jesterking Exp $
4
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20
* The Original Code is Copyright (C) 2006 Blender Foundation.
21
* All rights reserved.
23
* The Original Code is: all of this file.
25
* Contributor(s): none yet.
27
* ***** END GPL LICENSE BLOCK *****
30
#include "../CMP_util.h"
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},
39
static bNodeSocketType cmp_node_alphaover_out[]= {
40
{ SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
44
static void do_alphaover_premul(bNode *node, float *out, float *src, float *over, float *fac)
50
else if(*fac==1.0f && over[3]>=1.0f) {
54
float mul= 1.0f - *fac*over[3];
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];
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)
70
else if(*fac==1.0f && over[3]>=1.0f) {
74
float premul= fac[0]*over[3];
75
float mul= 1.0f - premul;
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];
85
static void node_composit_exec_alphaover(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
87
/* stack order in: col col */
88
/* stack order out: col */
89
if(out[0]->hasoutput==0)
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);
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 */
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);
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);
106
out[0]->data= stackbuf;
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,
119
/* execfunc */ node_composit_exec_alphaover,
122
/* freestoragefunc */ NULL,
123
/* copystoragefunc */ NULL,