Make gamma polynomial constants into an array; slightly fewer uniforms to set, and...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Feb 2016 13:11:35 +0000 (14:11 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Feb 2016 13:11:43 +0000 (14:11 +0100)
gamma_compression_effect.cpp
gamma_compression_effect.frag
gamma_compression_effect.h
gamma_expansion_effect.cpp
gamma_expansion_effect.frag
gamma_expansion_effect.h

index b0f6372..83489be 100644 (file)
@@ -13,11 +13,7 @@ GammaCompressionEffect::GammaCompressionEffect()
 {
        register_int("destination_curve", (int *)&destination_curve);
        register_uniform_float("linear_scale", &uniform_linear_scale);
-       register_uniform_float("c0", &uniform_c0);
-       register_uniform_float("c1", &uniform_c1);
-       register_uniform_float("c2", &uniform_c2);
-       register_uniform_float("c3", &uniform_c3);
-       register_uniform_float("c4", &uniform_c4);
+       register_uniform_float_array("c", uniform_c, 5);
        register_uniform_float("beta", &uniform_beta);
 }
 
@@ -81,11 +77,11 @@ void GammaCompressionEffect::set_gl_state(GLuint glsl_program_num, const string
                // maxerror      = 0.000785 = 0.200 * 255
                // error at 1.0  = 0.000078 = 0.020 * 255
                uniform_linear_scale = 12.92;
-               uniform_c0 = -0.03679675939;
-               uniform_c1 = 1.443803073;
-               uniform_c2 = -0.9239780987;
-               uniform_c3 = 0.8060491596;
-               uniform_c4 = -0.2891558568;
+               uniform_c[0] = -0.03679675939;
+               uniform_c[1] = 1.443803073;
+               uniform_c[2] = -0.9239780987;
+               uniform_c[3] = 0.8060491596;
+               uniform_c[4] = -0.2891558568;
                uniform_beta = 0.0031308;
        }
        if (destination_curve == GAMMA_REC_709) {  // Also includes Rec. 601, and 10-bit Rec. 2020.
@@ -93,11 +89,11 @@ void GammaCompressionEffect::set_gl_state(GLuint glsl_program_num, const string
                // maxerror      = 0.000131 = 0.033 * 255 = 0.134 * 1023
                // error at 1.0  = 0.000013 = 0.003 * 255 = 0.013 * 1023
                uniform_linear_scale = 4.5;
-               uniform_c0 = -0.08541688528;
-               uniform_c1 = 1.292793370;
-               uniform_c2 = -0.4070417645;
-               uniform_c3 = 0.2923891828;
-               uniform_c4 = -0.09273699351;
+               uniform_c[0] = -0.08541688528;
+               uniform_c[1] = 1.292793370;
+               uniform_c[2] = -0.4070417645;
+               uniform_c[3] = 0.2923891828;
+               uniform_c[4] = -0.09273699351;
                uniform_beta = 0.018;
        }
        if (destination_curve == GAMMA_REC_2020_12_BIT) {
@@ -111,11 +107,11 @@ void GammaCompressionEffect::set_gl_state(GLuint glsl_program_num, const string
                // from 0.553 to 0.501; adding a fifth order can get it down to
                // 0.167, although this assumes working in fp64 and not fp32.)
                uniform_linear_scale = 4.5;
-               uniform_c0 = -0.08569685663;
-               uniform_c1 = 1.293000900;
-               uniform_c2 = -0.4067291321;
-               uniform_c3 = 0.2919741179;
-               uniform_c4 = -0.09256205770;
+               uniform_c[0] = -0.08569685663;
+               uniform_c[1] = 1.293000900;
+               uniform_c[2] = -0.4067291321;
+               uniform_c[3] = 0.2919741179;
+               uniform_c[4] = -0.09256205770;
                uniform_beta = 0.0181;
        }
 }
index 2d84f32..a72a878 100644 (file)
@@ -2,7 +2,7 @@
 
 // Implicit uniforms:
 // uniform float PREFIX(linear_scale);
-// uniform float PREFIX(c0), PREFIX(c1), PREFIX(c2), PREFIX(c3), PREFIX(c4);
+// uniform float PREFIX(c)[5];
 // uniform float PREFIX(beta);
 
 vec4 FUNCNAME(vec2 tc) {
@@ -16,7 +16,7 @@ vec4 FUNCNAME(vec2 tc) {
 
        // Fourth-order polynomial approximation to pow(). See the .cpp file for details.
        vec3 s = sqrt(x.rgb);
-       vec3 b = PREFIX(c0) + (PREFIX(c1) + (PREFIX(c2) + (PREFIX(c3) + PREFIX(c4) * s) * s) * s) * s;
+       vec3 b = PREFIX(c)[0] + (PREFIX(c)[1] + (PREFIX(c)[2] + (PREFIX(c)[3] + PREFIX(c)[4] * s) * s) * s) * s;
 
        vec3 f = vec3(greaterThan(x.rgb, vec3(PREFIX(beta))));
        x = vec4(mix(a, b, f), x.a);
index 08fa194..d522911 100644 (file)
@@ -37,7 +37,7 @@ public:
 
 private:
        GammaCurve destination_curve;
-       float uniform_linear_scale, uniform_c0, uniform_c1, uniform_c2, uniform_c3, uniform_c4, uniform_beta;
+       float uniform_linear_scale, uniform_c[5], uniform_beta;
 };
 
 }  // namespace movit
index 15e0bff..63b4c51 100644 (file)
@@ -13,11 +13,7 @@ GammaExpansionEffect::GammaExpansionEffect()
 {
        register_int("source_curve", (int *)&source_curve);
        register_uniform_float("linear_scale", &uniform_linear_scale);
-       register_uniform_float("c0", &uniform_c0);
-       register_uniform_float("c1", &uniform_c1);
-       register_uniform_float("c2", &uniform_c2);
-       register_uniform_float("c3", &uniform_c3);
-       register_uniform_float("c4", &uniform_c4);
+       register_uniform_float_array("c", uniform_c, 5);
        register_uniform_float("beta", &uniform_beta);
 }
 
@@ -88,11 +84,11 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const string &p
                // Note that the worst _relative_ error by far is just at the beginning
                // of the exponential curve, ie., just around β.
                uniform_linear_scale = 1.0 / 12.92;
-               uniform_c0 = 0.001324469581;
-               uniform_c1 = 0.02227416690;
-               uniform_c2 = 0.5917615253;
-               uniform_c3 = 0.4733532353;
-               uniform_c4 = -0.08880738120;
+               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.
@@ -105,11 +101,11 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const string &p
                // our beta and gamma are different from the numbers mentioned
                // (we've inverted the formula).
                uniform_linear_scale = 1.0 / 4.5;
-               uniform_c0 = 0.005137028744;
-               uniform_c1 = 0.09802596889;
-               uniform_c2 = 0.7255768864;
-               uniform_c3 = 0.2135067966;
-               uniform_c4 = -0.04225094667;
+               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) {
@@ -122,11 +118,11 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const string &p
                // our beta and gamma are different from the numbers mentioned
                // (we've inverted the formula).
                uniform_linear_scale = 1.0 / 4.5;
-               uniform_c0 = 0.005167545928;
-               uniform_c1 = 0.09835585809;
-               uniform_c2 = 0.7254820139;
-               uniform_c3 = 0.2131291155;
-               uniform_c4 = -0.04213877222;
+               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;
        }
 }
