]> git.sesse.net Git - movit/blobdiff - gamma_expansion_effect.cpp
Fix an issue where the last pass would have been rendered with the sRGB flag set...
[movit] / gamma_expansion_effect.cpp
index bfccaa04b925a3aacd6d359a8b9680a2d1899373..63b4c51309b9b11fdb028f9b037ba3b045013397 100644 (file)
@@ -1,17 +1,23 @@
-#include <math.h>
 #include <assert.h>
 
 #include "effect_util.h"
 #include "gamma_expansion_effect.h"
 #include "util.h"
 
+using namespace std;
+
+namespace movit {
+
 GammaExpansionEffect::GammaExpansionEffect()
        : source_curve(GAMMA_LINEAR)
 {
        register_int("source_curve", (int *)&source_curve);
+       register_uniform_float("linear_scale", &uniform_linear_scale);
+       register_uniform_float_array("c", uniform_c, 5);
+       register_uniform_float("beta", &uniform_beta);
 }
 
-std::string GammaExpansionEffect::output_fragment_shader()
+string GammaExpansionEffect::output_fragment_shader()
 {
        if (source_curve == GAMMA_LINEAR) {
                return read_file("identity.frag");
@@ -24,7 +30,7 @@ std::string GammaExpansionEffect::output_fragment_shader()
        assert(false);
 }
 
-void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
+void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
 {
        Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
 
@@ -37,7 +43,7 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const std::stri
        // However, pow() is relatively slow in GLSL, so we approximate this
        // part by a minimax polynomial, whose coefficients are precalculated
        // in Maple. (It is very hard to accurately model the curve as a whole
-       // using minimax polynomials; both Maple and Mathematically generally
+       // using minimax polynomials; both Maple and Mathematica generally
        // just error out if you ask them to optimize over 0..1 with a higher-degree
        // polynomial.)
        //
@@ -77,13 +83,13 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const std::stri
                //
                // Note that the worst _relative_ error by far is just at the beginning
                // of the exponential curve, ie., just around β.
-               set_uniform_float(glsl_program_num, prefix, "linear_scale", 1.0 / 12.92);
-               set_uniform_float(glsl_program_num, prefix, "c0", 0.001324469581);
-               set_uniform_float(glsl_program_num, prefix, "c1", 0.02227416690);
-               set_uniform_float(glsl_program_num, prefix, "c2", 0.5917615253);
-               set_uniform_float(glsl_program_num, prefix, "c3", 0.4733532353);
-               set_uniform_float(glsl_program_num, prefix, "c4", -0.08880738120);
-               set_uniform_float(glsl_program_num, prefix, "beta", 0.04045);
+               uniform_linear_scale = 1.0 / 12.92;
+               uniform_c[0] = 0.001324469581;
+               uniform_c[1] = 0.02227416690;
+               uniform_c[2] = 0.5917615253;
+               uniform_c[3] = 0.4733532353;
+               uniform_c[4] = -0.08880738120;
+               uniform_beta = 0.04045;
        }
        if (source_curve == GAMMA_REC_709) {  // Also includes Rec. 601, and 10-bit Rec. 2020.
                // Rec. 2020, page 3; ɑ = 1.099, β = 0.018 * 4.5, ɣ = 1/0.45.
@@ -94,13 +100,13 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const std::stri
                // Note that Rec. 2020 only gives the other direction, which is why
                // our beta and gamma are different from the numbers mentioned
                // (we've inverted the formula).
-               set_uniform_float(glsl_program_num, prefix, "linear_scale", 1.0 / 4.5);
-               set_uniform_float(glsl_program_num, prefix, "c0", 0.005137028744);
-               set_uniform_float(glsl_program_num, prefix, "c1", 0.09802596889);
-               set_uniform_float(glsl_program_num, prefix, "c2", 0.7255768864);
-               set_uniform_float(glsl_program_num, prefix, "c3", 0.2135067966);
-               set_uniform_float(glsl_program_num, prefix, "c4", -0.04225094667);
-               set_uniform_float(glsl_program_num, prefix, "beta", 0.018 * 4.5);
+               uniform_linear_scale = 1.0 / 4.5;
+               uniform_c[0] = 0.005137028744;
+               uniform_c[1] = 0.09802596889;
+               uniform_c[2] = 0.7255768864;
+               uniform_c[3] = 0.2135067966;
+               uniform_c[4] = -0.04225094667;
+               uniform_beta = 0.018 * 4.5;
        }
        if (source_curve == GAMMA_REC_2020_12_BIT) {
                // Rec. 2020, page 3; ɑ = 1.0993, β = 0.0181 * 4.5, ɣ = 1/0.45.
@@ -111,12 +117,14 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const std::stri
                // Note that Rec. 2020 only gives the other direction, which is why
                // our beta and gamma are different from the numbers mentioned
                // (we've inverted the formula).
-               set_uniform_float(glsl_program_num, prefix, "linear_scale", 1.0 / 4.5);
-               set_uniform_float(glsl_program_num, prefix, "c0", 0.005167545928);
-               set_uniform_float(glsl_program_num, prefix, "c1", 0.09835585809);
-               set_uniform_float(glsl_program_num, prefix, "c2", 0.7254820139);
-               set_uniform_float(glsl_program_num, prefix, "c3", 0.2131291155);
-               set_uniform_float(glsl_program_num, prefix, "c4", -0.04213877222);
-               set_uniform_float(glsl_program_num, prefix, "beta", 0.0181 * 4.5);
+               uniform_linear_scale = 1.0 / 4.5;
+               uniform_c[0] = 0.005167545928;
+               uniform_c[1] = 0.09835585809;
+               uniform_c[2] = 0.7254820139;
+               uniform_c[3] = 0.2131291155;
+               uniform_c[4] = -0.04213877222;
+               uniform_beta = 0.0181 * 4.5;
        }
 }
+
+}  // namespace movit