1 /*! ========================================================================
4 ** $Id: radialblur.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
30 #include "radialblur.h"
31 #include <sinfg/string.h>
32 #include <sinfg/time.h>
33 #include <sinfg/context.h>
34 #include <sinfg/paramdesc.h>
35 #include <sinfg/renddesc.h>
36 #include <sinfg/surface.h>
37 #include <sinfg/value.h>
38 #include <sinfg/valuenode.h>
39 #include <sinfg/transform.h>
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
48 SINFG_LAYER_INIT(RadialBlur);
49 SINFG_LAYER_SET_NAME(RadialBlur,"radial_blur");
50 SINFG_LAYER_SET_LOCAL_NAME(RadialBlur,_("Radial Blur"));
51 SINFG_LAYER_SET_CATEGORY(RadialBlur,_("Blurs"));
52 SINFG_LAYER_SET_VERSION(RadialBlur,"0.1");
53 SINFG_LAYER_SET_CVS_ID(RadialBlur,"$Id: radialblur.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 /* === E N T R Y P O I N T ================================================= */
61 RadialBlur::RadialBlur():
68 RadialBlur::~RadialBlur()
73 RadialBlur::set_param(const String & param, const ValueBase &value)
79 return Layer_Composite::set_param(param,value);
83 RadialBlur::get_param(const String ¶m)const
92 return Layer_Composite::get_param(param);
96 RadialBlur::get_param_vocab()const
98 Layer::Vocab ret(Layer_Composite::get_param_vocab());
100 ret.push_back(ParamDesc("origin")
101 .set_local_name(_("Origin"))
102 .set_description(_("Point where you want the origin to be"))
105 ret.push_back(ParamDesc("size")
106 .set_local_name(_("Size"))
107 .set_description(_("Size of blur"))
108 .set_origin("origin")
111 ret.push_back(ParamDesc("fade_out")
112 .set_local_name(_("Fade Out"))
119 RadialBlur::get_color(Context context, const Point &p)const
122 return context.get_color(p);
126 RadialBlur::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
128 if(cb && !cb->amount_complete(0,10000))
133 if(!context.accelerated_render(surface,quality,renddesc,cb))
136 tmp_surface=*surface;
140 const Point tl(renddesc.get_tl());
142 const int w(surface->get_w());
143 const int h(surface->get_h());
144 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
146 Surface::alpha_pen apen(surface->begin());
148 apen.set_alpha(get_amount());
149 apen.set_blend_method(get_blend_method());
153 if(quality>=9)steps=20;
154 else if(quality>=5)steps=30;
155 else if(quality>=4)steps=60;
156 else if(quality>=3)steps=100;
159 Surface::value_prep_type cooker;
161 for(y=0,pos[1]=tl[1];y<h;y++,apen.inc_y(),apen.dec_x(x),pos[1]+=ph)
162 for(x=0,pos[0]=tl[0];x<w;x++,apen.inc_x(),pos[0]+=pw)
166 end((pos-origin)*(1.0f-size)+origin-tl);
167 begin[0]/=pw;begin[1]/=ph;
168 end[0]/=pw;end[1]/=ph;
170 Color pool(Color::alpha());
173 int x0(round_to_int(begin[0])),
174 y0(round_to_int(begin[1])),
175 x1(round_to_int(end[0])),
176 y1(round_to_int(end[1]));
180 int sx, sy; /* step positive or negative (1 or -1) */
181 int dx, dy; /* delta (difference in X and Y between points) */
183 int w(tmp_surface.get_w()),h(tmp_surface.get_h());
186 sx = ((x1 - x0) > 0) ? 1 : -1;
188 sy = ((y1 - y0) > 0) ? 1 : -1;
198 for (i = 0; i < dx; i++)
200 if(y0>=0 && x0>=0 && y0<h && x0<w)
205 pool+=cooker.cook(tmp_surface[y0][x0])*(i-dx);
207 pool+=cooker.cook(tmp_surface[x0][y0])*(i-dx);
213 pool+=cooker.cook(tmp_surface[y0][x0]);
215 pool+=cooker.cook(tmp_surface[x0][y0]);
231 apen.put_value(cooker.uncook(pool));
236 end=(pos-origin)*(1.0f-size)+origin;
238 Color pool(Color::alpha());
241 int steps(steps*size);
242 for(f=0,i=0;i<steps;i++,f+=1.0f/(steps-1))
244 Point loc((end-begin)*f+begin-tl);
245 loc[0]/=pw;loc[1]/=ph;
248 pool+=tmp_surface.linear_sample(loc[0],loc[1])*(i-steps),poolsize+=(i-steps);
250 pool+=tmp_surface.linear_sample(loc[0],loc[1]),poolsize+=1;
253 apen.put_value(pool);
258 if(cb && !cb->amount_complete(10000,10000)) return false;