1 /*! ========================================================================
4 ** $Id: radialblur.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "radialblur.h"
32 #include <synfig/string.h>
33 #include <synfig/time.h>
34 #include <synfig/context.h>
35 #include <synfig/paramdesc.h>
36 #include <synfig/renddesc.h>
37 #include <synfig/surface.h>
38 #include <synfig/value.h>
39 #include <synfig/valuenode.h>
40 #include <synfig/transform.h>
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_LAYER_INIT(RadialBlur);
50 SYNFIG_LAYER_SET_NAME(RadialBlur,"radial_blur");
51 SYNFIG_LAYER_SET_LOCAL_NAME(RadialBlur,_("Radial Blur"));
52 SYNFIG_LAYER_SET_CATEGORY(RadialBlur,_("Blurs"));
53 SYNFIG_LAYER_SET_VERSION(RadialBlur,"0.1");
54 SYNFIG_LAYER_SET_CVS_ID(RadialBlur,"$Id: radialblur.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 /* === E N T R Y P O I N T ================================================= */
62 RadialBlur::RadialBlur():
69 RadialBlur::~RadialBlur()
74 RadialBlur::set_param(const String & param, const ValueBase &value)
80 return Layer_Composite::set_param(param,value);
84 RadialBlur::get_param(const String ¶m)const
93 return Layer_Composite::get_param(param);
97 RadialBlur::get_param_vocab()const
99 Layer::Vocab ret(Layer_Composite::get_param_vocab());
101 ret.push_back(ParamDesc("origin")
102 .set_local_name(_("Origin"))
103 .set_description(_("Point where you want the origin to be"))
106 ret.push_back(ParamDesc("size")
107 .set_local_name(_("Size"))
108 .set_description(_("Size of blur"))
109 .set_origin("origin")
112 ret.push_back(ParamDesc("fade_out")
113 .set_local_name(_("Fade Out"))
120 RadialBlur::get_color(Context context, const Point &p)const
123 return context.get_color(p);
127 RadialBlur::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
129 if(cb && !cb->amount_complete(0,10000))
134 if(!context.accelerated_render(surface,quality,renddesc,cb))
137 tmp_surface=*surface;
141 const Point tl(renddesc.get_tl());
143 const int w(surface->get_w());
144 const int h(surface->get_h());
145 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
147 Surface::alpha_pen apen(surface->begin());
149 apen.set_alpha(get_amount());
150 apen.set_blend_method(get_blend_method());
154 if(quality>=9)steps=20;
155 else if(quality>=5)steps=30;
156 else if(quality>=4)steps=60;
157 else if(quality>=3)steps=100;
160 Surface::value_prep_type cooker;
162 for(y=0,pos[1]=tl[1];y<h;y++,apen.inc_y(),apen.dec_x(x),pos[1]+=ph)
163 for(x=0,pos[0]=tl[0];x<w;x++,apen.inc_x(),pos[0]+=pw)
167 end((pos-origin)*(1.0f-size)+origin-tl);
168 begin[0]/=pw;begin[1]/=ph;
169 end[0]/=pw;end[1]/=ph;
171 Color pool(Color::alpha());
174 int x0(round_to_int(begin[0])),
175 y0(round_to_int(begin[1])),
176 x1(round_to_int(end[0])),
177 y1(round_to_int(end[1]));
181 int sx, sy; /* step positive or negative (1 or -1) */
182 int dx, dy; /* delta (difference in X and Y between points) */
184 int w(tmp_surface.get_w()),h(tmp_surface.get_h());
187 sx = ((x1 - x0) > 0) ? 1 : -1;
189 sy = ((y1 - y0) > 0) ? 1 : -1;
199 for (i = 0; i < dx; i++)
201 if(y0>=0 && x0>=0 && y0<h && x0<w)
206 pool+=cooker.cook(tmp_surface[y0][x0])*(i-dx);
208 pool+=cooker.cook(tmp_surface[x0][y0])*(i-dx);
214 pool+=cooker.cook(tmp_surface[y0][x0]);
216 pool+=cooker.cook(tmp_surface[x0][y0]);
232 apen.put_value(cooker.uncook(pool));
237 end=(pos-origin)*(1.0f-size)+origin;
239 Color pool(Color::alpha());
242 int steps(steps*size);
243 for(f=0,i=0;i<steps;i++,f+=1.0f/(steps-1))
245 Point loc((end-begin)*f+begin-tl);
246 loc[0]/=pw;loc[1]/=ph;
249 pool+=tmp_surface.linear_sample(loc[0],loc[1])*(i-steps),poolsize+=(i-steps);
251 pool+=tmp_surface.linear_sample(loc[0],loc[1]),poolsize+=1;
254 apen.put_value(pool);
259 if(cb && !cb->amount_complete(10000,10000)) return false;