]> git.sesse.net Git - movit/blobdiff - gamma_expansion_effect.cpp
Check for __APPLE__ instead of __DARWIN__.
[movit] / gamma_expansion_effect.cpp
index 5f9423f7c749081f965d57bbb8ba06901381ca08..95437906f4c63134232e7775ba630016b2b6748f 100644 (file)
@@ -1,17 +1,20 @@
-#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);
 }
 
-std::string GammaExpansionEffect::output_fragment_shader()
+string GammaExpansionEffect::output_fragment_shader()
 {
        if (source_curve == GAMMA_LINEAR) {
                return read_file("identity.frag");
@@ -24,7 +27,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 +40,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.)
        //
@@ -74,6 +77,9 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const std::stri
                // maxerror      = 0.000094
                // error at beta = 0.000012
                // error at 1.0  = 0.000012
+               //
+               // 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);
@@ -117,3 +123,5 @@ void GammaExpansionEffect::set_gl_state(GLuint glsl_program_num, const std::stri
                set_uniform_float(glsl_program_num, prefix, "beta", 0.0181 * 4.5);
        }
 }
+
+}  // namespace movit