]> git.sesse.net Git - movit/commitdiff
Implement gamma expansion from sRGB.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 1 Oct 2012 17:05:43 +0000 (19:05 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 1 Oct 2012 17:05:43 +0000 (19:05 +0200)
gamma_expansion_effect.cpp
gamma_expansion_effect_srgb.glsl [new file with mode: 0644]

index 1748ae93dcee81c7268f803c82a8dffb13c8495a..1ecc897c00d73172e8205c48cb04a43a858eaea0 100644 (file)
@@ -1,3 +1,5 @@
+#include <assert.h>
+
 #include "gamma_expansion_effect.h"
 #include "util.h"
 
@@ -9,5 +11,13 @@ GammaExpansionEffect::GammaExpansionEffect()
 
 std::string GammaExpansionEffect::output_glsl()
 {
-       return read_file("todo.glsl");
+       switch (source_curve) {
+       case GAMMA_sRGB:
+               return read_file("gamma_expansion_effect_srgb.glsl");
+       case GAMMA_REC_709:  // and GAMMA_REC_601
+               // Not implemented yet.
+               assert(false);
+       default:
+               assert(false);
+       }
 }
diff --git a/gamma_expansion_effect_srgb.glsl b/gamma_expansion_effect_srgb.glsl
new file mode 100644 (file)
index 0000000..e90bb62
--- /dev/null
@@ -0,0 +1,31 @@
+// Expand sRGB gamma curve.
+
+#if 0
+
+// if we have the lut
+uniform sampler1D PREFIX(srgb_tex);
+
+vec4 FUNCNAME(vec2 tc) {
+       vec4 x = LAST_INPUT(tc);
+
+       x.r = texture1D(PREFIX(srgb_tex), x.r).x;
+       x.g = texture1D(PREFIX(srgb_tex), x.g).x;
+       x.b = texture1D(PREFIX(srgb_tex), x.b).x;
+
+       return x;
+}
+
+#else
+
+// use arithmetic (slow)
+vec4 FUNCNAME(vec2 tc) {
+       vec4 x = LAST_INPUT(tc);
+
+       vec3 a = x.rgb * vec3(1.0/12.92); 
+       vec3 b = pow((x.rgb + vec3(0.055)) * vec3(1.0/1.055), vec3(2.4));
+       vec3 f = vec3(greaterThan(x.rgb, vec3(0.04045)));
+
+       return vec4(mix(a, b, f), x.a); 
+}
+#endif