index 051d2fa..b8e3581 100644 (file)
@@ -2,7 +2,7 @@
 
 // Implicit uniforms:
 // uniform float PREFIX(linear_scale);
-// uniform float PREFIX(c0), PREFIX(c1), PREFIX(c2), PREFIX(c3), PREFIX(c4);
+// uniform float PREFIX(c)[5];
 // uniform float PREFIX(beta);
 
 vec4 FUNCNAME(vec2 tc) {
@@ -11,7 +11,7 @@ vec4 FUNCNAME(vec2 tc) {
        vec3 a = x.rgb * PREFIX(linear_scale);
 
        // Fourth-order polynomial approximation to pow(). See the .cpp file for details.
-       vec3 b = PREFIX(c0) + (PREFIX(c1) + (PREFIX(c2) + (PREFIX(c3) + PREFIX(c4) * x.rgb) * x.rgb) * x.rgb) * x.rgb;
+       vec3 b = PREFIX(c[0]) + (PREFIX(c[1]) + (PREFIX(c[2]) + (PREFIX(c[3]) + PREFIX(c[4]) * x.rgb) * x.rgb) * x.rgb) * x.rgb;
 
        vec3 f = vec3(greaterThan(x.rgb, vec3(PREFIX(beta))));
        x = vec4(mix(a, b, f), x.a);
index 20a5a76..429bd25 100644 (file)
@@ -38,7 +38,7 @@ public:
 
 private:
        GammaCurve source_curve;
-       float uniform_linear_scale, uniform_c0, uniform_c1, uniform_c2, uniform_c3, uniform_c4, uniform_beta;
+       float uniform_linear_scale, uniform_c[5], uniform_beta;
 };
 
 }  // namespace movit