X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain_test.cpp;h=d8ade1370e06d58669d2c47d1e2ff2c5b0d6f4ae;hp=28197f9152c3bdcedc0dfe40fedc5178e5de93da;hb=cc9e1cb1ba6a09b38b5e59ccab817a97dd49ca98;hpb=ac5f7aa64ab690120a71fe45ee4b9bbc56610191 diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index 28197f9..d8ade13 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -135,8 +135,57 @@ TEST(EffectChainTest, RewritingWorksAndGammaConversionsAreInserted) { expect_equal(expected_data, out_data, 3, 2); } +TEST(EffectChainTest, RewritingWorksAndTexturesAreAskedForsRGB) { + unsigned char data[] = { + 0, 64, + 128, 255, + }; + float expected_data[4] = { + 1.0f, 0.9771f, + 0.8983f, 0.0f, + }; + float out_data[2]; + EffectChainTester tester(NULL, 2, 2); + tester.add_input(data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB); + RewritingToInvertEffect *effect = new RewritingToInvertEffect(); + tester.get_chain()->add_effect(effect); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB); + + Node *node = effect->invert_node; + ASSERT_EQ(1, node->incoming_links.size()); + ASSERT_EQ(1, node->outgoing_links.size()); + EXPECT_EQ("FlatInput", node->incoming_links[0]->effect->effect_type_id()); + EXPECT_EQ("GammaCompressionEffect", node->outgoing_links[0]->effect->effect_type_id()); + + expect_equal(expected_data, out_data, 2, 2); +} + +TEST(EffectChainTest, RewritingWorksAndColorspaceConversionsAreInserted) { + float data[] = { + 0.0f, 0.25f, 0.3f, + 0.75f, 1.0f, 1.0f, + }; + float expected_data[6] = { + 1.0f, 0.75f, 0.7f, + 0.25f, 0.0f, 0.0f, + }; + float out_data[6]; + EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_REC_601_525, GAMMA_LINEAR); + RewritingToInvertEffect *effect = new RewritingToInvertEffect(); + tester.get_chain()->add_effect(effect); + tester.run(out_data, GL_RED, COLORSPACE_REC_601_525, GAMMA_LINEAR); + + Node *node = effect->invert_node; + ASSERT_EQ(1, node->incoming_links.size()); + ASSERT_EQ(1, node->outgoing_links.size()); + EXPECT_EQ("ColorspaceConversionEffect", node->incoming_links[0]->effect->effect_type_id()); + EXPECT_EQ("ColorspaceConversionEffect", node->outgoing_links[0]->effect->effect_type_id()); + + expect_equal(expected_data, out_data, 3, 2); +} + // Like RewritingToInvertEffect, but splicing in a MirrorEffect instead, -// which does not need linear light. +// which does not need linear light or sRGB primaries. class RewritingToMirrorEffect : public Effect { public: RewritingToMirrorEffect() {} @@ -177,6 +226,29 @@ TEST(EffectChainTest, NoGammaConversionsWhenLinearLightNotNeeded) { expect_equal(expected_data, out_data, 3, 2); } +TEST(EffectChainTest, NoColorspaceConversionsWhensRGBPrimariesNotNeeded) { + float data[] = { + 0.0f, 0.25f, 0.3f, + 0.75f, 1.0f, 1.0f, + }; + float expected_data[6] = { + 0.3f, 0.25f, 0.0f, + 1.0f, 1.0f, 0.75f, + }; + float out_data[6]; + EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_REC_601_525, GAMMA_LINEAR); + RewritingToMirrorEffect *effect = new RewritingToMirrorEffect(); + tester.get_chain()->add_effect(effect); + tester.run(out_data, GL_RED, COLORSPACE_REC_601_525, GAMMA_LINEAR); + + Node *node = effect->mirror_node; + ASSERT_EQ(1, node->incoming_links.size()); + EXPECT_EQ(0, node->outgoing_links.size()); + EXPECT_EQ("FlatInput", node->incoming_links[0]->effect->effect_type_id()); + + 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) { @@ -192,6 +264,23 @@ TEST(EffectChainTest, IdentityThroughsRGBConversions) { expect_equal(data, out_data, 256, 1); } +// Same, but uses the forward sRGB table from the GPU. +TEST(EffectChainTest, IdentityThroughGPUsRGBConversions) { + unsigned char data[256]; + float expected_data[256]; + for (unsigned i = 0; i < 256; ++i) { + data[i] = i; + expected_data[i] = i / 255.0; + }; + float out_data[256]; + EffectChainTester tester(NULL, 256, 1); + tester.add_input(data, 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(expected_data, out_data, 256, 1); +} + // Same, for the Rec. 601/709 gamma curve. TEST(EffectChainTest, IdentityThroughRec709) { float data[256];