1 /*! ========================================================================
4 ** $Id: supersample.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
30 #include "supersample.h"
31 #include <synfig/string.h>
32 #include <synfig/time.h>
33 #include <synfig/context.h>
34 #include <synfig/paramdesc.h>
35 #include <synfig/renddesc.h>
36 #include <synfig/surface.h>
37 #include <synfig/value.h>
38 #include <synfig/valuenode.h>
40 #include <synfig/target.h>
41 #include <synfig/render.h>
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_LAYER_INIT(SuperSample);
50 SYNFIG_LAYER_SET_NAME(SuperSample,"super_sample");
51 SYNFIG_LAYER_SET_LOCAL_NAME(SuperSample,_("Super Sample"));
52 SYNFIG_LAYER_SET_CATEGORY(SuperSample,_("Other"));
53 SYNFIG_LAYER_SET_VERSION(SuperSample,"0.1");
54 SYNFIG_LAYER_SET_CVS_ID(SuperSample,"$Id: supersample.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 SuperSample::SuperSample():width(2),height(2)
67 SuperSample::set_param(const String & param, const ValueBase &value)
79 SuperSample::get_param(const String& param)const
93 SuperSample::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
95 // don't bother supersampling if our quality is too low.
97 return context.accelerated_render(surface,quality,renddesc,cb);
99 RendDesc desc(renddesc);
101 SuperCallback subcb(cb,1,9000,10000);
102 SuperCallback stagetwo(cb,9000,10000,10000);
105 desc.set_wh(desc.get_w()*width,desc.get_h()*height);
112 handle<Target> target=surface_target(&tempsurface);
115 if(cb)cb->error(_("Unable to create SurfaceTarget"));
118 target->set_rend_desc(&desc);
120 if(!render(context-1,target,desc,&subcb))
122 if(cb)cb->error(strprintf(__FILE__"%d: Scanline Renderer Failure",__LINE__));
127 if(!context.accelerated_render(&tempsurface,quality,desc,cb))
129 //if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
133 surface->set_wh(renddesc.get_w(),renddesc.get_h());
135 Surface::pen pen(surface->begin());
136 Surface::pen temp_pen(tempsurface.begin());
138 if(cb && !cb->amount_complete(9001,10000)) return false;
145 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))
147 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
152 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
153 for(u=0;u<width;u++,temp_pen.inc_x())
155 pool+=temp_pen.get_value()*temp_pen.get_value().get_a();
156 sum+=temp_pen.get_value().get_a();
163 pool.set_a(sum/float(width*height));
167 pen.put_value(Color::alpha());
171 if(!stagetwo.amount_complete(y,surface->get_h()))
180 float multiplier=1.0f/float(width*height);
181 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))
183 for(x=0;x<surface->get_w();x++,pen.inc_x(),temp_pen.inc_x(width))
186 for(v=0;v<height;v++,temp_pen.inc_y(),temp_pen.dec_x(u))
187 for(u=0;u<width;u++,temp_pen.inc_x())
188 pool+=temp_pen.get_value();
190 pen.put_value(pool*multiplier);
194 if(!stagetwo.amount_complete(y,surface->get_h()))
200 if(cb && !cb->amount_complete(10000,10000)) return false;
206 SuperSample::get_param_vocab(void)const
210 ret.push_back(ParamDesc("width")
211 .set_local_name(_("Width"))
212 .set_description(_("Width of sample area (In pixels)"))
214 ret.push_back(ParamDesc("height")
215 .set_local_name(_("Height"))
216 .set_description(_("Height of sample area (In pixels)"))
218 ret.push_back(ParamDesc("scanline")
219 .set_local_name(_("Use Parametric"))
220 .set_description(_("Use the Parametric Renderer"))
222 ret.push_back(ParamDesc("alpha_aware")
223 .set_local_name(_("Be Alpha Safe"))
230 SuperSample::get_bounding_rect(Context context)const
232 return context.get_full_bounding_rect();