X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=deconvolution_sharpen_effect_test.cpp;h=8829b9da21de959685e7346cf7b4374a16b2e936;hp=ec78968dad3cb25798f93bf99da506be7680ef80;hb=09c983894685554b41f622dadd40ac1a4efc527d;hpb=51ad3870e0b89d5f07b6b81bc551b00b69d78161 diff --git a/deconvolution_sharpen_effect_test.cpp b/deconvolution_sharpen_effect_test.cpp index ec78968..8829b9d 100644 --- a/deconvolution_sharpen_effect_test.cpp +++ b/deconvolution_sharpen_effect_test.cpp @@ -1,10 +1,18 @@ // Unit tests for DeconvolutionSharpenEffect. -#include "test_util.h" -#include "gtest/gtest.h" +#include +#include +#include + #include "deconvolution_sharpen_effect.h" +#include "effect_chain.h" +#include "gtest/gtest.h" +#include "image_format.h" +#include "test_util.h" + +namespace movit { -TEST(DeconvolutionSharpenEffect, IdentityTransformDoesNothing) { +TEST(DeconvolutionSharpenEffectTest, IdentityTransformDoesNothing) { const int size = 4; float data[size * size] = { @@ -27,7 +35,7 @@ TEST(DeconvolutionSharpenEffect, IdentityTransformDoesNothing) { expect_equal(data, out_data, size, size); } -TEST(DeconvolutionSharpenEffect, DeconvolvesCircularBlur) { +TEST(DeconvolutionSharpenEffectTest, DeconvolvesCircularBlur) { const int size = 13; // Matches exactly a circular blur kernel with radius 2.0. @@ -76,7 +84,7 @@ TEST(DeconvolutionSharpenEffect, DeconvolvesCircularBlur) { expect_equal(expected_data, out_data, size, size, 0.15f, 0.005f); } -TEST(DeconvolutionSharpenEffect, DeconvolvesGaussianBlur) { +TEST(DeconvolutionSharpenEffectTest, DeconvolvesGaussianBlur) { const int size = 13; const float sigma = 0.5f; @@ -125,7 +133,7 @@ TEST(DeconvolutionSharpenEffect, DeconvolvesGaussianBlur) { expect_equal(expected_data, out_data, size, size); } -TEST(DeconvolutionSharpenEffect, NoiseAndCorrelationControlsReduceNoiseBoosting) { +TEST(DeconvolutionSharpenEffectTest, NoiseAndCorrelationControlsReduceNoiseBoosting) { const int size = 13; const float sigma = 0.5f; @@ -194,3 +202,37 @@ TEST(DeconvolutionSharpenEffect, NoiseAndCorrelationControlsReduceNoiseBoosting) // 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); +} + +} // namespace movit