X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=lift_gamma_gain_effect_test.cpp;h=f9163a8b32ea53188c831386512d78172828c58d;hp=0b63063347c582420a8710cf01ea3b4e0e92cdb7;hb=eff011224abc5dc81f801f3ea44572287a55bcac;hpb=37f56fcbe571b2322243f6de59494bf9e0cbb37a diff --git a/lift_gamma_gain_effect_test.cpp b/lift_gamma_gain_effect_test.cpp index 0b63063..f9163a8 100644 --- a/lift_gamma_gain_effect_test.cpp +++ b/lift_gamma_gain_effect_test.cpp @@ -1,11 +1,15 @@ // Unit tests for LiftGammaGainEffect. +#include + #include "effect_chain.h" #include "gtest/gtest.h" #include "image_format.h" #include "lift_gamma_gain_effect.h" #include "test_util.h" +namespace movit { + TEST(LiftGammaGainEffectTest, DefaultIsNoop) { float data[] = { 0.0f, 0.0f, 0.0f, 1.0f, @@ -94,3 +98,52 @@ TEST(LiftGammaGainEffectTest, Gamma22IsApproximatelysRGB) { expect_equal(data, out_data, 4, 5); } + +TEST(LiftGammaGainEffectTest, OutOfGamutColorsAreClipped) { + float data[] = { + -0.5f, 0.3f, 0.0f, 1.0f, + 0.5f, 0.0f, 0.0f, 1.0f, + 0.0f, 1.5f, 0.5f, 0.3f, + }; + float expected_data[] = { + 0.0f, 0.3f, 0.0f, 1.0f, // Clipped to zero. + 0.5f, 0.0f, 0.0f, 1.0f, + 0.0f, 1.5f, 0.5f, 0.3f, + }; + + float out_data[3 * 4]; + EffectChainTester tester(data, 1, 3, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.get_chain()->add_effect(new LiftGammaGainEffect()); + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(expected_data, out_data, 4, 3); +} + +TEST(LiftGammaGainEffectTest, NegativeLiftIsClamped) { + float data[] = { + 0.0f, 0.0f, 0.0f, 1.0f, + 0.5f, 0.5f, 0.5f, 0.3f, + 1.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 1.0f, 0.0f, 0.7f, + 0.0f, 0.0f, 1.0f, 1.0f, + }; + float lift[3] = { 0.0f, -0.1f, -0.2f }; + float expected_data[] = { + 0.0f, 0.0f , 0.0f, 1.0f, // Note: Clamped below zero. + 0.5f, 0.45f, 0.4f, 0.3f, + 1.0f, 0.0f, 0.0f, 1.0f, // Unaffected. + 0.0f, 1.0f, 0.0f, 0.7f, + 0.0f, 0.0f, 1.0f, 1.0f, + }; + + float out_data[5 * 4]; + EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB); + Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect()); + ASSERT_TRUE(lgg_effect->set_vec3("lift", lift)); + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_sRGB); + + // sRGB is only approximately gamma-2.2, so loosen up the limits a bit. + expect_equal(expected_data, out_data, 4, 5, 0.03, 0.003); +} + +} // namespace movit