Add a unit test for GammaCompressionEffect.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Oct 2012 20:56:13 +0000 (22:56 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Oct 2012 20:56:13 +0000 (22:56 +0200)
gamma_compression_effect_test.cpp [new file with mode: 0644]

diff --git a/gamma_compression_effect_test.cpp b/gamma_compression_effect_test.cpp
new file mode 100644 (file)
index 0000000..4662a01
--- /dev/null
@@ -0,0 +1,68 @@
+// Unit tests for GammaCompressionEffect.
+//
+// Pretty much the inverse of the GammaExpansionEffect tests;
+// EffectChainTest tests that they are actually inverses.
+
+#include "test_util.h"
+#include "gtest/gtest.h"
+#include "gamma_expansion_effect.h"
+
+TEST(GammaCompressionEffectTest, sRGB_KeyValues) {
+       float data[] = {
+               0.0f, 1.0f,
+               0.00309f, 0.00317f,   // On either side of the discontinuity.
+       };
+       float expected_data[] = {
+               0.0f, 1.0f,
+               0.040f, 0.041f,
+       };
+       float out_data[4];
+       EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_sRGB);
+
+       expect_equal(expected_data, out_data, 2, 2);
+}
+
+TEST(GammaCompressionEffectTest, sRGB_RampAlwaysIncreases) {
+       float data[256], out_data[256];
+       for (unsigned i = 0; i < 256; ++i) {
+               data[i] = i / 255.0f;
+       }
+       EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_sRGB);
+
+       for (unsigned i = 1; i < 256; ++i) {
+               EXPECT_GT(out_data[i], out_data[i - 1])
+                  << "No increase between " << i-1 << " and " << i;
+       }
+}
+
+TEST(GammaCompressionEffectTest, Rec709_KeyValues) {
+       float data[] = {
+               0.0f, 1.0f,
+               0.017778f, 0.018167f,  // On either side of the discontinuity.
+       };
+       float expected_data[] = {
+               0.0f, 1.0f,
+               0.080f, 0.082f,
+       };
+       float out_data[4];
+       EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_REC_709);
+
+       expect_equal(expected_data, out_data, 2, 2);
+}
+
+TEST(GammaCompressionEffectTest, 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, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_REC_709);
+
+       for (unsigned i = 1; i < 256; ++i) {
+               EXPECT_GT(out_data[i], out_data[i - 1])
+                  << "No increase between " << i-1 << " and " << i;
+       }
+}