X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=padding_effect_test.cpp;h=a1a36b9c29e3f6ff22c9dcc3fbd0e40431cf9ef9;hp=8c05a1e65c89f5b77c25c60e6d57ad94f54dc302;hb=6f1efa8348a90a393187c12d70fd10d81bbd2c99;hpb=e92a5ffa19eb67b4db5af1db8559630139073668 diff --git a/padding_effect_test.cpp b/padding_effect_test.cpp index 8c05a1e..a1a36b9 100644 --- a/padding_effect_test.cpp +++ b/padding_effect_test.cpp @@ -1,6 +1,6 @@ -// Unit tests for AlphaMultiplicationEffect. +// Unit tests for PaddingEffect. -#include +#include #include #include "effect_chain.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]; @@ -208,37 +206,6 @@ TEST(PaddingEffectTest, Crop) { expect_equal(expected_data, out_data, 1, 1); } -TEST(PaddingEffectTest, CropFromBottom) { - float data[2 * 2] = { - 1.0f, 0.5f, - 0.8f, 0.3f, - }; - float expected_data[1 * 1] = { - 0.5f, - }; - float out_data[1 * 1]; - - EffectChainTester tester(NULL, 1, 1); - - 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", 1)); - CHECK(effect->set_int("height", 1)); - CHECK(effect->set_float("left", -1.0f)); - CHECK(effect->set_float("top", -1.0f)); - CHECK(effect->set_int("pad_from_bottom", 1)); - - 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, @@ -275,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