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)
68 Layer::Vocab voc(get_param_vocab());
69 Layer::fill_static(voc);
73 SuperSample::set_param(const String & param, const ValueBase &value)
85 SuperSample::get_param(const String& param)const
99 SuperSample::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
101 // don't bother supersampling if our quality is too low.
103 return context.accelerated_render(surface,quality,renddesc,cb);
105 RendDesc desc(renddesc);
107 SuperCallback subcb(cb,1,9000,10000);
108 SuperCallback stagetwo(cb,9000,10000,10000);
111 desc.set_wh(desc.get_w()*width,desc.get_h()*height);
118 handle<Target> target=surface_target(&tempsurface);
121 if(cb)cb->error(_("Unable to create SurfaceTarget"));
124 target->set_rend_desc(&desc);
126 if(!render(context-1,target,desc,&subcb))
128 if(cb)cb->error(strprintf(__FILE__"%d: Scanline Renderer Failure",__LINE__));
133 if(!context.accelerated_render(&tempsurface,quality,desc,cb))
135 //if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
139 surface->set_wh(renddesc.get_w(),renddesc.get_h());
141 Surface::pen pen(surface->begin());
142 Surface::pen temp_pen(tempsurface.begin());
144 if(cb && !cb->amount_complete(9001,10000)) return false;
151 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))
153 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
158 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
159 for(u=0;u<width;u++,temp_pen.inc_x())
161 pool+=temp_pen.get_value()*temp_pen.get_value().get_a();
162 sum+=temp_pen.get_value().get_a();
169 pool.set_a(sum/float(width*height));
173 pen.put_value(Color::alpha());
177 if(!stagetwo.amount_complete(y,surface->get_h()))
186 float multiplier=1.0f/float(width*height);
187 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))
189 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
192 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
193 for(u=0;u<width;u++,temp_pen.inc_x())
194 pool+=temp_pen.get_value();
196 pen.put_value(pool*multiplier);
200 if(!stagetwo.amount_complete(y,surface->get_h()))
206 if(cb && !cb->amount_complete(10000,10000)) return false;
212 SuperSample::get_param_vocab(void)const
216 ret.push_back(ParamDesc("width")
217 .set_local_name(_("Width"))
218 .set_description(_("Width of sample area (In pixels)"))
220 ret.push_back(ParamDesc("height")
221 .set_local_name(_("Height"))
222 .set_description(_("Height of sample area (In pixels)"))
224 ret.push_back(ParamDesc("scanline")
225 .set_local_name(_("Use Parametric"))
226 .set_description(_("Use the Parametric Renderer"))
228 ret.push_back(ParamDesc("alpha_aware")
229 .set_local_name(_("Be Alpha Safe"))
236 SuperSample::get_bounding_rect(Context context)const
238 return context.get_full_bounding_rect();