3 #include "colorcurve.h"
14 ColorCurve::ColorCurve():
15 shprog("colorcurve.glsl"),
16 quad(get_fullscreen_quad())
18 shdata.uniform("source", 0);
19 shdata.uniform("curve", 1);
21 curve.storage(LUMINANCE, 256, 1);
22 curve.set_min_filter(LINEAR);
23 curve.set_wrap(CLAMP_TO_EDGE);
24 texturing.attach(1, curve);
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_peak(float)
48 void ColorCurve::set_brightness(float b)
50 set_brightness_response(1/b);
53 void ColorCurve::set_gamma(float g)
56 throw invalid_argument("ColorCurve::set_gamma");
58 unsigned char curve_data[256];
59 for(unsigned i=0; i<256; ++i)
60 curve_data[i] = pow(i/255.0f, 1/g)*255+0.5f;
61 curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
64 void ColorCurve::set_srgb()
66 unsigned char curve_data[256];
68 for(unsigned i=1; i<256; ++i)
69 curve_data[i] = to_srgb(i/255.0f)*255+0.5f;
70 curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
73 void ColorCurve::set_linear()
75 unsigned char curve_data[256];
76 for(unsigned i=0; i<256; ++i)
78 curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
81 void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &)
83 texturing.attach(0, color_buf);
85 Renderer::Push push(renderer);
86 renderer.set_shader_program(&shprog, &shdata);
87 renderer.set_texturing(&texturing);
92 ColorCurve::Template::Template():
93 exposure_adjust(0.0f),
94 brightness_response(0.4f),
99 ColorCurve *ColorCurve::Template::create(unsigned, unsigned) const
101 RefPtr<ColorCurve> colorcurve = new ColorCurve;
102 colorcurve->set_exposure_adjust(exposure_adjust);
103 colorcurve->set_brightness_response(brightness_response);
105 colorcurve->set_srgb();
107 colorcurve->set_gamma(gamma);
108 return colorcurve.release();
112 ColorCurve::Template::Loader::Loader(Template &t):
113 DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>(t)
115 add("brightness_response", &Template::brightness_response);
116 add("exposure_adjust", &Template::exposure_adjust);
117 add("gamma", &Loader::gamma);
118 add("srgb", &Loader::srgb);
121 void ColorCurve::Template::Loader::gamma(float g)
127 void ColorCurve::Template::Loader::srgb()