-
Notifications
You must be signed in to change notification settings - Fork 0
/
lift_gamma_gain_effect_test.cpp
122 lines (103 loc) · 3.5 KB
/
lift_gamma_gain_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
115
116
117
118
119
120
121
122
// Unit tests for LiftGammaGainEffect.
#include <epoxy/gl.h>
#include "effect_chain.h"
#include "gtest/gtest.h"
#include "image_format.h"
#include "lift_gamma_gain_effect.h"
#include "test_util.h"
namespace movit {
TEST(LiftGammaGainEffectTest, DefaultIsNoop) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.3f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 0.7f,
0.0f, 0.0f, 1.0f, 1.0f,
};
float out_data[5 * 4];
EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
tester.get_chain()->add_effect(new LiftGammaGainEffect());
tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
expect_equal(data, out_data, 4, 5);
}
TEST(LiftGammaGainEffectTest, Gain) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.3f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 0.7f,
0.0f, 0.0f, 1.0f, 1.0f,
};
float gain[3] = { 0.8f, 1.0f, 1.2f };
float expected_data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
0.4f, 0.5f, 0.6f, 0.3f,
0.8f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 0.7f,
0.0f, 0.0f, 1.2f, 1.0f,
};
float out_data[5 * 4];
EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
ASSERT_TRUE(lgg_effect->set_vec3("gain", gain));
tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
expect_equal(expected_data, out_data, 4, 5);
}
TEST(LiftGammaGainEffectTest, LiftIsDoneInApproximatelysRGB) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.3f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 0.7f,
0.0f, 0.0f, 1.0f, 1.0f,
};
float lift[3] = { 0.0f, 0.1f, 0.2f };
float expected_data[] = {
0.0f, 0.1f , 0.2f, 1.0f,
0.5f, 0.55f, 0.6f, 0.3f,
1.0f, 0.1f, 0.2f, 1.0f,
0.0f, 1.0f, 0.2f, 0.7f,
0.0f, 0.1f, 1.0f, 1.0f,
};
float out_data[5 * 4];
EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
ASSERT_TRUE(lgg_effect->set_vec3("lift", lift));
tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
// sRGB is only approximately gamma-2.2, so loosen up the limits a bit.
expect_equal(expected_data, out_data, 4, 5, 0.03, 0.003);
}
TEST(LiftGammaGainEffectTest, Gamma22IsApproximatelysRGB) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.3f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 0.7f,
0.0f, 0.0f, 1.0f, 1.0f,
};
float gamma[3] = { 2.2f, 2.2f, 2.2f };
float out_data[5 * 4];
EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB);
Effect *lgg_effect = tester.get_chain()->add_effect(new LiftGammaGainEffect());
ASSERT_TRUE(lgg_effect->set_vec3("gamma", gamma));
tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
expect_equal(data, out_data, 4, 5);
}
TEST(LiftGammaGainEffectTest, OutOfGamutColorsAreClipped) {
float data[] = {
-0.5f, 0.3f, 0.0f, 1.0f,
0.5f, 0.0f, 0.0f, 1.0f,
0.0f, 1.5f, 0.5f, 0.3f,
};
float expected_data[] = {
0.0f, 0.3f, 0.0f, 1.0f, // Clipped to zero.
0.5f, 0.0f, 0.0f, 1.0f,
0.0f, 1.5f, 0.5f, 0.3f,
};
float out_data[3 * 4];
EffectChainTester tester(data, 1, 3, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
tester.get_chain()->add_effect(new LiftGammaGainEffect());
tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
expect_equal(expected_data, out_data, 4, 3);
}
} // namespace movit