]> git.sesse.net Git - movit/blob - diffusion_effect_test.cpp
Put the resample alpha handling on the right effect.
[movit] / diffusion_effect_test.cpp
1 // Unit tests for DiffusionEffect.
2
3 #include "diffusion_effect.h"
4 #include "effect_chain.h"
5 #include "gtest/gtest.h"
6 #include "image_format.h"
7 #include "test_util.h"
8
9 TEST(DiffusionEffectTest, IdentityTransformDoesNothing) {
10         const int size = 4;
11
12         float data[size * size] = {
13                 0.0, 1.0, 0.0, 1.0,
14                 0.0, 1.0, 1.0, 0.0,
15                 0.0, 0.5, 1.0, 0.5,
16                 0.0, 0.0, 0.0, 0.0,
17         };
18         float out_data[size * size];
19
20         EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
21         Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
22         ASSERT_TRUE(diffusion_effect->set_float("radius", 0.0f));
23         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
24
25         expect_equal(data, out_data, size, size);
26 }
27
28 TEST(DiffusionEffectTest, FlattensOutWhitePyramid) {
29         const int size = 9;
30
31         float data[size * size] = {
32                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
33                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
34                 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
35                 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
36                 0.0, 0.0, 0.5, 0.7, 1.0, 0.7, 0.5, 0.0, 0.0,
37                 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
38                 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
39                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
40                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
41         };
42         float expected_data[size * size] = {
43                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
44                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
45                 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
46                 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
47                 0.0, 0.0, 0.4, 0.5, 0.6, 0.5, 0.4, 0.0, 0.0,
48                 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
49                 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
50                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
51                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
52         };
53         float out_data[size * size];
54
55         EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
56         Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
57         ASSERT_TRUE(diffusion_effect->set_float("radius", 2.0f));
58         ASSERT_TRUE(diffusion_effect->set_float("blurred_mix_amount", 0.7f));
59         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
60
61         expect_equal(expected_data, out_data, size, size, 0.05f, 0.002);
62 }