]> git.sesse.net Git - movit/blobdiff - padding_effect_test.cpp
In ResampleEffect, precompute the Lanczos function into a table.
[movit] / padding_effect_test.cpp
index dd836ea066ee527dd6f5af3aaa6c4415eeebe28b..a1a36b9c29e3f6ff22c9dcc3fbd0e40431cf9ef9 100644 (file)
@@ -1,4 +1,4 @@
-// Unit tests for AlphaMultiplicationEffect.
+// Unit tests for PaddingEffect.
 
 #include <epoxy/gl.h>
 #include <stddef.h>
@@ -150,10 +150,8 @@ TEST(PaddingEffectTest, NonIntegerOffset) {
        float data[4 * 1] = {
                0.25f, 0.50f, 0.75f, 1.0f,
        };
-       // Note that the first pixel is completely blank, since the cutoff goes
-       // at the immediate left of the texel.
        float expected_data[5 * 2] = {
-               0.0f, 0.4375f, 0.6875f, 0.9375f, 0.0f,
+               0.1875f, 0.4375f, 0.6875f, 0.9375f, 0.25f,
                0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
        };
        float out_data[5 * 2];
@@ -244,4 +242,72 @@ TEST(PaddingEffectTest, AlphaIsCorrectEvenWithNonLinearInputsAndOutputs) {
        expect_equal(expected_data, out_data, 4, 4);
 }
 
+TEST(PaddingEffectTest, BorderOffsetTopAndBottom) {
+       float data[2 * 2] = {
+               1.0f, 0.5f,
+               0.8f, 0.3f,
+       };
+       float expected_data[4 * 4] = {
+               0.0f, 0.000f, 0.000f, 0.0f,
+               0.0f, 0.750f, 0.375f, 0.0f,
+               0.0f, 0.800f, 0.300f, 0.0f,
+               0.0f, 0.200f, 0.075f, 0.0f,  // Repeated pixels, 25% opacity.
+       };
+       float out_data[4 * 4];
+
+        EffectChainTester tester(NULL, 4, 4);
+
+       ImageFormat format;
+       format.color_space = COLORSPACE_sRGB;
+       format.gamma_curve = GAMMA_LINEAR;
+
+       FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 2, 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", 4));
+       CHECK(effect->set_int("height", 4));
+       CHECK(effect->set_float("left", 1.0f));
+       CHECK(effect->set_float("top", 1.0f));
+       CHECK(effect->set_float("border_offset_top", 0.25f));
+       CHECK(effect->set_float("border_offset_bottom", 0.25f));
+
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
+       expect_equal(expected_data, out_data, 4, 4);
+}
+
+TEST(PaddingEffectTest, BorderOffsetLeftAndRight) {
+       float data[3 * 2] = {
+               1.0f, 0.5f, 0.6f,
+               0.8f, 0.3f, 0.2f,
+       };
+       float expected_data[4 * 2] = {
+               0.750f, 0.5f, 0.3f, 0.0f,
+               0.600f, 0.3f, 0.1f, 0.0f
+       };
+       float out_data[4 * 2];
+
+        EffectChainTester tester(NULL, 4, 2);
+
+       ImageFormat format;
+       format.color_space = COLORSPACE_sRGB;
+       format.gamma_curve = GAMMA_LINEAR;
+
+       FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 3, 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", 4));
+       CHECK(effect->set_int("height", 2));
+       CHECK(effect->set_float("left", 0.0f));
+       CHECK(effect->set_float("top", 0.0f));
+       CHECK(effect->set_float("border_offset_left", 0.25f));
+       CHECK(effect->set_float("border_offset_right", -0.5f));
+
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
+       expect_equal(expected_data, out_data, 4, 2);
+}
+
 }  // namespace movit