Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2006 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): Juho Vepsäläinen 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "node_composite_util.h" 00034 00035 /* **************** Crop ******************** */ 00036 00037 static bNodeSocketTemplate cmp_node_crop_in[]= { 00038 { SOCK_RGBA, 1, "Image", 1.0f, 1.0f, 1.0f, 1.0f}, 00039 { -1, 0, "" } 00040 }; 00041 static bNodeSocketTemplate cmp_node_crop_out[]= { 00042 { SOCK_RGBA, 0, "Image"}, 00043 { -1, 0, "" } 00044 }; 00045 00046 static void node_composit_exec_crop(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00047 { 00048 if(in[0]->data) { 00049 NodeTwoXYs *ntxy= node->storage; 00050 CompBuf *cbuf= in[0]->data; 00051 CompBuf *stackbuf; 00052 int x, y; 00053 float *srcfp, *outfp; 00054 rcti outputrect; 00055 00056 if(node->custom2) { 00057 ntxy->x1= cbuf->x* ntxy->fac_x1; 00058 ntxy->x2= cbuf->x* ntxy->fac_x2; 00059 ntxy->y1= cbuf->y* ntxy->fac_y1; 00060 ntxy->y2= cbuf->y* ntxy->fac_y2; 00061 } 00062 00063 /* check input image size */ 00064 if(cbuf->x <= ntxy->x1 + 1) 00065 ntxy->x1= cbuf->x - 1; 00066 00067 if(cbuf->y <= ntxy->y1 + 1) 00068 ntxy->y1= cbuf->y - 1; 00069 00070 if(cbuf->x <= ntxy->x2 + 1) 00071 ntxy->x2= cbuf->x - 1; 00072 00073 if(cbuf->y <= ntxy->y2 + 1) 00074 ntxy->y2= cbuf->y - 1; 00075 00076 /* figure out the minimums and maximums */ 00077 outputrect.xmax=MAX2(ntxy->x1, ntxy->x2) + 1; 00078 outputrect.xmin=MIN2(ntxy->x1, ntxy->x2); 00079 outputrect.ymax=MAX2(ntxy->y1, ntxy->y2) + 1; 00080 outputrect.ymin=MIN2(ntxy->y1, ntxy->y2); 00081 00082 if(node->custom1) { 00083 /* this option crops the image size too */ 00084 stackbuf= get_cropped_compbuf(&outputrect, cbuf->rect, cbuf->x, cbuf->y, cbuf->type); 00085 } 00086 else { 00087 /* this option won't crop the size of the image as well */ 00088 /* allocate memory for the output image */ 00089 stackbuf = alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1); 00090 00091 /* select the cropped part of the image and set it to the output */ 00092 for(y=outputrect.ymin; y<outputrect.ymax; y++){ 00093 srcfp= cbuf->rect + (y * cbuf->x + outputrect.xmin) * cbuf->type; 00094 outfp= stackbuf->rect + (y * stackbuf->x + outputrect.xmin) * stackbuf->type; 00095 for(x=outputrect.xmin; x<outputrect.xmax; x++, outfp+= stackbuf->type, srcfp+= cbuf->type) 00096 memcpy(outfp, srcfp, sizeof(float)*stackbuf->type); 00097 } 00098 } 00099 00100 out[0]->data= stackbuf; 00101 } 00102 } 00103 00104 static void node_composit_init_crop(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) 00105 { 00106 NodeTwoXYs *nxy= MEM_callocN(sizeof(NodeTwoXYs), "node xy data"); 00107 node->storage= nxy; 00108 nxy->x1= 0; 00109 nxy->x2= 0; 00110 nxy->y1= 0; 00111 nxy->y2= 0; 00112 } 00113 00114 void register_node_type_cmp_crop(bNodeTreeType *ttype) 00115 { 00116 static bNodeType ntype; 00117 00118 node_type_base(ttype, &ntype, CMP_NODE_CROP, "Crop", NODE_CLASS_DISTORT, NODE_OPTIONS); 00119 node_type_socket_templates(&ntype, cmp_node_crop_in, cmp_node_crop_out); 00120 node_type_size(&ntype, 140, 100, 320); 00121 node_type_init(&ntype, node_composit_init_crop); 00122 node_type_storage(&ntype, "NodeTwoXYs", node_free_standard_storage, node_copy_standard_storage); 00123 node_type_exec(&ntype, node_composit_exec_crop); 00124 00125 nodeRegisterType(ttype, &ntype); 00126 }