1 /* === S Y N F I G ========================================================= */
2 /*! \file supersample.cpp
3 ** \brief Implementation of the "Super Sample" layer
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 "supersample.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>
44 #include <synfig/target.h>
45 #include <synfig/render.h>
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 SYNFIG_LAYER_INIT(SuperSample);
54 SYNFIG_LAYER_SET_NAME(SuperSample,"super_sample");
55 SYNFIG_LAYER_SET_LOCAL_NAME(SuperSample,N_("Super Sample"));
56 SYNFIG_LAYER_SET_CATEGORY(SuperSample,N_("Other"));
57 SYNFIG_LAYER_SET_VERSION(SuperSample,"0.1");
58 SYNFIG_LAYER_SET_CVS_ID(SuperSample,"$Id$");
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
64 SuperSample::SuperSample():width(2),height(2)
71 SuperSample::set_param(const String & param, const ValueBase &value)
83 SuperSample::get_param(const String& param)const
97 SuperSample::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
99 // don't bother supersampling if our quality is too low.
101 return context.accelerated_render(surface,quality,renddesc,cb);
103 RendDesc desc(renddesc);
105 SuperCallback subcb(cb,1,9000,10000);
106 SuperCallback stagetwo(cb,9000,10000,10000);
109 desc.set_wh(desc.get_w()*width,desc.get_h()*height);
116 handle<Target> target=surface_target(&tempsurface);
119 if(cb)cb->error(_("Unable to create SurfaceTarget"));
122 target->set_rend_desc(&desc);
124 if(!render(context-1,target,desc,&subcb))
126 if(cb)cb->error(strprintf(__FILE__"%d: Scanline Renderer Failure",__LINE__));
131 if(!context.accelerated_render(&tempsurface,quality,desc,cb))
133 //if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
137 surface->set_wh(renddesc.get_w(),renddesc.get_h());
139 Surface::pen pen(surface->begin());
140 Surface::pen temp_pen(tempsurface.begin());
142 if(cb && !cb->amount_complete(9001,10000)) return false;
149 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))
151 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
156 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
157 for(u=0;u<width;u++,temp_pen.inc_x())
159 pool+=temp_pen.get_value()*temp_pen.get_value().get_a();
160 sum+=temp_pen.get_value().get_a();
167 pool.set_a(sum/float(width*height));
171 pen.put_value(Color::alpha());
175 if(!stagetwo.amount_complete(y,surface->get_h()))
184 float multiplier=1.0f/float(width*height);
185 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))
187 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
190 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
191 for(u=0;u<width;u++,temp_pen.inc_x())
192 pool+=temp_pen.get_value();
194 pen.put_value(pool*multiplier);
198 if(!stagetwo.amount_complete(y,surface->get_h()))
204 if(cb && !cb->amount_complete(10000,10000)) return false;
210 SuperSample::get_param_vocab(void)const
214 ret.push_back(ParamDesc("width")
215 .set_local_name(_("Width"))
216 .set_description(_("Width of sample area (In pixels)"))
218 ret.push_back(ParamDesc("height")
219 .set_local_name(_("Height"))
220 .set_description(_("Height of sample area (In pixels)"))
222 ret.push_back(ParamDesc("scanline")
223 .set_local_name(_("Use Parametric"))
224 .set_description(_("Use the Parametric Renderer"))
226 ret.push_back(ParamDesc("alpha_aware")
227 .set_local_name(_("Be Alpha Safe"))
234 SuperSample::get_bounding_rect(Context context)const
236 return context.get_full_bounding_rect();