Add a unit test for LiftGammaGainEffect.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2012 19:04:05 +0000 (21:04 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2012 19:04:05 +0000 (21:04 +0200)
.gitignore
Makefile
lift_gamma_gain_effect_test.cpp [new file with mode: 0644]

index a5589c9..b79e6d3 100644 (file)
@@ -19,5 +19,6 @@ blur_effect_test
 unsharp_mask_effect_test
 diffusion_effect_test
 white_balance_effect_test
+lift_gamma_gain_effect_test
 flat_input_test
 chain-*.frag
index 427e7dd..d068f6c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ TESTS += blur_effect_test
 TESTS += unsharp_mask_effect_test
 TESTS += diffusion_effect_test
 TESTS += white_balance_effect_test
+TESTS += lift_gamma_gain_effect_test
 TESTS += flat_input_test
 
 # Core.
@@ -86,6 +87,8 @@ diffusion_effect_test: diffusion_effect_test.o $(TEST_OBJS) libmovit.a
        $(CXX) -o $@ $^ $(LDFLAGS)
 white_balance_effect_test: white_balance_effect_test.o $(TEST_OBJS) libmovit.a
        $(CXX) -o $@ $^ $(LDFLAGS)
+lift_gamma_gain_effect_test: lift_gamma_gain_effect_test.o $(TEST_OBJS) libmovit.a
+       $(CXX) -o $@ $^ $(LDFLAGS)
 flat_input_test: flat_input_test.o $(TEST_OBJS) libmovit.a
        $(CXX) -o $@ $^ $(LDFLAGS)
 
diff --git a/lift_gamma_gain_effect_test.cpp b/lift_gamma_gain_effect_test.cpp
new file mode 100644 (file)
index 0000000..00c96ca
--- /dev/null
@@ -0,0 +1,94 @@
+// Unit tests for LiftGammaGainEffect.
+
+#include "test_util.h"
+#include "gtest/gtest.h"
+#include "lift_gamma_gain_effect.h"
+
+TEST(LiftGammaGainEffectTest, DefaultIsNoop) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               1.0f, 0.0f, 0.0f, 1.0f,
+               0.0f, 1.0f, 0.0f, 0.7f,
+               0.0f, 0.0f, 1.0f, 1.0f,
+       };
+
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.get_chain()->add_effect(new LiftGammaGainEffect());
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 4, 5);
+}
+
+TEST(LiftGammaGainEffectTest, Gain) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               1.0f, 0.0f, 0.0f, 1.0f,
+               0.0f, 1.0f, 0.0f, 0.7f,
+               0.0f, 0.0f, 1.0f, 1.0f,
+       };
+       float gain[3] = { 0.8f, 1.0f, 1.2f };
+       float expected_data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.4f, 0.5f, 0.6f, 0.3f,
+               0.8f, 0.0f, 0.0f, 1.0f,
+               0.0f, 1.0f, 0.0f, 0.7f,
+               0.0f, 0.0f, 1.2f, 1.0f,
+       };
+
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
+       ASSERT_TRUE(lgg_effect->set_vec3("gain", gain));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 4, 5);
+}
+
+TEST(LiftGammaGainEffectTest, LiftIsDoneInApproximatelysRGB) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               1.0f, 0.0f, 0.0f, 1.0f,
+               0.0f, 1.0f, 0.0f, 0.7f,
+               0.0f, 0.0f, 1.0f, 1.0f,
+       };
+       float lift[3] = { 0.0f, 0.1f, 0.2f };
+       float expected_data[] = {
+               0.0f, 0.1f , 0.2f, 1.0f,
+               0.5f, 0.55f, 0.6f, 0.3f,
+               1.0f, 0.1f,  0.2f, 1.0f,
+               0.0f, 1.0f,  0.2f, 0.7f,
+               0.0f, 0.1f,  1.0f, 1.0f,
+       };
+
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
+       Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
+       ASSERT_TRUE(lgg_effect->set_vec3("lift", lift));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
+
+       // sRGB is only approximately gamma-2.2, so loosen up the limits a bit.
+       expect_equal(expected_data, out_data, 4, 5, 0.03, 0.003);
+}
+
+TEST(LiftGammaGainEffectTest, Gamma22IsApproximatelysRGB) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               1.0f, 0.0f, 0.0f, 1.0f,
+               0.0f, 1.0f, 0.0f, 0.7f,
+               0.0f, 0.0f, 1.0f, 1.0f,
+       };
+       float gamma[3] = { 2.2f, 2.2f, 2.2f };
+
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
+       Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
+       ASSERT_TRUE(lgg_effect->set_vec3("gamma", gamma));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 4, 5);
+}