]> git.sesse.net Git - movit/blobdiff - effect_chain_test.cpp
Add unit tests for back-and-forth conversions through sRGB and Rec. 709 gamma.
[movit] / effect_chain_test.cpp
index e5ca1cc1f28423c2ae8e8779695fdd3508c269e6..20fd9bc97395672921b05f677f34efdf0d35762b 100644 (file)
@@ -15,8 +15,8 @@ TEST(EffectChainTest, EmptyChain) {
                0.75f, 1.0f, 1.0f,
        };
        float out_data[6];
-       EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+       EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
 
        expect_equal(data, out_data, 3, 2);
 }
@@ -35,9 +35,9 @@ TEST(EffectChainTest, Identity) {
                0.75f, 1.0f, 1.0f,
        };
        float out_data[6];
-       EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
        tester.get_chain()->add_effect(new IdentityEffect());
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
 
        expect_equal(data, out_data, 3, 2);
 }
@@ -57,9 +57,9 @@ TEST(EffectChainTest, TextureBouncePreservesIdentity) {
                0.75f, 1.0f, 1.0f,
        };
        float out_data[6];
-       EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
        tester.get_chain()->add_effect(new BouncingIdentityEffect());
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
 
        expect_equal(data, out_data, 3, 2);
 }
@@ -74,9 +74,38 @@ TEST(MirrorTest, BasicTest) {
                1.0f, 1.0f, 0.75f,
        };
        float out_data[6];
-       EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
        tester.get_chain()->add_effect(new MirrorEffect());
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
 
        expect_equal(expected_data, out_data, 3, 2);
 }
+
+// The identity effect needs linear light, and thus will get conversions on both sides.
+// Verify that sRGB data is properly converted to and from linear light for the entire ramp.
+TEST(EffectChainTest, IdentityThroughsRGBConversions) {
+       float data[256];
+       for (unsigned i = 0; i < 256; ++i) {
+               data[i] = i / 255.0;
+       };
+       float out_data[256];
+       EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB);
+       tester.get_chain()->add_effect(new IdentityEffect());
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
+
+       expect_equal(data, out_data, 256, 1);
+}
+
+// Same, for the Rec. 601/709 gamma curve.
+TEST(EffectChainTest, IdentityThroughRec709) {
+       float data[256];
+       for (unsigned i = 0; i < 256; ++i) {
+               data[i] = i / 255.0;
+       };
+       float out_data[256];
+       EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_709);
+       tester.get_chain()->add_effect(new IdentityEffect());
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
+
+       expect_equal(data, out_data, 256, 1);
+}