3 #include "colorcurve.h"
13 ColorCurve::ColorCurve():
14 shprog("colorcurve.glsl"),
15 quad(get_fullscreen_quad())
17 shdata.uniform("source", 0);
18 shdata.uniform("curve", 1);
20 curve.storage(LUMINANCE, 256);
21 curve.set_min_filter(LINEAR);
22 curve.set_wrap(CLAMP_TO_EDGE);
29 void ColorCurve::set_peak(float p)
32 throw invalid_argument("ColorCurve::set_peak");
33 shdata.uniform("peak", p);
36 void ColorCurve::set_brightness(float b)
39 throw invalid_argument("ColorCurve::set_brightness");
40 shdata.uniform("brightness", b);
43 void ColorCurve::set_gamma(float g)
46 throw invalid_argument("ColorCurve::set_gamma");
48 unsigned char curve_data[256];
49 for(unsigned i=0; i<256; ++i)
50 curve_data[i] = pow(i/255.0f, 1/g)*255+0.5f;
51 curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
54 void ColorCurve::set_srgb()
56 unsigned char curve_data[256];
58 for(unsigned i=1; i<256; ++i)
59 curve_data[i] = to_srgb(i/255.0f)*255+0.5f;
60 curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
63 void ColorCurve::set_linear()
65 unsigned char curve_data[256];
66 for(unsigned i=0; i<256; ++i)
68 curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
71 void ColorCurve::render(const Texture2D &color_buf, const Texture2D &)
73 Bind _bind_shader(shprog);
75 Bind _bind_mesh(quad);
76 Bind _bind_tex(color_buf);
77 Bind _bind_curve(curve, 1);