1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
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 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
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>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
50 /* === G L O B A L S ======================================================= */
52 SYNFIG_LAYER_INIT(Layer_Clamp);
53 SYNFIG_LAYER_SET_NAME(Layer_Clamp,"clamp");
54 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Clamp,N_("Clamp"));
55 SYNFIG_LAYER_SET_CATEGORY(Layer_Clamp,N_("Filters"));
56 SYNFIG_LAYER_SET_VERSION(Layer_Clamp,"0.2");
57 SYNFIG_LAYER_SET_CVS_ID(Layer_Clamp,"$Id$");
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 /* === E N T R Y P O I N T ================================================= */
65 Layer_Clamp::Layer_Clamp():
66 invert_negative(false),
74 Layer_Clamp::clamp_color(const Color &in)const
79 return Color::alpha();
88 ret.set_g(ret.get_g()-ret.get_r());
89 ret.set_b(ret.get_b()-ret.get_r());
94 ret.set_r(ret.get_r()-ret.get_g());
95 ret.set_b(ret.get_b()-ret.get_g());
100 ret.set_g(ret.get_g()-ret.get_b());
101 ret.set_r(ret.get_r()-ret.get_b());
107 if(ret.get_r()<floor) ret.set_r(floor);
108 if(ret.get_g()<floor) ret.set_g(floor);
109 if(ret.get_b()<floor) ret.set_b(floor);
110 if(ret.get_a()<floor) ret.set_a(floor);
115 if(ret.get_r()>ceiling) ret.set_r(ceiling);
116 if(ret.get_g()>ceiling) ret.set_g(ceiling);
117 if(ret.get_b()>ceiling) ret.set_b(ceiling);
118 if(ret.get_a()>ceiling) ret.set_a(ceiling);
124 Layer_Clamp::set_param(const String & param, const ValueBase &value)
126 IMPORT(invert_negative);
127 IMPORT(clamp_ceiling);
135 Layer_Clamp::get_param(const String ¶m)const
137 EXPORT(invert_negative);
138 EXPORT(clamp_ceiling);
150 Layer_Clamp::get_param_vocab()const
154 ret.push_back(ParamDesc("invert_negative")
155 .set_local_name(_("Invert Negative"))
158 ret.push_back(ParamDesc("clamp_ceiling")
159 .set_local_name(_("Clamp Ceiling"))
162 ret.push_back(ParamDesc("ceiling")
163 .set_local_name(_("Ceiling"))
166 ret.push_back(ParamDesc("floor")
167 .set_local_name(_("Floor"))
174 Layer_Clamp::get_color(Context context, const Point &pos)const
176 return clamp_color(context.get_color(pos));
180 Layer_Clamp::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
182 SuperCallback supercb(cb,0,9500,10000);
184 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
189 Surface::pen pen(surface->begin());
191 for(y=0;y<renddesc.get_h();y++,pen.inc_y(),pen.dec_x(x))
192 for(x=0;x<renddesc.get_w();x++,pen.inc_x())
193 pen.put_value(clamp_color(pen.get_value()));
195 // Mark our progress as finished
196 if(cb && !cb->amount_complete(10000,10000))
204 Layer_Clamp::get_full_bounding_rect(Context context)const
206 return context.get_full_bounding_rect();