3 #include "colorcurve.h"
14 ColorCurve::ColorCurve():
15 shprog("colorcurve.glsl"),
16 quad(get_fullscreen_quad()),
17 linear_sampler(get_linear_sampler()),
18 nearest_sampler(get_nearest_sampler())
20 shdata.uniform("source", 0);
21 shdata.uniform("curve", 1);
23 curve.storage(LUMINANCE8, 256, 1);
24 texturing.attach(1, curve, linear_sampler.get());
26 set_exposure_adjust(0.0f);
27 set_brightness_response(0.4f);
31 void ColorCurve::set_exposure_adjust(float e)
33 shdata.uniform("exposure", pow(2.0f, e));
36 void ColorCurve::set_brightness_response(float b)
39 throw invalid_argument("ColorCurve::set_brightness_response");
40 float t = (b<1 ? pow(b, 1/(1-b)) : 0.0f);
41 shdata.uniform("brightness_response", b, t, pow(t, b));
44 void ColorCurve::set_gamma(float g)
47 throw invalid_argument("ColorCurve::set_gamma");
49 unsigned char curve_data[256];
50 for(unsigned i=0; i<256; ++i)
51 curve_data[i] = pow(i/255.0f, 1/g)*255+0.5f;
52 curve.image(0, curve_data);
55 void ColorCurve::set_srgb()
57 unsigned char curve_data[256];
59 for(unsigned i=1; i<256; ++i)
60 curve_data[i] = to_srgb(i/255.0f)*255+0.5f;
61 curve.image(0, curve_data);
64 void ColorCurve::set_linear()
66 unsigned char curve_data[256];
67 for(unsigned i=0; i<256; ++i)
69 curve.image(0, curve_data);
72 void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &)
74 texturing.attach(0, color_buf, nearest_sampler.get());
76 Renderer::Push push(renderer);
77 renderer.set_shader_program(&shprog, &shdata);
78 renderer.set_texturing(&texturing);
83 ColorCurve::Template::Template():
84 exposure_adjust(0.0f),
85 brightness_response(0.4f),
90 ColorCurve *ColorCurve::Template::create(unsigned, unsigned) const
92 RefPtr<ColorCurve> colorcurve = new ColorCurve;
93 colorcurve->set_exposure_adjust(exposure_adjust);
94 colorcurve->set_brightness_response(brightness_response);
96 colorcurve->set_srgb();
98 colorcurve->set_gamma(gamma);
99 return colorcurve.release();
103 ColorCurve::Template::Loader::Loader(Template &t):
104 DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>(t)
106 add("brightness_response", &Template::brightness_response);
107 add("exposure_adjust", &Template::exposure_adjust);
108 add("gamma", &Loader::gamma);
109 add("srgb", &Loader::srgb);
112 void ColorCurve::Template::Loader::gamma(float g)
118 void ColorCurve::Template::Loader::srgb()