#include "flat_input.h"
#include "gtest/gtest.h"
#include "mirror_effect.h"
+#include "resize_effect.h"
#include "opengl.h"
#include "test_util.h"
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() {}
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) {
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];