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);
31 void ColorCurve::set_peak(float p)
34 throw invalid_argument("ColorCurve::set_peak");
35 shdata.uniform("peak", p);
38 void ColorCurve::set_brightness(float b)
41 throw invalid_argument("ColorCurve::set_brightness");
42 shdata.uniform("brightness", 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, LUMINANCE, UNSIGNED_BYTE, 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, LUMINANCE, UNSIGNED_BYTE, 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, LUMINANCE, UNSIGNED_BYTE, curve_data);
73 void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &)
75 texturing.attach(0, color_buf);
77 Renderer::Push push(renderer);
78 renderer.set_shader_program(&shprog, &shdata);
79 renderer.set_texturing(&texturing);