X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=gamma_expansion_effect.cpp;h=d4e532f8b816f1cf594a0f82ba199f5133f944cb;hp=9391a91f55bd9be3c171a9ad911d71d1e4ca6a9c;hb=0dc1dfe6444a700ebd2c9f006cba000b90c3a7b0;hpb=db1fbb73b18b68850f61d1c8b89f2e4d3f7aadc1 diff --git a/gamma_expansion_effect.cpp b/gamma_expansion_effect.cpp index 9391a91..d4e532f 100644 --- a/gamma_expansion_effect.cpp +++ b/gamma_expansion_effect.cpp @@ -1,3 +1,4 @@ +#include #include #include "gamma_expansion_effect.h" @@ -7,18 +8,37 @@ GammaExpansionEffect::GammaExpansionEffect() : source_curve(GAMMA_LINEAR) { register_int("source_curve", (int *)&source_curve); + register_1d_texture("expansion_curve_tex", expansion_curve, EXPANSION_CURVE_SIZE); } std::string GammaExpansionEffect::output_fragment_shader() { - switch (source_curve) { - case GAMMA_LINEAR: - return read_file("identity-fs.glsl"); - case GAMMA_sRGB: - return read_file("gamma_expansion_effect_srgb.glsl"); - case GAMMA_REC_709: // and GAMMA_REC_601 - return read_file("gamma_expansion_effect_rec709.glsl"); - default: - assert(false); + if (source_curve == GAMMA_LINEAR) { + return read_file("identity.frag"); } + if (source_curve == GAMMA_sRGB) { + for (unsigned i = 0; i < EXPANSION_CURVE_SIZE; ++i) { + float x = i / (float)(EXPANSION_CURVE_SIZE - 1); + if (x < 0.04045f) { + expansion_curve[i] = (1.0/12.92f) * x; + } else { + expansion_curve[i] = pow((x + 0.055) * (1.0/1.055f), 2.4); + } + } + invalidate_1d_texture("expansion_curve_tex"); + return read_file("gamma_expansion_effect.frag"); + } + if (source_curve == GAMMA_REC_709) { // And Rec. 601. + for (unsigned i = 0; i < EXPANSION_CURVE_SIZE; ++i) { + float x = i / (float)(EXPANSION_CURVE_SIZE - 1); + if (x < 0.081f) { + expansion_curve[i] = (1.0/4.5f) * x; + } else { + expansion_curve[i] = pow((x + 0.099) * (1.0/1.099f), 1.0f/0.45f); + } + } + invalidate_1d_texture("expansion_curve_tex"); + return read_file("gamma_expansion_effect.frag"); + } + assert(false); }