]> git.sesse.net Git - movit/commitdiff
Add unit tests for GlowEffect.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 19 Jan 2013 22:11:33 +0000 (23:11 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 19 Jan 2013 22:11:33 +0000 (23:11 +0100)
Makefile
glow_effect.h
glow_effect_test.cpp [new file with mode: 0644]

index 306a730adef46fed79efae373d4640dac13506e1..8bfaf9fa6c5bac3796388c16cf3ed68d852ec3bb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -41,6 +41,7 @@ TESTS += saturation_effect_test
 TESTS += deconvolution_sharpen_effect_test
 TESTS += blur_effect_test
 TESTS += unsharp_mask_effect_test
 TESTS += deconvolution_sharpen_effect_test
 TESTS += blur_effect_test
 TESTS += unsharp_mask_effect_test
+TESTS += glow_effect_test
 TESTS += diffusion_effect_test
 TESTS += white_balance_effect_test
 TESTS += lift_gamma_gain_effect_test
 TESTS += diffusion_effect_test
 TESTS += white_balance_effect_test
 TESTS += lift_gamma_gain_effect_test
index c0ac9ce5ee4163516ee2806557196447786099a7..8b21e521a9449979aae90ad7df14ef903f8c6b34 100644 (file)
@@ -3,9 +3,6 @@
 
 // Glow: Cut out the highlights of the image (everything above a certain threshold),
 // blur them, and overlay them onto the original image.
 
 // Glow: Cut out the highlights of the image (everything above a certain threshold),
 // blur them, and overlay them onto the original image.
-//
-// FIXME: This might be broken after MixEffect started working in premultiplied alpha.
-// We need to think about how this is going to work, and then add a test.
 
 #include "effect.h"
 
 
 #include "effect.h"
 
diff --git a/glow_effect_test.cpp b/glow_effect_test.cpp
new file mode 100644 (file)
index 0000000..77c9d12
--- /dev/null
@@ -0,0 +1,107 @@
+// Unit tests for GlowEffect.
+
+#include <math.h>
+
+#include "test_util.h"
+#include "gtest/gtest.h"
+#include "glow_effect.h"
+
+TEST(GlowEffectTest, NoAmountDoesNothing) {
+       const int size = 4;
+
+       float data[size * size] = {
+               0.0, 1.0, 0.0, 1.0,
+               0.0, 1.0, 1.0, 0.0,
+               0.0, 0.5, 1.0, 0.5,
+               0.0, 0.0, 0.0, 0.0,
+       };
+       float out_data[size * size];
+
+       EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *glow_effect = tester.get_chain()->add_effect(new GlowEffect());
+       ASSERT_TRUE(glow_effect->set_float("radius", 2.0f));
+       ASSERT_TRUE(glow_effect->set_float("blurred_mix_amount", 0.0f));
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, size, size);
+}
+
+TEST(GlowEffectTest, SingleDot) {
+       const int size = 13;
+       const float sigma = 0.5f;
+       const float amount = 0.2f;
+
+       float data[] = {  // One single dot in the middle.
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+       };
+       float expected_data[size * size], out_data[size * size];
+
+       // The output should be equal to the input, plus approximately a logistic blob.
+       // From http://en.wikipedia.org/wiki/Logistic_distribution#Alternative_parameterization.
+       const float c1 = M_PI / (sigma * 4 * sqrt(3.0f));
+       const float c2 = M_PI / (sigma * 2.0 * sqrt(3.0f));
+
+       for (int y = 0; y < size; ++y) {
+               for (int x = 0; x < size; ++x) {
+                       float xd = c2 * (x - 6);
+                       float yd = c2 * (y - 6);
+                       expected_data[y * size + x] = data[y * size + x] +
+                               (amount * c1 * c1) / (cosh(xd) * cosh(xd) * cosh(yd) * cosh(yd));
+               }
+       }
+
+       EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *glow_effect = tester.get_chain()->add_effect(new GlowEffect());
+       ASSERT_TRUE(glow_effect->set_float("radius", sigma));
+       ASSERT_TRUE(glow_effect->set_float("blurred_mix_amount", amount));
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, size, size, 0.1f, 1e-3);
+}
+
+TEST(GlowEffectTest, GlowsOntoZeroAlpha) {
+       const int size = 7;
+       const float sigma = 1.0f;
+       const float amount = 1.0f;
+
+       float data[4 * size] = {
+               0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0,
+               0.0, 1.0, 0.0, 0.5,
+               0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0,
+       };
+       float expected_data[4 * size] = {
+               0.0, 1.0, 0.0, 0.002, 
+               0.0, 1.0, 0.0, 0.014,
+               0.0, 1.0, 0.0, 0.065, 
+               0.0, 1.0, 0.0, 0.635, 
+               0.0, 1.0, 0.0, 0.065, 
+               0.0, 1.0, 0.0, 0.014,
+               0.0, 1.0, 0.0, 0.002, 
+       };
+
+       float out_data[4 * size];
+
+       EffectChainTester tester(data, 1, size, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *glow_effect = tester.get_chain()->add_effect(new GlowEffect());
+       ASSERT_TRUE(glow_effect->set_float("radius", sigma));
+       ASSERT_TRUE(glow_effect->set_float("blurred_mix_amount", amount));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 4, size);
+}