X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain.cpp;h=3ccab448f17a4ae85a3055d2cab375c6c41e6a0d;hp=1ff57d75672b3769121f7c0956941c6538415620;hb=affe96389941123d20354ad8091977aa196a741c;hpb=bfa58911af9e945f3532a2c48306b4e9e293e0f7 diff --git a/effect_chain.cpp b/effect_chain.cpp index 1ff57d7..3ccab44 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -13,10 +13,11 @@ #include "gamma_compression_effect.h" #include "lift_gamma_gain_effect.h" #include "colorspace_conversion_effect.h" +#include "saturation_effect.h" #include "texture_enum.h" EffectChain::EffectChain(unsigned width, unsigned height) - : width(width), height(height), finalized(false) {} + : width(width), height(height), use_srgb_texture_format(false), finalized(false) {} void EffectChain::add_input(const ImageFormat &format) { @@ -33,21 +34,28 @@ void EffectChain::add_output(const ImageFormat &format) Effect *instantiate_effect(EffectId effect) { switch (effect) { - case GAMMA_CONVERSION: + case EFFECT_GAMMA_EXPANSION: return new GammaExpansionEffect(); - case RGB_PRIMARIES_CONVERSION: - return new GammaExpansionEffect(); - case LIFT_GAMMA_GAIN: + case EFFECT_GAMMA_COMPRESSION: + return new GammaCompressionEffect(); + case EFFECT_LIFT_GAMMA_GAIN: return new LiftGammaGainEffect(); + case EFFECT_SATURATION: + return new SaturationEffect(); } assert(false); } void EffectChain::normalize_to_linear_gamma() { - GammaExpansionEffect *gamma_conversion = new GammaExpansionEffect(); - gamma_conversion->set_int("source_curve", current_gamma_curve); - effects.push_back(gamma_conversion); + if (current_gamma_curve == GAMMA_sRGB) { + // TODO: check if the extension exists + use_srgb_texture_format = true; + } else { + GammaExpansionEffect *gamma_conversion = new GammaExpansionEffect(); + gamma_conversion->set_int("source_curve", current_gamma_curve); + effects.push_back(gamma_conversion); + } current_gamma_curve = GAMMA_LINEAR; } @@ -180,11 +188,15 @@ void EffectChain::render_to_screen(unsigned char *src) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, SOURCE_IMAGE); - // TODO: use sRGB textures if applicable + GLenum internal_format = GL_RGBA8; + if (use_srgb_texture_format) { + internal_format = GL_SRGB8; + } + if (input_format.pixel_format == FORMAT_RGB) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, src); + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, src); } else if (input_format.pixel_format == FORMAT_RGBA) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, src); + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, src); } else { assert(false); }