]> git.sesse.net Git - movit/commitdiff
Add unit tests to EffectChain testing that the sRGB conversion on the GPU works.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2012 11:21:01 +0000 (13:21 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2012 11:21:01 +0000 (13:21 +0200)
effect_chain_test.cpp
test_util.cpp
test_util.h

index 778259f7da5ca7961510a9739d9915e491e21698..d8ade1370e06d58669d2c47d1e2ff2c5b0d6f4ae 100644 (file)
@@ -135,6 +135,31 @@ 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,
@@ -239,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];
index 4fba7bb02fe2a58e94dea62f10cb62474eb9b4cd..1730907c5283b405018ffaa9b21dccec013b7ea7 100644 (file)
@@ -7,10 +7,13 @@
 
 #include <algorithm>
 
-EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned height, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve)
+EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned height,
+                                     MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve)
        : chain(width, height), width(width), height(height)
 {
-       add_input(data, pixel_format, color_space, gamma_curve);
+       if (data != NULL) {
+               add_input(data, pixel_format, color_space, gamma_curve);
+       }
 
        glGenTextures(1, &texnum);
        check_error();
@@ -54,6 +57,18 @@ Input *EffectChainTester::add_input(const float *data, MovitPixelFormat pixel_fo
        return input;
 }
 
+Input *EffectChainTester::add_input(const unsigned char *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve)
+{
+       ImageFormat format;
+       format.color_space = color_space;
+       format.gamma_curve = gamma_curve;
+
+       FlatInput *input = new FlatInput(format, pixel_format, GL_UNSIGNED_BYTE, width, height);
+       input->set_pixel_data(data);
+       chain.add_input(input);
+       return input;
+}
+
 void EffectChainTester::run(float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve)
 {
        ImageFormat image_format;
index c66dfa47a0c2b427261034df0f8ff7c5a716515a..2430b8fbf3c0952ea41829866c500be04be33a14 100644 (file)
@@ -5,11 +5,15 @@
 
 class EffectChainTester {
 public:
-       EffectChainTester(const float *data, unsigned width, unsigned height, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve);
+       EffectChainTester(const float *data, unsigned width, unsigned height,
+                         MovitPixelFormat pixel_format = FORMAT_GRAYSCALE,
+                         Colorspace color_space = COLORSPACE_sRGB,
+                         GammaCurve gamma_curve = GAMMA_LINEAR);
        ~EffectChainTester();
        
        EffectChain *get_chain() { return &chain; }
        Input *add_input(const float *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve);
+       Input *add_input(const unsigned char *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve);
        void run(float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve);
 
 private: