|
Blender
V2.59
|
00001 /* 00002 * $Id: CMP_scale.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 00035 #include "../CMP_util.h" 00036 00037 /* **************** Scale ******************** */ 00038 00039 #define CMP_SCALE_MAX 12000 00040 00041 static bNodeSocketType cmp_node_scale_in[]= { 00042 { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00043 { SOCK_VALUE, 1, "X", 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX}, 00044 { SOCK_VALUE, 1, "Y", 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX}, 00045 { -1, 0, "" } 00046 }; 00047 static bNodeSocketType cmp_node_scale_out[]= { 00048 { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00049 { -1, 0, "" } 00050 }; 00051 00052 /* only supports RGBA nodes now */ 00053 /* node->custom1 stores if input values are absolute or relative scale */ 00054 static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, bNodeStack **out) 00055 { 00056 if(out[0]->hasoutput==0) 00057 return; 00058 00059 if(in[0]->data) { 00060 RenderData *rd= data; 00061 CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA); 00062 ImBuf *ibuf; 00063 int newx, newy; 00064 00065 if(node->custom1==CMP_SCALE_RELATIVE) { 00066 newx= MAX2((int)(in[1]->vec[0]*cbuf->x), 1); 00067 newy= MAX2((int)(in[2]->vec[0]*cbuf->y), 1); 00068 } 00069 else if(node->custom1==CMP_SCALE_SCENEPERCENT) { 00070 newx = cbuf->x * (rd->size / 100.0f); 00071 newy = cbuf->y * (rd->size / 100.0f); 00072 } 00073 else if (node->custom1==CMP_SCALE_RENDERPERCENT) { 00074 newx= (rd->xsch * rd->size)/100; 00075 newy= (rd->ysch * rd->size)/100; 00076 } else { /* CMP_SCALE_ABSOLUTE */ 00077 newx= MAX2((int)in[1]->vec[0], 1); 00078 newy= MAX2((int)in[2]->vec[0], 1); 00079 } 00080 newx= MIN2(newx, CMP_SCALE_MAX); 00081 newy= MIN2(newy, CMP_SCALE_MAX); 00082 00083 ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0); 00084 if(ibuf) { 00085 ibuf->rect_float= cbuf->rect; 00086 IMB_scaleImBuf(ibuf, newx, newy); 00087 00088 if(ibuf->rect_float == cbuf->rect) { 00089 /* no scaling happened. */ 00090 stackbuf= pass_on_compbuf(in[0]->data); 00091 } 00092 else { 00093 stackbuf= alloc_compbuf(newx, newy, CB_RGBA, 0); 00094 stackbuf->rect= ibuf->rect_float; 00095 stackbuf->malloc= 1; 00096 } 00097 00098 ibuf->rect_float= NULL; 00099 ibuf->mall &= ~IB_rectfloat; 00100 IMB_freeImBuf(ibuf); 00101 00102 /* also do the translation vector */ 00103 stackbuf->xof = (int)(((float)newx/(float)cbuf->x) * (float)cbuf->xof); 00104 stackbuf->yof = (int)(((float)newy/(float)cbuf->y) * (float)cbuf->yof); 00105 } 00106 else { 00107 stackbuf= dupalloc_compbuf(cbuf); 00108 printf("Scaling to %dx%d failed\n", newx, newy); 00109 } 00110 00111 out[0]->data= stackbuf; 00112 if(cbuf!=in[0]->data) 00113 free_compbuf(cbuf); 00114 } 00115 } 00116 00117 void register_node_type_cmp_scale(ListBase *lb) 00118 { 00119 static bNodeType ntype; 00120 00121 node_type_base(&ntype, CMP_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, NODE_OPTIONS, 00122 cmp_node_scale_in, cmp_node_scale_out); 00123 node_type_size(&ntype, 140, 100, 320); 00124 node_type_exec(&ntype, node_composit_exec_scale); 00125 00126 nodeRegisterType(lb, &ntype); 00127 } 00128 00129 00130 00131 00132 00133 00134