]> git.sesse.net Git - movit/blobdiff - gamma_expansion_effect_test.cpp
Run include-what-you-use over all of movit. Some hand tuning.
[movit] / gamma_expansion_effect_test.cpp
index 0fd9a71dd57518e8b28fba15268a7690fa2754b6..6fc0252c8c5a28780e7d6127790a0e942543a9f5 100644 (file)
@@ -1,8 +1,10 @@
 // Unit tests for GammaExpansionEffect.
 
-#include "test_util.h"
-#include "gtest/gtest.h"
+#include <GL/glew.h>
+
 #include "gamma_expansion_effect.h"
+#include "gtest/gtest.h"
+#include "test_util.h"
 
 TEST(GammaExpansionEffectTest, sRGB_KeyValues) {
        float data[] = {
@@ -14,8 +16,8 @@ TEST(GammaExpansionEffectTest, sRGB_KeyValues) {
                0.00309f, 0.00317f, 
        };
        float out_data[4];
-       EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_sRGB);
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+       EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
 
        expect_equal(expected_data, out_data, 2, 2);
 }
@@ -25,11 +27,71 @@ TEST(GammaExpansionEffectTest, sRGB_RampAlwaysIncreases) {
        for (unsigned i = 0; i < 256; ++i) {
                data[i] = i / 255.0f;
        }
-       EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_sRGB);
-       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+       EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
 
        for (unsigned i = 1; i < 256; ++i) {
                EXPECT_GT(out_data[i], out_data[i - 1])
                   << "No increase between " << i-1 << " and " << i;
        }
 }
+
+TEST(GammaExpansionEffectTest, sRGB_AlphaIsUnchanged) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 0.0f,
+               0.0f, 0.0f, 0.0f, 0.25f,
+               0.0f, 0.0f, 0.0f, 0.5f,
+               0.0f, 0.0f, 0.0f, 0.75f,
+               0.0f, 0.0f, 0.0f, 1.0f,
+       };
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 5, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 5, 1);
+}
+
+TEST(GammaExpansionEffectTest, Rec709_KeyValues) {
+       float data[] = {
+               0.0f, 1.0f,
+               0.080f, 0.082f,  // On either side of the discontinuity.
+       };
+       float expected_data[] = {
+               0.0f, 1.0f,
+               0.017778f, 0.018167f,
+       };
+       float out_data[4];
+       EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_709);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 2, 2);
+}
+
+TEST(GammaExpansionEffectTest, Rec709_RampAlwaysIncreases) {
+       float data[256], out_data[256];
+       for (unsigned i = 0; i < 256; ++i) {
+               data[i] = i / 255.0f;
+       }
+       EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_REC_709);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       for (unsigned i = 1; i < 256; ++i) {
+               EXPECT_GT(out_data[i], out_data[i - 1])
+                  << "No increase between " << i-1 << " and " << i;
+       }
+}
+
+TEST(GammaExpansionEffectTest, Rec709_AlphaIsUnchanged) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 0.0f,
+               0.0f, 0.0f, 0.0f, 0.25f,
+               0.0f, 0.0f, 0.0f, 0.5f,
+               0.0f, 0.0f, 0.0f, 0.75f,
+               0.0f, 0.0f, 0.0f, 1.0f,
+       };
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 5, 1, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_REC_709);
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 5, 1);
+}