Move to 'using namespace std;' in all .cpp files.
[movit] / lift_gamma_gain_effect_test.cpp
index 00c96ca..9850ba2 100644 (file)
@@ -1,8 +1,10 @@
 // Unit tests for LiftGammaGainEffect.
 
-#include "test_util.h"
+#include "effect_chain.h"
 #include "gtest/gtest.h"
+#include "image_format.h"
 #include "lift_gamma_gain_effect.h"
+#include "test_util.h"
 
 TEST(LiftGammaGainEffectTest, DefaultIsNoop) {
        float data[] = {
@@ -14,7 +16,7 @@ TEST(LiftGammaGainEffectTest, DefaultIsNoop) {
        };
 
        float out_data[5 * 4];
-       EffectChainTester tester(data, 1, 5, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
        tester.get_chain()->add_effect(new LiftGammaGainEffect());
        tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
 
@@ -39,7 +41,7 @@ TEST(LiftGammaGainEffectTest, Gain) {
        };
 
        float out_data[5 * 4];
-       EffectChainTester tester(data, 1, 5, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, 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);
@@ -65,7 +67,7 @@ TEST(LiftGammaGainEffectTest, LiftIsDoneInApproximatelysRGB) {
        };
 
        float out_data[5 * 4];
-       EffectChainTester tester(data, 1, 5, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, 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);
@@ -85,10 +87,30 @@ TEST(LiftGammaGainEffectTest, Gamma22IsApproximatelysRGB) {
        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);
+       EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, 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);
 }
+
+TEST(LiftGammaGainEffectTest, OutOfGamutColorsAreClipped) {
+       float data[] = {
+               -0.5f, 0.3f, 0.0f, 1.0f,
+                0.5f, 0.0f, 0.0f, 1.0f,
+                0.0f, 1.5f, 0.5f, 0.3f,
+       };
+       float expected_data[] = {
+                0.0f, 0.3f, 0.0f, 1.0f,  // Clipped to zero.
+                0.5f, 0.0f, 0.0f, 1.0f,
+                0.0f, 1.5f, 0.5f, 0.3f,
+       };
+
+       float out_data[3 * 4];
+       EffectChainTester tester(data, 1, 3, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.get_chain()->add_effect(new LiftGammaGainEffect());
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 4, 3);
+}