Implement the Rec. 709 gamma curve.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 1 Oct 2012 19:01:36 +0000 (21:01 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 1 Oct 2012 19:01:36 +0000 (21:01 +0200)
gamma_compression_effect.cpp
gamma_compression_effect_rec709.glsl [new file with mode: 0644]
gamma_compression_effect_srgb.glsl
gamma_expansion_effect.cpp
gamma_expansion_effect_rec709.glsl [new file with mode: 0644]

index 5815428..5a76ec3 100644 (file)
@@ -17,8 +17,7 @@ std::string GammaCompressionEffect::output_glsl()
        case GAMMA_sRGB:
                return read_file("gamma_compression_effect_srgb.glsl");
        case GAMMA_REC_709:  // and GAMMA_REC_601
-               // Not implemented yet.
-               assert(false);
+               return read_file("gamma_compression_effect_rec709.glsl");
        default:
                assert(false);
        }
diff --git a/gamma_compression_effect_rec709.glsl b/gamma_compression_effect_rec709.glsl
new file mode 100644 (file)
index 0000000..807cd49
--- /dev/null
@@ -0,0 +1,31 @@
+// Compress to Rec. 601/Rec. 709 gamma curve.
+
+#if 0
+
+// if we have the lut
+uniform sampler1D PREFIX(rec709_inverse_tex);
+
+vec4 FUNCNAME(vec2 tc) {
+       vec4 x = LAST_INPUT(tc);
+
+       x.r = texture1D(PREFIX(rec709_inverse_tex), x.r).x;
+       x.g = texture1D(PREFIX(rec709_inverse_tex), x.g).x;
+       x.b = texture1D(PREFIX(rec709_inverse_tex), x.b).x;
+
+       return x;
+}
+
+#else
+
+// use arithmetic (slow)
+vec4 FUNCNAME(vec2 tc) {
+       vec4 x = LAST_INPUT(tc);
+
+       vec3 a = vec3(4.5) * x.rgb;
+       vec3 b = vec3(1.099) * pow(x.rgb, vec3(0.45)) - vec3(0.099);
+       vec3 f = vec3(greaterThan(x.rgb, vec3(0.018)));
+
+       return vec4(mix(a, b, f), x.a); 
+}
+#endif
index 2d53e08..e65d6bb 100644 (file)
@@ -3,14 +3,14 @@
 #if 0
 
 // if we have the lut
-uniform sampler1D PREFIX(srgb_tex);
+uniform sampler1D PREFIX(srgb_inverse_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;
+       x.r = texture1D(PREFIX(srgb_inverse_tex), x.r).x;
+       x.g = texture1D(PREFIX(srgb_inverse_tex), x.g).x;
+       x.b = texture1D(PREFIX(srgb_inverse_tex), x.b).x;
 
        return x;
 }
index 74a8de9..fdf34f5 100644 (file)
@@ -17,8 +17,7 @@ std::string GammaExpansionEffect::output_glsl()
        case GAMMA_sRGB:
                return read_file("gamma_expansion_effect_srgb.glsl");
        case GAMMA_REC_709:  // and GAMMA_REC_601
-               // Not implemented yet.
-               assert(false);
+               return read_file("gamma_expansion_effect_rec709.glsl");
        default:
                assert(false);
        }
diff --git a/gamma_expansion_effect_rec709.glsl b/gamma_expansion_effect_rec709.glsl
new file mode 100644 (file)
index 0000000..00259cc
--- /dev/null
@@ -0,0 +1,31 @@
+// Expand Rec. 601/Rec. 709 gamma curve.
+
+#if 0
+
+// if we have the lut
+uniform sampler1D PREFIX(rec709_tex);
+
+vec4 FUNCNAME(vec2 tc) {
+       vec4 x = LAST_INPUT(tc);
+
+       x.r = texture1D(PREFIX(rec709_tex), x.r).x;
+       x.g = texture1D(PREFIX(rec709_tex), x.g).x;
+       x.b = texture1D(PREFIX(rec709_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/4.500);
+       vec3 b = pow((x.rgb + vec3(0.099)) * vec3(1.0/1.099), vec3(1.0/0.45));
+       vec3 f = vec3(greaterThan(x.rgb, vec3(0.081)));
+
+       return vec4(mix(a, b, f), x.a); 
+}
+#endif