1 /* === S Y N F I G ========================================================= */
3 ** \brief Implementation of the "Clamp" 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 /* ========================================================================= */
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),
71 Layer::Vocab voc(get_param_vocab());
72 Layer::fill_static(voc);
76 Layer_Clamp::clamp_color(const Color &in)const
81 return Color::alpha();
90 ret.set_g(ret.get_g()-ret.get_r());
91 ret.set_b(ret.get_b()-ret.get_r());
96 ret.set_r(ret.get_r()-ret.get_g());
97 ret.set_b(ret.get_b()-ret.get_g());
100 if(ret.get_b()<floor)
102 ret.set_g(ret.get_g()-ret.get_b());
103 ret.set_r(ret.get_r()-ret.get_b());
109 if(ret.get_r()<floor) ret.set_r(floor);
110 if(ret.get_g()<floor) ret.set_g(floor);
111 if(ret.get_b()<floor) ret.set_b(floor);
112 if(ret.get_a()<floor) ret.set_a(floor);
117 if(ret.get_r()>ceiling) ret.set_r(ceiling);
118 if(ret.get_g()>ceiling) ret.set_g(ceiling);
119 if(ret.get_b()>ceiling) ret.set_b(ceiling);
120 if(ret.get_a()>ceiling) ret.set_a(ceiling);
126 Layer_Clamp::set_param(const String & param, const ValueBase &value)
128 IMPORT(invert_negative);
129 IMPORT(clamp_ceiling);
137 Layer_Clamp::get_param(const String ¶m)const
139 EXPORT(invert_negative);
140 EXPORT(clamp_ceiling);
152 Layer_Clamp::get_param_vocab()const
156 ret.push_back(ParamDesc("invert_negative")
157 .set_local_name(_("Invert Negative"))
160 ret.push_back(ParamDesc("clamp_ceiling")
161 .set_local_name(_("Clamp Ceiling"))
164 ret.push_back(ParamDesc("ceiling")
165 .set_local_name(_("Ceiling"))
168 ret.push_back(ParamDesc("floor")
169 .set_local_name(_("Floor"))
176 Layer_Clamp::get_color(Context context, const Point &pos)const
178 return clamp_color(context.get_color(pos));
182 Layer_Clamp::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
184 SuperCallback supercb(cb,0,9500,10000);
186 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
191 Surface::pen pen(surface->begin());
193 for(y=0;y<renddesc.get_h();y++,pen.inc_y(),pen.dec_x(x))
194 for(x=0;x<renddesc.get_w();x++,pen.inc_x())
195 pen.put_value(clamp_color(pen.get_value()));
197 // Mark our progress as finished
198 if(cb && !cb->amount_complete(10000,10000))
206 Layer_Clamp::get_full_bounding_rect(Context context)const
208 return context.get_full_bounding_rect();