1 /* === S Y N F I G ========================================================= */
2 /*! \file radialblur.cpp
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "radialblur.h"
35 #include <synfig/string.h>
36 #include <synfig/time.h>
37 #include <synfig/context.h>
38 #include <synfig/paramdesc.h>
39 #include <synfig/renddesc.h>
40 #include <synfig/surface.h>
41 #include <synfig/value.h>
42 #include <synfig/valuenode.h>
43 #include <synfig/transform.h>
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 SYNFIG_LAYER_INIT(RadialBlur);
53 SYNFIG_LAYER_SET_NAME(RadialBlur,"radial_blur");
54 SYNFIG_LAYER_SET_LOCAL_NAME(RadialBlur,_("Radial Blur"));
55 SYNFIG_LAYER_SET_CATEGORY(RadialBlur,_("Blurs"));
56 SYNFIG_LAYER_SET_VERSION(RadialBlur,"0.1");
57 SYNFIG_LAYER_SET_CVS_ID(RadialBlur,"$Id$");
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 /* === E N T R Y P O I N T ================================================= */
65 RadialBlur::RadialBlur():
72 RadialBlur::~RadialBlur()
77 RadialBlur::set_param(const String & param, const ValueBase &value)
83 return Layer_Composite::set_param(param,value);
87 RadialBlur::get_param(const String ¶m)const
96 return Layer_Composite::get_param(param);
100 RadialBlur::get_param_vocab()const
102 Layer::Vocab ret(Layer_Composite::get_param_vocab());
104 ret.push_back(ParamDesc("origin")
105 .set_local_name(_("Origin"))
106 .set_description(_("Point where you want the origin to be"))
109 ret.push_back(ParamDesc("size")
110 .set_local_name(_("Size"))
111 .set_description(_("Size of blur"))
112 .set_origin("origin")
115 ret.push_back(ParamDesc("fade_out")
116 .set_local_name(_("Fade Out"))
123 RadialBlur::get_color(Context context, const Point &p)const
126 return context.get_color(p);
130 RadialBlur::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
132 if(cb && !cb->amount_complete(0,10000))
137 if(!context.accelerated_render(surface,quality,renddesc,cb))
140 tmp_surface=*surface;
144 const Point tl(renddesc.get_tl());
146 const int w(surface->get_w());
147 const int h(surface->get_h());
148 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
150 Surface::alpha_pen apen(surface->begin());
152 apen.set_alpha(get_amount());
153 apen.set_blend_method(get_blend_method());
157 if(quality>=9)steps=20;
158 else if(quality>=5)steps=30;
159 else if(quality>=4)steps=60;
160 else if(quality>=3)steps=100;
163 Surface::value_prep_type cooker;
165 for(y=0,pos[1]=tl[1];y<h;y++,apen.inc_y(),apen.dec_x(x),pos[1]+=ph)
166 for(x=0,pos[0]=tl[0];x<w;x++,apen.inc_x(),pos[0]+=pw)
170 end((pos-origin)*(1.0f-size)+origin-tl);
171 begin[0]/=pw;begin[1]/=ph;
172 end[0]/=pw;end[1]/=ph;
174 Color pool(Color::alpha());
177 int x0(round_to_int(begin[0])),
178 y0(round_to_int(begin[1])),
179 x1(round_to_int(end[0])),
180 y1(round_to_int(end[1]));
184 int sx, sy; /* step positive or negative (1 or -1) */
185 int dx, dy; /* delta (difference in X and Y between points) */
187 int w(tmp_surface.get_w()),h(tmp_surface.get_h());
190 sx = ((x1 - x0) > 0) ? 1 : -1;
192 sy = ((y1 - y0) > 0) ? 1 : -1;
202 for (i = 0; i < dx; i++)
204 if(y0>=0 && x0>=0 && y0<h && x0<w)
209 pool+=cooker.cook(tmp_surface[y0][x0])*(i-dx);
211 pool+=cooker.cook(tmp_surface[x0][y0])*(i-dx);
217 pool+=cooker.cook(tmp_surface[y0][x0]);
219 pool+=cooker.cook(tmp_surface[x0][y0]);
235 apen.put_value(cooker.uncook(pool));
240 end=(pos-origin)*(1.0f-size)+origin;
242 Color pool(Color::alpha());
245 int steps(steps*size);
246 for(f=0,i=0;i<steps;i++,f+=1.0f/(steps-1))
248 Point loc((end-begin)*f+begin-tl);
249 loc[0]/=pw;loc[1]/=ph;
252 pool+=tmp_surface.linear_sample(loc[0],loc[1])*(i-steps),poolsize+=(i-steps);
254 pool+=tmp_surface.linear_sample(loc[0],loc[1]),poolsize+=1;
257 apen.put_value(pool);
262 if(cb && !cb->amount_complete(10000,10000)) return false;