]> git.sesse.net Git - movit/blob - diffusion_effect_test.cpp
There's no need to #undef PREFIX, since we do the token pasting ourselves.
[movit] / diffusion_effect_test.cpp
1 // Unit tests for DiffusionEffect.
2
3 #include <epoxy/gl.h>
4
5 #include "diffusion_effect.h"
6 #include "effect_chain.h"
7 #include "gtest/gtest.h"
8 #include "image_format.h"
9 #include "test_util.h"
10
11 namespace movit {
12
13 TEST(DiffusionEffectTest, IdentityTransformDoesNothing) {
14         const int size = 4;
15
16         float data[size * size] = {
17                 0.0, 1.0, 0.0, 1.0,
18                 0.0, 1.0, 1.0, 0.0,
19                 0.0, 0.5, 1.0, 0.5,
20                 0.0, 0.0, 0.0, 0.0,
21         };
22         float out_data[size * size];
23
24         EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
25         Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
26         ASSERT_TRUE(diffusion_effect->set_float("radius", 0.0f));
27         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
28
29         expect_equal(data, out_data, size, size);
30 }
31
32 TEST(DiffusionEffectTest, FlattensOutWhitePyramid) {
33         const int size = 9;
34
35         float data[size * size] = {
36                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
37                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
40                 0.0, 0.0, 0.5, 0.7, 1.0, 0.7, 0.5, 0.0, 0.0,
41                 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
42                 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
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         };
46         float expected_data[size * size] = {
47                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
48                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
51                 0.0, 0.0, 0.4, 0.5, 0.6, 0.5, 0.4, 0.0, 0.0,
52                 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
53                 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
54                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
55                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
56         };
57         float out_data[size * size];
58
59         EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
60         Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
61         ASSERT_TRUE(diffusion_effect->set_float("radius", 2.0f));
62         ASSERT_TRUE(diffusion_effect->set_float("blurred_mix_amount", 0.7f));
63         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
64
65         expect_equal(expected_data, out_data, size, size, 0.05f, 0.002);
66 }
67
68 }  // namespace movit