X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=blur_effect_test.cpp;h=1c9193dfaa10cf8a600e05dd44a91eace3e88ba8;hp=4114bcbc45bff018a271f8d360b388bbde85bca6;hb=refs%2Fheads%2F1.3.x-release;hpb=9651a4eaae012cdc49c1aa38197861e04f62e91e diff --git a/blur_effect_test.cpp b/blur_effect_test.cpp index 4114bcb..1c9193d 100644 --- a/blur_effect_test.cpp +++ b/blur_effect_test.cpp @@ -1,5 +1,5 @@ // Unit tests for BlurEffect. -#include +#include #include #include @@ -9,6 +9,8 @@ #include "image_format.h" #include "test_util.h" +namespace movit { + TEST(BlurEffectTest, IdentityTransformDoesNothing) { const int size = 4; @@ -20,12 +22,15 @@ TEST(BlurEffectTest, IdentityTransformDoesNothing) { }; float out_data[size * size]; - EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); - Effect *blur_effect = tester.get_chain()->add_effect(new BlurEffect()); - ASSERT_TRUE(blur_effect->set_float("radius", 0.0f)); - tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); + for (int num_taps = 2; num_taps < 20; num_taps += 2) { + EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); + Effect *blur_effect = tester.get_chain()->add_effect(new BlurEffect()); + ASSERT_TRUE(blur_effect->set_float("radius", 0.0f)); + ASSERT_TRUE(blur_effect->set_int("num_taps", num_taps)); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); - expect_equal(data, out_data, size, size); + expect_equal(data, out_data, size, size); + } } namespace { @@ -99,3 +104,33 @@ TEST(BlurEffectTest, BlurTwoDotsLargeRadius) { expect_equal(expected_data, out_data, size, size, 0.1f, 1e-3); } + +TEST(BlurEffectTest, BlurTwoDotsSmallRadiusFewerTaps) { + const float sigma = 3.0f; + const int size = 32; + const int x1 = 8; + const int y1 = 8; + const int x2 = 20; + const int y2 = 10; + + float data[size * size], out_data[size * size], expected_data[size * size]; + memset(data, 0, sizeof(data)); + memset(expected_data, 0, sizeof(expected_data)); + + data[y1 * size + x1] = 1.0f; + data[y2 * size + x2] = 1.0f; + + add_blurred_point(expected_data, size, x1, y1, 1.0f, sigma); + add_blurred_point(expected_data, size, x2, y2, 1.0f, sigma); + + EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); + Effect *blur_effect = tester.get_chain()->add_effect(new BlurEffect()); + ASSERT_TRUE(blur_effect->set_float("radius", sigma)); + ASSERT_TRUE(blur_effect->set_int("num_taps", 10)); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); + + // Set the limits a bit tighter than usual, since there is so little energy in here. + expect_equal(expected_data, out_data, size, size, 1e-3, 1e-5); +} + +} // namespace movit