]> git.sesse.net Git - movit/commitdiff
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 b0f6372d4b9560ac9fb59c8c438feb022974189e..83489be5dbf669bcf692e3e497394b58ee22655b 100644 (file)
@@ -13,11 +13,7 @@ GammaCompressionEffect::GammaCompressionEffect()
 {
        register_int("destination_curve", (int *)&destination_curve);
        register_uniform_float("linear_scale", &uniform_linear_scale);
 {
        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);
 }
 
        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;
                // 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.
                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;
                // 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) {
                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;
                // 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;
        }
 }
                uniform_beta = 0.0181;
        }
 }
index 2d84f326dd054a23908b3ef1ecdcd5e71f0bb2f1..a72a878c84720c1d0bc53274e429a4d7af0659ca 100644 (file)
@@ -2,7 +2,7 @@
 
 // Implicit uniforms:
 // uniform float PREFIX(linear_scale);
 
 // 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) {
 // 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);
 
        // 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);
 
        vec3 f = vec3(greaterThan(x.rgb, vec3(PREFIX(beta))));
        x = vec4(mix(a, b, f), x.a);
index 08fa1940adfdf58e6b37dcd35780361fd299a904..d52291115ec0ae85e3cb16840eddf4892acd4040 100644 (file)
@@ -37,7 +37,7 @@ public:
 
 private:
        GammaCurve destination_curve;
 
 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
 };
 
 }  // namespace movit
index 15e0bffb8f03ed0a1bf034c29b9fbbcd6245be38..63b4c51309b9b11fdb028f9b037ba3b045013397 100644 (file)
@@ -13,11 +13,7 @@ GammaExpansionEffect::GammaExpansionEffect()
 {
        register_int("source_curve", (int *)&source_curve);
        register_uniform_float("linear_scale", &uniform_linear_scale);
 {
        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);
 }
 
        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;
                // 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.
                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;
                // 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) {
                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;
                // 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;
        }
 }
                uniform_beta = 0.0181 * 4.5;
        }
 }
index 051d2faf1042cc47e0be4b3b715dba67c0333794..b8e3581f53772107880d9b90b68981a95e9f35d9 100644 (file)
@@ -2,7 +2,7 @@
 
 // Implicit uniforms:
 // uniform float PREFIX(linear_scale);
 
 // 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) {
 // 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 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);
 
        vec3 f = vec3(greaterThan(x.rgb, vec3(PREFIX(beta))));
        x = vec4(mix(a, b, f), x.a);
index 20a5a76fba04315d74f9aa09502eaac3e196e658..429bd25c4f8cf55de6fa9e907e9be1abdf2db4c2 100644 (file)
@@ -38,7 +38,7 @@ public:
 
 private:
        GammaCurve source_curve;
 
 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
 };
 
 }  // namespace movit