-
Notifications
You must be signed in to change notification settings - Fork 9
/
glow_effect_test.cpp
114 lines (95 loc) · 3.79 KB
/
glow_effect_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Unit tests for GlowEffect.
#include <epoxy/gl.h>
#include <math.h>
#include "effect_chain.h"
#include "glow_effect.h"
#include "gtest/gtest.h"
#include "image_format.h"
#include "test_util.h"
namespace movit {
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);
}
} // namespace movit