2
* $Id: CMP_valToRgb.c,v 1.4 2007/04/04 13:58:10 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"
33
/* **************** VALTORGB ******************** */
34
static bNodeSocketType cmp_node_valtorgb_in[]= {
35
{ SOCK_VALUE, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
38
static bNodeSocketType cmp_node_valtorgb_out[]= {
39
{ SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
40
{ SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
44
static void do_colorband_composit(bNode *node, float *out, float *in)
46
do_colorband(node->storage, in[0], out);
49
static void node_composit_exec_valtorgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
51
/* stack order in: fac */
52
/* stack order out: col, alpha */
54
if(out[0]->hasoutput==0 && out[1]->hasoutput==0)
58
/* input no image? then only color operation */
59
if(in[0]->data==NULL) {
60
do_colorband(node->storage, in[0]->vec[0], out[0]->vec);
63
/* make output size of input image */
64
CompBuf *cbuf= in[0]->data;
65
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
67
composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_colorband_composit, CB_VAL);
69
out[0]->data= stackbuf;
72
out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A);
78
static void node_composit_init_valtorgb(bNode* node)
80
node->storage= add_colorband(1);
83
bNodeType cmp_node_valtorgb= {
84
/* *next,*prev */ NULL, NULL,
85
/* type code */ CMP_NODE_VALTORGB,
86
/* name */ "ColorRamp",
87
/* width+range */ 240, 200, 300,
88
/* class+opts */ NODE_CLASS_CONVERTOR, NODE_OPTIONS,
89
/* input sock */ cmp_node_valtorgb_in,
90
/* output sock */ cmp_node_valtorgb_out,
91
/* storage */ "ColorBand",
92
/* execfunc */ node_composit_exec_valtorgb,
94
/* initfunc */ node_composit_init_valtorgb,
95
/* freestoragefunc */ node_free_standard_storage,
96
/* copystoragefunc */ node_copy_standard_storage,
102
/* **************** RGBTOBW ******************** */
103
static bNodeSocketType cmp_node_rgbtobw_in[]= {
104
{ SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
107
static bNodeSocketType cmp_node_rgbtobw_out[]= {
108
{ SOCK_VALUE, 0, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
112
static void do_rgbtobw(bNode *node, float *out, float *in)
114
out[0]= in[0]*0.35f + in[1]*0.45f + in[2]*0.2f;
117
static void node_composit_exec_rgbtobw(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
119
/* stack order out: bw */
120
/* stack order in: col */
122
if(out[0]->hasoutput==0)
125
/* input no image? then only color operation */
126
if(in[0]->data==NULL) {
127
do_rgbtobw(node, out[0]->vec, in[0]->vec);
130
/* make output size of input image */
131
CompBuf *cbuf= in[0]->data;
132
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
134
composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_rgbtobw, CB_RGBA);
136
out[0]->data= stackbuf;
140
bNodeType cmp_node_rgbtobw= {
141
/* *next,*prev */ NULL, NULL,
142
/* type code */ CMP_NODE_RGBTOBW,
143
/* name */ "RGB to BW",
144
/* width+range */ 80, 40, 120,
145
/* class+opts */ NODE_CLASS_CONVERTOR, 0,
146
/* input sock */ cmp_node_rgbtobw_in,
147
/* output sock */ cmp_node_rgbtobw_out,
149
/* execfunc */ node_composit_exec_rgbtobw,
151
/* freestoragefunc */ NULL,
152
/* copystoragefunc */ NULL,