3 #include "colorcurve.h"
15 ColorCurve::ColorCurve(Resources &resources):
16 shprog(resources.get<Program>("_colorcurve.glsl")),
17 quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
18 linear_sampler(resources.get<Sampler>("_linear_clamp.samp")),
19 nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp"))
21 shdata.uniform("source", 0);
22 shdata.uniform("curve", 1);
24 curve.storage(LUMINANCE8, 256, 1);
25 texturing.attach(1, curve, &linear_sampler);
27 set_exposure_adjust(0.0f);
28 set_brightness_response(0.4f);
32 void ColorCurve::set_exposure_adjust(float e)
34 shdata.uniform("exposure", pow(2.0f, e));
37 void ColorCurve::set_brightness_response(float b)
40 throw invalid_argument("ColorCurve::set_brightness_response");
41 float t = (b<1 ? pow(b, 1/(1-b)) : 0.0f);
42 shdata.uniform("brightness_response", b, t, pow(t, b));
45 void ColorCurve::set_gamma(float g)
48 throw invalid_argument("ColorCurve::set_gamma");
50 unsigned char curve_data[256];
51 for(unsigned i=0; i<256; ++i)
52 curve_data[i] = pow(i/255.0f, 1/g)*255+0.5f;
53 curve.image(0, curve_data);
56 void ColorCurve::set_srgb()
58 unsigned char curve_data[256];
60 for(unsigned i=1; i<256; ++i)
61 curve_data[i] = to_srgb(i/255.0f)*255+0.5f;
62 curve.image(0, curve_data);
65 void ColorCurve::set_linear()
67 unsigned char curve_data[256];
68 for(unsigned i=0; i<256; ++i)
70 curve.image(0, curve_data);
73 void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &)
75 texturing.attach(0, color_buf, &nearest_sampler);
77 Renderer::Push push(renderer);
78 renderer.set_shader_program(&shprog, &shdata);
79 renderer.set_texturing(&texturing);
84 ColorCurve::Template::Template():
85 exposure_adjust(0.0f),
86 brightness_response(0.4f),
91 ColorCurve *ColorCurve::Template::create(Resources &res, unsigned, unsigned) const
93 RefPtr<ColorCurve> colorcurve = new ColorCurve(res);
94 colorcurve->set_exposure_adjust(exposure_adjust);
95 colorcurve->set_brightness_response(brightness_response);
97 colorcurve->set_srgb();
99 colorcurve->set_gamma(gamma);
100 return colorcurve.release();
104 ColorCurve::Template::Loader::Loader(Template &t):
105 DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>(t)
107 add("brightness_response", &Template::brightness_response);
108 add("exposure_adjust", &Template::exposure_adjust);
109 add("gamma", &Loader::gamma);
110 add("srgb", &Loader::srgb);
113 void ColorCurve::Template::Loader::gamma(float g)
119 void ColorCurve::Template::Loader::srgb()