X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=gamma_expansion_effect.cpp;h=45745673d3420c3152e14434a3ace4741ce208bd;hp=cef1416ae5b8f7f5c7f9fc8c74641c11927412ef;hb=c5cd45a98c89b983f53fd8759c4e0a3cb286b96b;hpb=93b0136eb2bd31043526b95dc3e920bc2ab880ee diff --git a/gamma_expansion_effect.cpp b/gamma_expansion_effect.cpp index cef1416..4574567 100644 --- a/gamma_expansion_effect.cpp +++ b/gamma_expansion_effect.cpp @@ -1,7 +1,45 @@ +#include +#include + #include "gamma_expansion_effect.h" +#include "util.h" GammaExpansionEffect::GammaExpansionEffect() : source_curve(GAMMA_LINEAR) { register_int("source_curve", (int *)&source_curve); + memset(expansion_curve, 0, sizeof(expansion_curve)); + register_1d_texture("expansion_curve_tex", expansion_curve, EXPANSION_CURVE_SIZE); +} + +std::string GammaExpansionEffect::output_fragment_shader() +{ + 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); }