Move to 'using namespace std;' in all .cpp files.
[movit] / padding_effect_test.cpp
index e3f6f41..c9c8ef1 100644 (file)
@@ -1,9 +1,14 @@
 // Unit tests for AlphaMultiplicationEffect.
 
-#include "test_util.h"
+#include <stddef.h>
+
+#include "effect_chain.h"
 #include "flat_input.h"
-#include "padding_effect.h"
 #include "gtest/gtest.h"
+#include "image_format.h"
+#include "padding_effect.h"
+#include "test_util.h"
+#include "util.h"
 
 TEST(PaddingEffectTest, SimpleCenter) {
        float data[2 * 2] = {
@@ -67,7 +72,7 @@ TEST(PaddingEffectTest, WhiteBorderColor) {
        CHECK(effect->set_float("left", 1.0f));
        CHECK(effect->set_float("top", 1.0f));
 
-       RGBATriplet border_color(1.0f, 1.0f, 1.0f, 1.0f);
+       RGBATuple border_color(1.0f, 1.0f, 1.0f, 1.0f);
        CHECK(effect->set_vec4("border_color", (float *)&border_color));
 
        tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
@@ -100,7 +105,7 @@ TEST(PaddingEffectTest, BorderColorIsInLinearGamma) {
        CHECK(effect->set_float("left", 0.0f));
        CHECK(effect->set_float("top", 0.0f));
 
-       RGBATriplet border_color(0.2f, 0.4f, 0.6f, 0.8f);  // Same as the pixel in data[].
+       RGBATuple border_color(0.2f, 0.4f, 0.6f, 0.8f);  // Same as the pixel in data[].
        CHECK(effect->set_vec4("border_color", (float *)&border_color));
 
        tester.run(out_data, GL_RGBA, COLORSPACE_REC_601_625, GAMMA_REC_601, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
@@ -199,3 +204,39 @@ TEST(PaddingEffectTest, Crop) {
        tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
        expect_equal(expected_data, out_data, 1, 1);
 }
+
+TEST(PaddingEffectTest, AlphaIsCorrectEvenWithNonLinearInputsAndOutputs) {
+       float data[2 * 1] = {
+               1.0f,
+               0.8f,
+       };
+       float expected_data[4 * 4] = {
+               1.0f, 1.0f, 1.0f, 0.5f,
+               1.0f, 1.0f, 1.0f, 1.0f,
+               0.8f, 0.8f, 0.8f, 1.0f,
+               1.0f, 1.0f, 1.0f, 0.5f,
+       };
+       float out_data[4 * 4];
+
+       EffectChainTester tester(NULL, 1, 4);
+
+       ImageFormat format;
+       format.color_space = COLORSPACE_REC_601_625;
+       format.gamma_curve = GAMMA_REC_709;
+
+       FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 1, 2);
+       input->set_pixel_data(data);
+       tester.get_chain()->add_input(input);
+
+       Effect *effect = tester.get_chain()->add_effect(new PaddingEffect());
+       CHECK(effect->set_int("width", 1));
+       CHECK(effect->set_int("height", 4));
+       CHECK(effect->set_float("left", 0.0f));
+       CHECK(effect->set_float("top", 1.0f));
+
+       RGBATuple border_color(1.0f, 1.0f, 1.0f, 0.5f);
+       CHECK(effect->set_vec4("border_color", (float *)&border_color));
+
+       tester.run(out_data, GL_RGBA, COLORSPACE_REC_601_625, GAMMA_REC_709, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
+       expect_equal(expected_data, out_data, 4, 4);
+}