X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=gamma_expansion_effect_test.cpp;h=dc50f911f9dca122e1e6e67a1eee6131b1305dbd;hb=0059fbc390f8a50b5848cc9de52d4208450c7d71;hp=ed124c4f31c7a9d750c91bcf4269e4398fd7839c;hpb=2fdbe6e32ef5de09db9c890b6cd4355bf65dd1e5;p=movit diff --git a/gamma_expansion_effect_test.cpp b/gamma_expansion_effect_test.cpp index ed124c4..dc50f91 100644 --- a/gamma_expansion_effect_test.cpp +++ b/gamma_expansion_effect_test.cpp @@ -1,8 +1,10 @@ // Unit tests for GammaExpansionEffect. -#include "test_util.h" -#include "gtest/gtest.h" +#include + #include "gamma_expansion_effect.h" +#include "gtest/gtest.h" +#include "test_util.h" TEST(GammaExpansionEffectTest, sRGB_KeyValues) { float data[] = { @@ -34,6 +36,21 @@ TEST(GammaExpansionEffectTest, sRGB_RampAlwaysIncreases) { } } +TEST(GammaExpansionEffectTest, sRGB_AlphaIsUnchanged) { + float data[] = { + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.25f, + 0.0f, 0.0f, 0.0f, 0.5f, + 0.0f, 0.0f, 0.0f, 0.75f, + 0.0f, 0.0f, 0.0f, 1.0f, + }; + float out_data[5 * 4]; + EffectChainTester tester(data, 5, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB); + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(data, out_data, 5, 1); +} + TEST(GammaExpansionEffectTest, Rec709_KeyValues) { float data[] = { 0.0f, 1.0f, @@ -63,3 +80,39 @@ TEST(GammaExpansionEffectTest, Rec709_RampAlwaysIncreases) { << "No increase between " << i-1 << " and " << i; } } + +TEST(GammaExpansionEffectTest, Rec709_AlphaIsUnchanged) { + float data[] = { + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.25f, + 0.0f, 0.0f, 0.0f, 0.5f, + 0.0f, 0.0f, 0.0f, 0.75f, + 0.0f, 0.0f, 0.0f, 1.0f, + }; + float out_data[5 * 4]; + EffectChainTester tester(data, 5, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_REC_709); + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(data, out_data, 5, 1); +} + +TEST(GammaExpansionEffectTest, Rec2020_12BitIsVeryCloseToRec709) { + float data[256]; + for (unsigned i = 0; i < 256; ++i) { + data[i] = i / 255.0f; + } + float out_data_709[256]; + float out_data_2020[256]; + + EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_709); + tester.run(out_data_709, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); + EffectChainTester tester2(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_2020_12_BIT); + tester2.run(out_data_2020, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); + + double sqdiff = 0.0; + for (unsigned i = 0; i < 256; ++i) { + EXPECT_NEAR(out_data_709[i], out_data_2020[i], 1e-3); + sqdiff += (out_data_709[i] - out_data_2020[i]) * (out_data_709[i] - out_data_2020[i]); + } + EXPECT_GT(sqdiff, 1e-6); +}