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);
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);