1 /* === S Y N F I G ========================================================= */
2 /*! \file supersample.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 "supersample.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>
42 #include <synfig/target.h>
43 #include <synfig/render.h>
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 SYNFIG_LAYER_INIT(SuperSample);
52 SYNFIG_LAYER_SET_NAME(SuperSample,"super_sample");
53 SYNFIG_LAYER_SET_LOCAL_NAME(SuperSample,_("Super Sample"));
54 SYNFIG_LAYER_SET_CATEGORY(SuperSample,_("Other"));
55 SYNFIG_LAYER_SET_VERSION(SuperSample,"0.1");
56 SYNFIG_LAYER_SET_CVS_ID(SuperSample,"$Id$");
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 SuperSample::SuperSample():width(2),height(2)
69 SuperSample::set_param(const String & param, const ValueBase &value)
81 SuperSample::get_param(const String& param)const
95 SuperSample::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
97 // don't bother supersampling if our quality is too low.
99 return context.accelerated_render(surface,quality,renddesc,cb);
101 RendDesc desc(renddesc);
103 SuperCallback subcb(cb,1,9000,10000);
104 SuperCallback stagetwo(cb,9000,10000,10000);
107 desc.set_wh(desc.get_w()*width,desc.get_h()*height);
114 handle<Target> target=surface_target(&tempsurface);
117 if(cb)cb->error(_("Unable to create SurfaceTarget"));
120 target->set_rend_desc(&desc);
122 if(!render(context-1,target,desc,&subcb))
124 if(cb)cb->error(strprintf(__FILE__"%d: Scanline Renderer Failure",__LINE__));
129 if(!context.accelerated_render(&tempsurface,quality,desc,cb))
131 //if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
135 surface->set_wh(renddesc.get_w(),renddesc.get_h());
137 Surface::pen pen(surface->begin());
138 Surface::pen temp_pen(tempsurface.begin());
140 if(cb && !cb->amount_complete(9001,10000)) return false;
147 for(y=0;y<surface->get_h();y++,pen.inc_y(),pen.dec_x(x),temp_pen.inc_y(height),temp_pen.dec_x(x*width))
149 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
154 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
155 for(u=0;u<width;u++,temp_pen.inc_x())
157 pool+=temp_pen.get_value()*temp_pen.get_value().get_a();
158 sum+=temp_pen.get_value().get_a();
165 pool.set_a(sum/float(width*height));
169 pen.put_value(Color::alpha());
173 if(!stagetwo.amount_complete(y,surface->get_h()))
182 float multiplier=1.0f/float(width*height);
183 for(y=0;y<surface->get_h();y++,pen.inc_y(),pen.dec_x(x),temp_pen.inc_y(height),temp_pen.dec_x(x*width))
185 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
188 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
189 for(u=0;u<width;u++,temp_pen.inc_x())
190 pool+=temp_pen.get_value();
192 pen.put_value(pool*multiplier);
196 if(!stagetwo.amount_complete(y,surface->get_h()))
202 if(cb && !cb->amount_complete(10000,10000)) return false;
208 SuperSample::get_param_vocab(void)const
212 ret.push_back(ParamDesc("width")
213 .set_local_name(_("Width"))
214 .set_description(_("Width of sample area (In pixels)"))
216 ret.push_back(ParamDesc("height")
217 .set_local_name(_("Height"))
218 .set_description(_("Height of sample area (In pixels)"))
220 ret.push_back(ParamDesc("scanline")
221 .set_local_name(_("Use Parametric"))
222 .set_description(_("Use the Parametric Renderer"))
224 ret.push_back(ParamDesc("alpha_aware")
225 .set_local_name(_("Be Alpha Safe"))
232 SuperSample::get_bounding_rect(Context context)const
234 return context.get_full_bounding_rect();