1 /* === S Y N F I G ========================================================= */
2 /*! \file layer_motionblur.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 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
33 #include "layer_motionblur.h"
36 #include "paramdesc.h"
40 #include "valuenode.h"
45 /* === U S I N G =========================================================== */
47 using namespace synfig;
51 /* === G L O B A L S ======================================================= */
53 SYNFIG_LAYER_INIT(Layer_MotionBlur);
54 SYNFIG_LAYER_SET_NAME(Layer_MotionBlur,"MotionBlur");
55 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_MotionBlur,_("Motion Blur"));
56 SYNFIG_LAYER_SET_CATEGORY(Layer_MotionBlur,_("Blurs"));
57 SYNFIG_LAYER_SET_VERSION(Layer_MotionBlur,"0.1");
58 SYNFIG_LAYER_SET_CVS_ID(Layer_MotionBlur,"$Id$");
60 /* === M E M B E R S ======================================================= */
62 Layer_MotionBlur::Layer_MotionBlur():
63 Layer_Composite (1.0,Color::BLEND_STRAIGHT),
69 Layer_MotionBlur::set_param(const String ¶m, const ValueBase &value)
73 return Layer_Composite::set_param(param,value);
77 Layer_MotionBlur::get_param(const String ¶m)const
84 return Layer_Composite::get_param(param);
88 Layer_MotionBlur::set_time(Context context, Time time)const
90 context.set_time(time);
95 Layer_MotionBlur::set_time(Context context, Time time, const Point &pos)const
97 context.set_time(time,pos);
102 Layer_MotionBlur::get_color(Context context, const Point &pos)const
107 time+=(Vector::value_type)( (signed)(RAND_MAX/2)-(signed)rand() )/(Vector::value_type)(RAND_MAX) *aperture -aperture*0.5;
108 context.set_time(time, pos);
111 return context.get_color(pos);
115 Layer_MotionBlur::get_param_vocab()const
118 //ret=Layer_Composite::get_param_vocab();
120 ret.push_back(ParamDesc("aperture")
121 .set_local_name(_("Aperture"))
122 .set_description(_("Shutter Time"))
129 Layer_MotionBlur::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
131 if(aperture && quality<10)
134 SuperCallback subimagecb;
138 case 1: // Production Quality
141 case 2: // Excellent Quality
144 case 3: // Good Quality
147 case 4: // Moderate Quality
150 case 5: // Draft Quality
165 case 10: // Rough Quality
175 surface->set_wh(renddesc.get_w(),renddesc.get_h());
178 for(i=0;i<samples;i++)
180 subimagecb=SuperCallback(cb,i*(5000/samples),(i+1)*(5000/samples),5000);
181 context.set_time(time_cur+(aperture/samples)*i-aperture*0.5);
182 if(!context.accelerated_render(&tmp,quality,renddesc,&subimagecb))
184 for(int y=0;y<renddesc.get_h();y++)
185 for(int x=0;x<renddesc.get_w();x++)
186 (*surface)[y][x]+=tmp[y][x].premult_alpha();
188 for(int y=0;y<renddesc.get_h();y++)
189 for(int x=0;x<renddesc.get_w();x++)
190 (*surface)[y][x]=((*surface)[y][x]/(float)samples).demult_alpha();
193 return context.accelerated_render(surface,quality,renddesc,cb);