]> git.sesse.net Git - movit/commitdiff
Fix a bug where DeconvolutionSharpenEffect would forget one line of the kernel.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 29 Dec 2013 22:55:57 +0000 (23:55 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 29 Dec 2013 22:55:57 +0000 (23:55 +0100)
This manifested itself in that non-identity filters would start changing alpha
of solid images (since the kernel didn't sum up to one), which obviously isn't
good. Added a unit test to make sure it doesn't happen again.

deconvolution_sharpen_effect.frag
deconvolution_sharpen_effect_test.cpp

index 90ca3c1efd967df06a1656bf6c22aeebb19bf0d1..4b4b18f163b6e272a677a61ec51e070b8d01680e 100644 (file)
@@ -36,7 +36,7 @@ vec4 FUNCNAME(vec2 tc) {
        // Case D: All other samples have four-way symmetry.
        // (Actually we have eight-way, but since we are using normalized
        // coordinates, we can't just flip x and y.)
-       for (int y = 1; y < R; ++y) {
+       for (int y = 1; y <= R; ++y) {
                for (int x = 1; x <= R; ++x) {
                        vec4 sample = PREFIX(samples)[y * (R + 1) + x];
                        vec2 mirror_sample = vec2(sample.x, -sample.y);
index 6980b3d16b34bac262789ec2bf9632c690e9d3cb..8daeb675969397bb3be460911e5b8491d0b3e78b 100644 (file)
@@ -199,3 +199,35 @@ TEST(DeconvolutionSharpenEffectTest, NoiseAndCorrelationControlsReduceNoiseBoost
        // Check that we didn't boost total energy (which in this case means the noise) more than 10%.
        EXPECT_LT(sumsq_out, sumsq_in * 1.1f);
 }
+
+TEST(DeconvolutionSharpenEffectTest, CircularDeconvolutionKeepsAlpha) {
+       // Somewhat bigger, to make sure we are much bigger than the matrix size.
+       const int size = 32;
+
+       float data[size * size * 4];
+       float out_data[size * size];
+       float expected_alpha[size * size];
+
+       // Checkerbox pattern.
+       for (int y = 0; y < size; ++y) {
+               for (int x = 0; x < size; ++x) {
+                       int c = (y ^ x) & 1;
+                       data[(y * size + x) * 4 + 0] = c;
+                       data[(y * size + x) * 4 + 1] = c;
+                       data[(y * size + x) * 4 + 2] = c;
+                       data[(y * size + x) * 4 + 3] = 1.0;
+                       expected_alpha[y * size + x] = 1.0;
+               }
+       }
+
+       EffectChainTester tester(data, size, size, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *deconvolution_effect = tester.get_chain()->add_effect(new DeconvolutionSharpenEffect());
+       ASSERT_TRUE(deconvolution_effect->set_int("matrix_size", 5));
+       ASSERT_TRUE(deconvolution_effect->set_float("circle_radius", 2.0f));
+       ASSERT_TRUE(deconvolution_effect->set_float("gaussian_radius", 0.0f));
+       ASSERT_TRUE(deconvolution_effect->set_float("correlation", 0.0001f));
+       ASSERT_TRUE(deconvolution_effect->set_float("noise", 0.0f));
+       tester.run(out_data, GL_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_alpha, out_data, size, size);
+}