X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=padding_effect_test.cpp;h=a1a36b9c29e3f6ff22c9dcc3fbd0e40431cf9ef9;hp=88ba811e7020a6525e7ed7c6511e4f6088dd2170;hb=6f1efa8348a90a393187c12d70fd10d81bbd2c99;hpb=fbb1247a1996c6dbe54114eb5cc23dc79e17099c diff --git a/padding_effect_test.cpp b/padding_effect_test.cpp index 88ba811..a1a36b9 100644 --- a/padding_effect_test.cpp +++ b/padding_effect_test.cpp @@ -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