|
Blender
V2.59
|
00001 /* 00002 * $Id: CMP_gamma.c 35237 2011-02-27 20:13:22Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2006 Blender Foundation. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 00029 */ 00030 00036 #include "../CMP_util.h" 00037 00038 /* **************** Gamma Tools ******************** */ 00039 00040 static bNodeSocketType cmp_node_gamma_in[]= { 00041 { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00042 { SOCK_VALUE, 1, "Gamma", 1.0f, 0.0f, 0.0f, 0.0f, 0.001f, 10.0f}, 00043 { -1, 0, "" } 00044 }; 00045 static bNodeSocketType cmp_node_gamma_out[]= { 00046 { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00047 { -1, 0, "" } 00048 }; 00049 00050 static void do_gamma(bNode *UNUSED(node), float *out, float *in, float *fac) 00051 { 00052 int i=0; 00053 for(i=0; i<3; i++) { 00054 /* check for negative to avoid nan's */ 00055 out[i] = (in[i] > 0.0f)? pow(in[i],fac[0]): in[i]; 00056 } 00057 out[3] = in[3]; 00058 } 00059 static void node_composit_exec_gamma(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00060 { 00061 /* stack order in: Fac, Image */ 00062 /* stack order out: Image */ 00063 if(out[0]->hasoutput==0) return; 00064 00065 /* input no image? then only color operation */ 00066 if(in[0]->data==NULL) { 00067 do_gamma(node, out[0]->vec, in[0]->vec, in[1]->vec); 00068 } 00069 else { 00070 /* make output size of input image */ 00071 CompBuf *cbuf= in[0]->data; 00072 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs 00073 00074 composit2_pixel_processor(node, stackbuf, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_gamma, CB_RGBA, CB_VAL); 00075 00076 out[0]->data= stackbuf; 00077 } 00078 } 00079 00080 void register_node_type_cmp_gamma(ListBase *lb) 00081 { 00082 static bNodeType ntype; 00083 00084 node_type_base(&ntype, CMP_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, NODE_OPTIONS, 00085 cmp_node_gamma_in, cmp_node_gamma_out); 00086 node_type_size(&ntype, 140, 100, 320); 00087 node_type_exec(&ntype, node_composit_exec_gamma); 00088 00089 nodeRegisterType(lb, &ntype); 00090 }