]> git.sesse.net Git - movit/blobdiff - blur_effect_test.cpp
Do some IEEE trickery to help the shader optimizer remove a sub or two in some YCbCr...
[movit] / blur_effect_test.cpp
index 1ef479ec478d8a9be52ac3f70d87a46be761bd62..1c9193dfaa10cf8a600e05dd44a91eace3e88ba8 100644 (file)
@@ -1,5 +1,5 @@
 // Unit tests for BlurEffect.
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 #include <math.h>
 #include <string.h>
 
@@ -22,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 {
@@ -102,4 +105,32 @@ 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