]> git.sesse.net Git - movit/commitdiff
Add unit tests for colorspace conversion insertion.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2012 10:46:48 +0000 (12:46 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2012 10:46:48 +0000 (12:46 +0200)
effect_chain_test.cpp

index 28197f9152c3bdcedc0dfe40fedc5178e5de93da..5df9270f3b09d48c344bda1569b84895d92478ab 100644 (file)
@@ -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) {