1 /* === S I N F G =========================================================== */
2 /*! \file colorcorrect.cpp
3 ** \brief Template Header
5 ** $Id: colorcorrect.cpp,v 1.3 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 ======================================================= */
31 #include "colorcorrect.h"
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_ColorCorrect);
52 SINFG_LAYER_SET_NAME(Layer_ColorCorrect,"colorcorrect");
53 SINFG_LAYER_SET_LOCAL_NAME(Layer_ColorCorrect,_("Color Correct"));
54 SINFG_LAYER_SET_CATEGORY(Layer_ColorCorrect,_("Filters"));
55 SINFG_LAYER_SET_VERSION(Layer_ColorCorrect,"0.1");
56 SINFG_LAYER_SET_CVS_ID(Layer_ColorCorrect,"$Id: colorcorrect.cpp,v 1.3 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_ColorCorrect::Layer_ColorCorrect():
65 hue_adjust(Angle::zero()),
73 Layer_ColorCorrect::correct_color(const Color &in)const
76 Real brightness((this->brightness-0.5)*this->contrast+0.5);
78 if(gamma.get_gamma_r()!=1.0)
82 ret.set_r(-gamma.r_F32_to_F32(-ret.get_r()));
85 ret.set_r(gamma.r_F32_to_F32(ret.get_r()));
88 if(gamma.get_gamma_g()!=1.0)
92 ret.set_g(-gamma.g_F32_to_F32(-ret.get_g()));
95 ret.set_g(gamma.g_F32_to_F32(ret.get_g()));
98 if(gamma.get_gamma_b()!=1.0)
102 ret.set_b(-gamma.b_F32_to_F32(-ret.get_b()));
105 ret.set_b(gamma.b_F32_to_F32(ret.get_b()));
109 assert(!isnan(ret.get_r()));
110 assert(!isnan(ret.get_g()));
111 assert(!isnan(ret.get_b()));
115 const float factor(exp(exposure));
116 ret.set_r(ret.get_r()*factor);
117 ret.set_g(ret.get_g()*factor);
118 ret.set_b(ret.get_b()*factor);
124 ret.set_r(ret.get_r()*contrast);
125 ret.set_g(ret.get_g()*contrast);
126 ret.set_b(ret.get_b()*contrast);
131 // Adjust R Channel Brightness
132 if(ret.get_r()>-brightness)
133 ret.set_r(ret.get_r()+brightness);
134 else if(ret.get_r()<brightness)
135 ret.set_r(ret.get_r()-brightness);
139 // Adjust G Channel Brightness
140 if(ret.get_g()>-brightness)
141 ret.set_g(ret.get_g()+brightness);
142 else if(ret.get_g()<brightness)
143 ret.set_g(ret.get_g()-brightness);
147 // Adjust B Channel Brightness
148 if(ret.get_b()>-brightness)
149 ret.set_b(ret.get_b()+brightness);
150 else if(ret.get_b()<brightness)
151 ret.set_b(ret.get_b()-brightness);
156 // Return the color, adjusting the hue if necessary
158 return ret.rotate_uv(hue_adjust);
164 Layer_ColorCorrect::set_param(const String & param, const ValueBase &value)
171 if(param=="gamma" && value.get_type()==ValueBase::TYPE_REAL)
173 gamma.set_gamma(1.0/value.get(Real()));
180 Layer_ColorCorrect::get_param(const String ¶m)const
188 return 1.0/gamma.get_gamma();
197 Layer_ColorCorrect::get_param_vocab()const
201 ret.push_back(ParamDesc("hue_adjust")
202 .set_local_name(_("Hue Adjust"))
205 ret.push_back(ParamDesc("brightness")
206 .set_local_name(_("Brightness"))
209 ret.push_back(ParamDesc("contrast")
210 .set_local_name(_("Contrast"))
213 ret.push_back(ParamDesc("exposure")
214 .set_local_name(_("Exposure Adjust"))
217 ret.push_back(ParamDesc("gamma")
218 .set_local_name(_("Gamma Adjustment"))
225 Layer_ColorCorrect::get_color(Context context, const Point &pos)const
227 return correct_color(context.get_color(pos));
231 Layer_ColorCorrect::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
233 SuperCallback supercb(cb,0,9500,10000);
235 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
240 Surface::pen pen(surface->begin());
242 for(y=0;y<renddesc.get_h();y++,pen.inc_y(),pen.dec_x(x))
243 for(x=0;x<renddesc.get_w();x++,pen.inc_x())
244 pen.put_value(correct_color(pen.get_value()));
246 // Mark our progress as finished
247 if(cb && !cb->amount_complete(10000,10000))
254 Layer_ColorCorrect::get_full_bounding_rect(Context context)const
256 return context.get_full_bounding_rect();