2
* $Id: CMP_alphaOver.c 26841 2010-02-12 13:34:04Z campbellbarton $
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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[0]==1.0f && over[3]>=1.0f) {
54
float mul= 1.0f - fac[0]*over[3];
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];
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[0]==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];
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)
91
else if(fac[0]==1.0f && over[3]>=1.0f) {
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];
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];
110
static void node_composit_exec_alphaover(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
112
/* stack order in: col col */
113
/* stack order out: col */
114
if(out[0]->hasoutput==0)
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);
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;
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);
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);
134
out[0]->data= stackbuf;
138
static void node_alphaover_init(bNode* node)
140
node->storage= MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats");
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,
154
/* initfunc */ node_alphaover_init,
155
/* freestoragefunc */ node_free_standard_storage,
156
/* copystoragefunc */ node_copy_standard_storage,