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): Alfredo de Greef (eeshlo) 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "node_composite_util.h" 00034 00035 static bNodeSocketTemplate cmp_node_dblur_in[]= { 00036 { SOCK_RGBA, 1, "Image", 1.0f, 1.0f, 1.0f, 1.f}, 00037 { -1, 0, "" } 00038 }; 00039 00040 static bNodeSocketTemplate cmp_node_dblur_out[]= { 00041 { SOCK_RGBA, 0, "Image"}, 00042 { -1, 0, "" } 00043 }; 00044 00045 static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap, 00046 float center_x, float center_y, float dist, float angle, float spin, float zoom) 00047 { 00048 if ((dist != 0.f) || (spin != 0.f) || (zoom != 0.f)) { 00049 void (*getpix)(CompBuf*, float, float, float*) = wrap ? qd_getPixelLerpWrap : qd_getPixelLerp; 00050 const float a= angle; 00051 const float itsc= 1.f / powf(2.f, (float)iterations); 00052 float D; 00053 float center_x_pix, center_y_pix; 00054 float tx, ty; 00055 float sc, rot; 00056 CompBuf *tmp; 00057 int i, j; 00058 00059 tmp= dupalloc_compbuf(img); 00060 00061 D= dist * sqrtf(img->x * img->x + img->y * img->y); 00062 center_x_pix= center_x * img->x; 00063 center_y_pix= center_y * img->y; 00064 00065 tx= itsc * D * cosf(a); 00066 ty= -itsc * D * sinf(a); 00067 sc= itsc * zoom; 00068 rot= itsc * spin; 00069 00070 /* blur the image */ 00071 for(i= 0; i < iterations; ++i) { 00072 const float cs= cosf(rot), ss= sinf(rot); 00073 const float isc= 1.f / (1.f + sc); 00074 unsigned int x, y; 00075 float col[4]= {0,0,0,0}; 00076 00077 for(y= 0; y < img->y; ++y) { 00078 const float v= isc * (y - center_y_pix) + ty; 00079 00080 for(x= 0; x < img->x; ++x) { 00081 const float u= isc * (x - center_x_pix) + tx; 00082 unsigned int p= (x + y * img->x) * img->type; 00083 00084 getpix(tmp, cs * u + ss * v + center_x_pix, cs * v - ss * u + center_y_pix, col); 00085 00086 /* mix img and transformed tmp */ 00087 for(j= 0; j < 4; ++j) { 00088 img->rect[p + j]= 0.5f * (img->rect[p + j] + col[j]); 00089 } 00090 } 00091 } 00092 00093 /* copy img to tmp */ 00094 if(i != (iterations - 1)) 00095 memcpy(tmp->rect, img->rect, sizeof(float) * img->x * img->y * img->type); 00096 00097 /* double transformations */ 00098 tx *= 2.f, ty *= 2.f; 00099 sc *= 2.f, rot *= 2.f; 00100 00101 if(node->exec & NODE_BREAK) break; 00102 } 00103 00104 free_compbuf(tmp); 00105 } 00106 00107 return img; 00108 } 00109 00110 static void node_composit_exec_dblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00111 { 00112 NodeDBlurData *ndbd= node->storage; 00113 CompBuf *new, *img= in[0]->data; 00114 00115 if((img == NULL) || (out[0]->hasoutput == 0)) return; 00116 00117 if (img->type != CB_RGBA) 00118 new = typecheck_compbuf(img, CB_RGBA); 00119 else 00120 new = dupalloc_compbuf(img); 00121 00122 out[0]->data= dblur(node, new, ndbd->iter, ndbd->wrap, ndbd->center_x, ndbd->center_y, ndbd->distance, ndbd->angle, ndbd->spin, ndbd->zoom); 00123 } 00124 00125 static void node_composit_init_dblur(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) 00126 { 00127 NodeDBlurData *ndbd= MEM_callocN(sizeof(NodeDBlurData), "node dblur data"); 00128 node->storage= ndbd; 00129 ndbd->center_x= 0.5; 00130 ndbd->center_y= 0.5; 00131 } 00132 00133 void register_node_type_cmp_dblur(bNodeTreeType *ttype) 00134 { 00135 static bNodeType ntype; 00136 00137 node_type_base(ttype, &ntype, CMP_NODE_DBLUR, "Directional Blur", NODE_CLASS_OP_FILTER, NODE_OPTIONS); 00138 node_type_socket_templates(&ntype, cmp_node_dblur_in, cmp_node_dblur_out); 00139 node_type_size(&ntype, 150, 120, 200); 00140 node_type_init(&ntype, node_composit_init_dblur); 00141 node_type_storage(&ntype, "NodeDBlurData", node_free_standard_storage, node_copy_standard_storage); 00142 node_type_exec(&ntype, node_composit_exec_dblur); 00143 00144 nodeRegisterType(ttype, &ntype); 00145 }