From 430394b9790b9a7083aac549f607047499788710 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 1 Oct 2012 19:05:43 +0200 Subject: [PATCH] Implement gamma expansion from sRGB. --- gamma_expansion_effect.cpp | 12 +++++++++++- gamma_expansion_effect_srgb.glsl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gamma_expansion_effect_srgb.glsl diff --git a/gamma_expansion_effect.cpp b/gamma_expansion_effect.cpp index 1748ae9..1ecc897 100644 --- a/gamma_expansion_effect.cpp +++ b/gamma_expansion_effect.cpp @@ -1,3 +1,5 @@ +#include + #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 index 0000000..e90bb62 --- /dev/null +++ b/gamma_expansion_effect_srgb.glsl @@ -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 -- 2.39.2