1 /* === S Y N F I G ========================================================= */
2 /*! \file radialblur.cpp
3 ** \brief Template Header
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.
19 ** === N O T E S ===========================================================
21 ** ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "radialblur.h"
33 #include <synfig/string.h>
34 #include <synfig/time.h>
35 #include <synfig/context.h>
36 #include <synfig/paramdesc.h>
37 #include <synfig/renddesc.h>
38 #include <synfig/surface.h>
39 #include <synfig/value.h>
40 #include <synfig/valuenode.h>
41 #include <synfig/transform.h>
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 SYNFIG_LAYER_INIT(RadialBlur);
51 SYNFIG_LAYER_SET_NAME(RadialBlur,"radial_blur");
52 SYNFIG_LAYER_SET_LOCAL_NAME(RadialBlur,_("Radial Blur"));
53 SYNFIG_LAYER_SET_CATEGORY(RadialBlur,_("Blurs"));
54 SYNFIG_LAYER_SET_VERSION(RadialBlur,"0.1");
55 SYNFIG_LAYER_SET_CVS_ID(RadialBlur,"$Id$");
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 /* === E N T R Y P O I N T ================================================= */
63 RadialBlur::RadialBlur():
70 RadialBlur::~RadialBlur()
75 RadialBlur::set_param(const String & param, const ValueBase &value)
81 return Layer_Composite::set_param(param,value);
85 RadialBlur::get_param(const String ¶m)const
94 return Layer_Composite::get_param(param);
98 RadialBlur::get_param_vocab()const
100 Layer::Vocab ret(Layer_Composite::get_param_vocab());
102 ret.push_back(ParamDesc("origin")
103 .set_local_name(_("Origin"))
104 .set_description(_("Point where you want the origin to be"))
107 ret.push_back(ParamDesc("size")
108 .set_local_name(_("Size"))
109 .set_description(_("Size of blur"))
110 .set_origin("origin")
113 ret.push_back(ParamDesc("fade_out")
114 .set_local_name(_("Fade Out"))
121 RadialBlur::get_color(Context context, const Point &p)const
124 return context.get_color(p);
128 RadialBlur::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
130 if(cb && !cb->amount_complete(0,10000))
135 if(!context.accelerated_render(surface,quality,renddesc,cb))
138 tmp_surface=*surface;
142 const Point tl(renddesc.get_tl());
144 const int w(surface->get_w());
145 const int h(surface->get_h());
146 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
148 Surface::alpha_pen apen(surface->begin());
150 apen.set_alpha(get_amount());
151 apen.set_blend_method(get_blend_method());
155 if(quality>=9)steps=20;
156 else if(quality>=5)steps=30;
157 else if(quality>=4)steps=60;
158 else if(quality>=3)steps=100;
161 Surface::value_prep_type cooker;
163 for(y=0,pos[1]=tl[1];y<h;y++,apen.inc_y(),apen.dec_x(x),pos[1]+=ph)
164 for(x=0,pos[0]=tl[0];x<w;x++,apen.inc_x(),pos[0]+=pw)
168 end((pos-origin)*(1.0f-size)+origin-tl);
169 begin[0]/=pw;begin[1]/=ph;
170 end[0]/=pw;end[1]/=ph;
172 Color pool(Color::alpha());
175 int x0(round_to_int(begin[0])),
176 y0(round_to_int(begin[1])),
177 x1(round_to_int(end[0])),
178 y1(round_to_int(end[1]));
182 int sx, sy; /* step positive or negative (1 or -1) */
183 int dx, dy; /* delta (difference in X and Y between points) */
185 int w(tmp_surface.get_w()),h(tmp_surface.get_h());
188 sx = ((x1 - x0) > 0) ? 1 : -1;
190 sy = ((y1 - y0) > 0) ? 1 : -1;
200 for (i = 0; i < dx; i++)
202 if(y0>=0 && x0>=0 && y0<h && x0<w)
207 pool+=cooker.cook(tmp_surface[y0][x0])*(i-dx);
209 pool+=cooker.cook(tmp_surface[x0][y0])*(i-dx);
215 pool+=cooker.cook(tmp_surface[y0][x0]);
217 pool+=cooker.cook(tmp_surface[x0][y0]);
233 apen.put_value(cooker.uncook(pool));
238 end=(pos-origin)*(1.0f-size)+origin;
240 Color pool(Color::alpha());
243 int steps(steps*size);
244 for(f=0,i=0;i<steps;i++,f+=1.0f/(steps-1))
246 Point loc((end-begin)*f+begin-tl);
247 loc[0]/=pw;loc[1]/=ph;
250 pool+=tmp_surface.linear_sample(loc[0],loc[1])*(i-steps),poolsize+=(i-steps);
252 pool+=tmp_surface.linear_sample(loc[0],loc[1]),poolsize+=1;
255 apen.put_value(pool);
260 if(cb && !cb->amount_complete(10000,10000)) return false;