|
Blender
V2.59
|
00001 /* 00002 * 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): Juho Vepsäläinen 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00035 #include "../CMP_util.h" 00036 00037 /* **************** Crop ******************** */ 00038 00039 static bNodeSocketType cmp_node_crop_in[]= { 00040 { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, 00041 { -1, 0, "" } 00042 }; 00043 static bNodeSocketType cmp_node_crop_out[]= { 00044 { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00045 { -1, 0, "" } 00046 }; 00047 00048 static void node_composit_exec_crop(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00049 { 00050 if(in[0]->data) { 00051 NodeTwoXYs *ntxy= node->storage; 00052 CompBuf *cbuf= in[0]->data; 00053 CompBuf *stackbuf; 00054 int x, y; 00055 float *srcfp, *outfp; 00056 rcti outputrect; 00057 00058 if(node->custom2) { 00059 ntxy->x1= cbuf->x* ntxy->fac_x1; 00060 ntxy->x2= cbuf->x* ntxy->fac_x2; 00061 ntxy->y1= cbuf->y* ntxy->fac_y1; 00062 ntxy->y2= cbuf->y* ntxy->fac_y2; 00063 } 00064 00065 /* check input image size */ 00066 if(cbuf->x <= ntxy->x1 + 1) 00067 ntxy->x1= cbuf->x - 1; 00068 00069 if(cbuf->y <= ntxy->y1 + 1) 00070 ntxy->y1= cbuf->y - 1; 00071 00072 if(cbuf->x <= ntxy->x2 + 1) 00073 ntxy->x2= cbuf->x - 1; 00074 00075 if(cbuf->y <= ntxy->y2 + 1) 00076 ntxy->y2= cbuf->y - 1; 00077 00078 /* figure out the minimums and maximums */ 00079 outputrect.xmax=MAX2(ntxy->x1, ntxy->x2) + 1; 00080 outputrect.xmin=MIN2(ntxy->x1, ntxy->x2); 00081 outputrect.ymax=MAX2(ntxy->y1, ntxy->y2) + 1; 00082 outputrect.ymin=MIN2(ntxy->y1, ntxy->y2); 00083 00084 if(node->custom1) { 00085 /* this option crops the image size too */ 00086 stackbuf= get_cropped_compbuf(&outputrect, cbuf->rect, cbuf->x, cbuf->y, cbuf->type); 00087 } 00088 else { 00089 /* this option won't crop the size of the image as well */ 00090 /* allocate memory for the output image */ 00091 stackbuf = alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1); 00092 00093 /* select the cropped part of the image and set it to the output */ 00094 for(y=outputrect.ymin; y<outputrect.ymax; y++){ 00095 srcfp= cbuf->rect + (y * cbuf->x + outputrect.xmin) * cbuf->type; 00096 outfp= stackbuf->rect + (y * stackbuf->x + outputrect.xmin) * stackbuf->type; 00097 for(x=outputrect.xmin; x<outputrect.xmax; x++, outfp+= stackbuf->type, srcfp+= cbuf->type) 00098 memcpy(outfp, srcfp, sizeof(float)*stackbuf->type); 00099 } 00100 } 00101 00102 out[0]->data= stackbuf; 00103 } 00104 } 00105 00106 static void node_composit_init_crop(bNode* node) 00107 { 00108 NodeTwoXYs *nxy= MEM_callocN(sizeof(NodeTwoXYs), "node xy data"); 00109 node->storage= nxy; 00110 nxy->x1= 0; 00111 nxy->x2= 0; 00112 nxy->y1= 0; 00113 nxy->y2= 0; 00114 } 00115 00116 void register_node_type_cmp_crop(ListBase *lb) 00117 { 00118 static bNodeType ntype; 00119 00120 node_type_base(&ntype, CMP_NODE_CROP, "Crop", NODE_CLASS_DISTORT, NODE_OPTIONS, 00121 cmp_node_crop_in, cmp_node_crop_out); 00122 node_type_size(&ntype, 140, 100, 320); 00123 node_type_init(&ntype, node_composit_init_crop); 00124 node_type_storage(&ntype, "NodeTwoXYs", node_free_standard_storage, node_copy_standard_storage); 00125 node_type_exec(&ntype, node_composit_exec_crop); 00126 00127 nodeRegisterType(lb, &ntype); 00128 } 00129