1 /* === S I N F G =========================================================== */
3 ** \brief Template Header
5 ** $Id: clamp.cpp,v 1.2 2005/01/24 05:00:18 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
32 #include <sinfg/string.h>
33 #include <sinfg/time.h>
34 #include <sinfg/context.h>
35 #include <sinfg/paramdesc.h>
36 #include <sinfg/renddesc.h>
37 #include <sinfg/surface.h>
38 #include <sinfg/value.h>
39 #include <sinfg/valuenode.h>
43 /* === U S I N G =========================================================== */
47 using namespace sinfg;
49 /* === G L O B A L S ======================================================= */
51 SINFG_LAYER_INIT(Layer_Clamp);
52 SINFG_LAYER_SET_NAME(Layer_Clamp,"clamp");
53 SINFG_LAYER_SET_LOCAL_NAME(Layer_Clamp,_("Clamp"));
54 SINFG_LAYER_SET_CATEGORY(Layer_Clamp,_("Filters"));
55 SINFG_LAYER_SET_VERSION(Layer_Clamp,"0.2");
56 SINFG_LAYER_SET_CVS_ID(Layer_Clamp,"$Id: clamp.cpp,v 1.2 2005/01/24 05:00:18 darco Exp $");
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 /* === E N T R Y P O I N T ================================================= */
64 Layer_Clamp::Layer_Clamp():
65 invert_negative(false),
73 Layer_Clamp::clamp_color(const Color &in)const
78 return Color::alpha();
87 ret.set_g(ret.get_g()-ret.get_r());
88 ret.set_b(ret.get_b()-ret.get_r());
93 ret.set_r(ret.get_r()-ret.get_g());
94 ret.set_b(ret.get_b()-ret.get_g());
99 ret.set_g(ret.get_g()-ret.get_b());
100 ret.set_r(ret.get_r()-ret.get_b());
106 if(ret.get_r()<floor) ret.set_r(floor);
107 if(ret.get_g()<floor) ret.set_g(floor);
108 if(ret.get_b()<floor) ret.set_b(floor);
109 if(ret.get_a()<floor) ret.set_a(floor);
114 if(ret.get_r()>ceiling) ret.set_r(ceiling);
115 if(ret.get_g()>ceiling) ret.set_g(ceiling);
116 if(ret.get_b()>ceiling) ret.set_b(ceiling);
117 if(ret.get_a()>ceiling) ret.set_a(ceiling);
123 Layer_Clamp::set_param(const String & param, const ValueBase &value)
125 IMPORT(invert_negative);
126 IMPORT(clamp_ceiling);
134 Layer_Clamp::get_param(const String ¶m)const
136 EXPORT(invert_negative);
137 EXPORT(clamp_ceiling);
149 Layer_Clamp::get_param_vocab()const
153 ret.push_back(ParamDesc("invert_negative")
154 .set_local_name(_("Invert Negative"))
157 ret.push_back(ParamDesc("clamp_ceiling")
158 .set_local_name(_("Clamp Ceiling"))
161 ret.push_back(ParamDesc("ceiling")
162 .set_local_name(_("Ceiling"))
165 ret.push_back(ParamDesc("floor")
166 .set_local_name(_("Floor"))
173 Layer_Clamp::get_color(Context context, const Point &pos)const
175 return clamp_color(context.get_color(pos));
179 Layer_Clamp::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
181 SuperCallback supercb(cb,0,9500,10000);
183 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
188 Surface::pen pen(surface->begin());
190 for(y=0;y<renddesc.get_h();y++,pen.inc_y(),pen.dec_x(x))
191 for(x=0;x<renddesc.get_w();x++,pen.inc_x())
192 pen.put_value(clamp_color(pen.get_value()));
194 // Mark our progress as finished
195 if(cb && !cb->amount_complete(10000,10000))
203 Layer_Clamp::get_full_bounding_rect(Context context)const
205 return context.get_full_bounding_rect();