From: Steinar H. Gunderson Date: Sun, 14 Oct 2012 10:46:48 +0000 (+0200) Subject: Add unit tests for colorspace conversion insertion. X-Git-Tag: 1.0~249 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=898a2140fa78eecb3552f63f021c608b239f969c;hp=0bd42ece563848c10733dba085ea3672f92d2558 Add unit tests for colorspace conversion insertion. --- diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index 28197f9..5df9270 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -135,8 +135,32 @@ TEST(EffectChainTest, RewritingWorksAndGammaConversionsAreInserted) { expect_equal(expected_data, out_data, 3, 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 +201,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) {