5 #include "gamma_compression_effect.h"
8 GammaCompressionEffect::GammaCompressionEffect()
9 : destination_curve(GAMMA_LINEAR)
11 register_int("destination_curve", (int *)&destination_curve);
12 memset(compression_curve, 0, sizeof(compression_curve));
13 register_1d_texture("compression_curve_tex", compression_curve, COMPRESSION_CURVE_SIZE);
16 std::string GammaCompressionEffect::output_fragment_shader()
18 if (destination_curve == GAMMA_LINEAR) {
19 return read_file("identity.frag");
21 if (destination_curve == GAMMA_sRGB) {
22 for (unsigned i = 0; i < COMPRESSION_CURVE_SIZE; ++i) {
23 float x = i / (float)(COMPRESSION_CURVE_SIZE - 1);
25 compression_curve[i] = 12.92f * x;
27 compression_curve[i] = 1.055f * pow(x, 1.0f / 2.4f) - 0.055f;
30 invalidate_1d_texture("compression_curve_tex");
31 return read_file("gamma_compression_effect.frag");
33 if (destination_curve == GAMMA_REC_709) { // And Rec. 601.
34 for (unsigned i = 0; i < COMPRESSION_CURVE_SIZE; ++i) {
35 float x = i / (float)(COMPRESSION_CURVE_SIZE - 1);
37 compression_curve[i] = 4.5f * x;
39 compression_curve[i] = 1.099f * pow(x, 0.45f) - 0.099;
42 invalidate_1d_texture("compression_curve_tex");
43 return read_file("gamma_compression_effect.frag");