1 /*! ========================================================================
4 ** $Id: supersample.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
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.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "supersample.h"
32 #include <synfig/string.h>
33 #include <synfig/time.h>
34 #include <synfig/context.h>
35 #include <synfig/paramdesc.h>
36 #include <synfig/renddesc.h>
37 #include <synfig/surface.h>
38 #include <synfig/value.h>
39 #include <synfig/valuenode.h>
41 #include <synfig/target.h>
42 #include <synfig/render.h>
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 SYNFIG_LAYER_INIT(SuperSample);
51 SYNFIG_LAYER_SET_NAME(SuperSample,"super_sample");
52 SYNFIG_LAYER_SET_LOCAL_NAME(SuperSample,_("Super Sample"));
53 SYNFIG_LAYER_SET_CATEGORY(SuperSample,_("Other"));
54 SYNFIG_LAYER_SET_VERSION(SuperSample,"0.1");
55 SYNFIG_LAYER_SET_CVS_ID(SuperSample,"$Id: supersample.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 SuperSample::SuperSample():width(2),height(2)
68 SuperSample::set_param(const String & param, const ValueBase &value)
80 SuperSample::get_param(const String& param)const
94 SuperSample::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
96 // don't bother supersampling if our quality is too low.
98 return context.accelerated_render(surface,quality,renddesc,cb);
100 RendDesc desc(renddesc);
102 SuperCallback subcb(cb,1,9000,10000);
103 SuperCallback stagetwo(cb,9000,10000,10000);
106 desc.set_wh(desc.get_w()*width,desc.get_h()*height);
113 handle<Target> target=surface_target(&tempsurface);
116 if(cb)cb->error(_("Unable to create SurfaceTarget"));
119 target->set_rend_desc(&desc);
121 if(!render(context-1,target,desc,&subcb))
123 if(cb)cb->error(strprintf(__FILE__"%d: Scanline Renderer Failure",__LINE__));
128 if(!context.accelerated_render(&tempsurface,quality,desc,cb))
130 //if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
134 surface->set_wh(renddesc.get_w(),renddesc.get_h());
136 Surface::pen pen(surface->begin());
137 Surface::pen temp_pen(tempsurface.begin());
139 if(cb && !cb->amount_complete(9001,10000)) return false;
146 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))
148 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
153 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
154 for(u=0;u<width;u++,temp_pen.inc_x())
156 pool+=temp_pen.get_value()*temp_pen.get_value().get_a();
157 sum+=temp_pen.get_value().get_a();
164 pool.set_a(sum/float(width*height));
168 pen.put_value(Color::alpha());
172 if(!stagetwo.amount_complete(y,surface->get_h()))
181 float multiplier=1.0f/float(width*height);
182 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))
184 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
187 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
188 for(u=0;u<width;u++,temp_pen.inc_x())
189 pool+=temp_pen.get_value();
191 pen.put_value(pool*multiplier);
195 if(!stagetwo.amount_complete(y,surface->get_h()))
201 if(cb && !cb->amount_complete(10000,10000)) return false;
207 SuperSample::get_param_vocab(void)const
211 ret.push_back(ParamDesc("width")
212 .set_local_name(_("Width"))
213 .set_description(_("Width of sample area (In pixels)"))
215 ret.push_back(ParamDesc("height")
216 .set_local_name(_("Height"))
217 .set_description(_("Height of sample area (In pixels)"))
219 ret.push_back(ParamDesc("scanline")
220 .set_local_name(_("Use Parametric"))
221 .set_description(_("Use the Parametric Renderer"))
223 ret.push_back(ParamDesc("alpha_aware")
224 .set_local_name(_("Be Alpha Safe"))
231 SuperSample::get_bounding_rect(Context context)const
233 return context.get_full_bounding_rect();