-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcolorspace_conversion_effect_test.cpp
284 lines (238 loc) · 10 KB
/
colorspace_conversion_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// Unit tests for ColorspaceConversionEffect.
#include <epoxy/gl.h>
#include "colorspace_conversion_effect.h"
#include "gtest/gtest.h"
#include "test_util.h"
namespace movit {
TEST(ColorspaceConversionEffectTest, Reversible) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 0.5f,
};
float temp_data[4 * 6], out_data[4 * 6];
{
EffectChainTester tester(data, 1, 6, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
tester.run(temp_data, GL_RGBA, COLORSPACE_REC_601_525, GAMMA_LINEAR);
}
{
EffectChainTester tester(temp_data, 1, 6, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_REC_601_525, GAMMA_LINEAR);
tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
}
expect_equal(data, out_data, 4, 6);
}
TEST(ColorspaceConversionEffectTest, sRGB_Primaries) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
};
float out_data[4 * 5];
EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
tester.run(out_data, GL_RGBA, COLORSPACE_XYZ, GAMMA_LINEAR);
// Black should stay black.
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 0]);
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 1]);
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 2]);
EXPECT_FLOAT_EQ(1.0f, out_data[0 * 4 + 3]);
// White point should be D65.
// XYZ values from http://en.wikipedia.org/wiki/CIE_Standard_Illuminant_D65.
EXPECT_NEAR(0.9505, out_data[1 * 4 + 0], 1e-3);
EXPECT_NEAR(1.0000, out_data[1 * 4 + 1], 1e-3);
EXPECT_NEAR(1.0889, out_data[1 * 4 + 2], 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[1 * 4 + 3]);
float white_xyz_sum = out_data[1 * 4 + 0] + out_data[1 * 4 + 1] + out_data[1 * 4 + 2];
float white_x = out_data[1 * 4 + 0] / white_xyz_sum;
float white_y = out_data[1 * 4 + 1] / white_xyz_sum;
EXPECT_NEAR(0.3127, white_x, 1e-3);
EXPECT_NEAR(0.3290, white_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[1 * 4 + 3]);
// Convert the primaries from XYZ to xyz, and compare to the references
// given by Rec. 709 (which are shared with sRGB).
float red_xyz_sum = out_data[2 * 4 + 0] + out_data[2 * 4 + 1] + out_data[2 * 4 + 2];
float red_x = out_data[2 * 4 + 0] / red_xyz_sum;
float red_y = out_data[2 * 4 + 1] / red_xyz_sum;
EXPECT_NEAR(0.640, red_x, 1e-3);
EXPECT_NEAR(0.330, red_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[2 * 4 + 3]);
float green_xyz_sum = out_data[3 * 4 + 0] + out_data[3 * 4 + 1] + out_data[3 * 4 + 2];
float green_x = out_data[3 * 4 + 0] / green_xyz_sum;
float green_y = out_data[3 * 4 + 1] / green_xyz_sum;
EXPECT_NEAR(0.300, green_x, 1e-3);
EXPECT_NEAR(0.600, green_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[3 * 4 + 3]);
float blue_xyz_sum = out_data[4 * 4 + 0] + out_data[4 * 4 + 1] + out_data[4 * 4 + 2];
float blue_x = out_data[4 * 4 + 0] / blue_xyz_sum;
float blue_y = out_data[4 * 4 + 1] / blue_xyz_sum;
EXPECT_NEAR(0.150, blue_x, 1e-3);
EXPECT_NEAR(0.060, blue_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[4 * 4 + 3]);
}
TEST(ColorspaceConversionEffectTest, Rec601_525_Primaries) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
};
float out_data[4 * 5];
EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_REC_601_525, GAMMA_LINEAR);
tester.run(out_data, GL_RGBA, COLORSPACE_XYZ, GAMMA_LINEAR);
// Black should stay black.
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 0]);
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 1]);
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 2]);
EXPECT_FLOAT_EQ(1.0f, out_data[0 * 4 + 3]);
// Convert the primaries from XYZ to xyz, and compare to the references
// given by Rec. 601.
float white_xyz_sum = out_data[1 * 4 + 0] + out_data[1 * 4 + 1] + out_data[1 * 4 + 2];
float white_x = out_data[1 * 4 + 0] / white_xyz_sum;
float white_y = out_data[1 * 4 + 1] / white_xyz_sum;
EXPECT_NEAR(0.3127, white_x, 1e-3);
EXPECT_NEAR(0.3290, white_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[1 * 4 + 3]);
float red_xyz_sum = out_data[2 * 4 + 0] + out_data[2 * 4 + 1] + out_data[2 * 4 + 2];
float red_x = out_data[2 * 4 + 0] / red_xyz_sum;
float red_y = out_data[2 * 4 + 1] / red_xyz_sum;
EXPECT_NEAR(0.630, red_x, 1e-3);
EXPECT_NEAR(0.340, red_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[2 * 4 + 3]);
float green_xyz_sum = out_data[3 * 4 + 0] + out_data[3 * 4 + 1] + out_data[3 * 4 + 2];
float green_x = out_data[3 * 4 + 0] / green_xyz_sum;
float green_y = out_data[3 * 4 + 1] / green_xyz_sum;
EXPECT_NEAR(0.310, green_x, 1e-3);
EXPECT_NEAR(0.595, green_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[3 * 4 + 3]);
float blue_xyz_sum = out_data[4 * 4 + 0] + out_data[4 * 4 + 1] + out_data[4 * 4 + 2];
float blue_x = out_data[4 * 4 + 0] / blue_xyz_sum;
float blue_y = out_data[4 * 4 + 1] / blue_xyz_sum;
EXPECT_NEAR(0.155, blue_x, 1e-3);
EXPECT_NEAR(0.070, blue_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[4 * 4 + 3]);
}
TEST(ColorspaceConversionEffectTest, Rec601_625_Primaries) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
};
float out_data[4 * 5];
EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_REC_601_625, GAMMA_LINEAR);
tester.run(out_data, GL_RGBA, COLORSPACE_XYZ, GAMMA_LINEAR);
// Black should stay black.
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 0]);
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 1]);
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 2]);
EXPECT_FLOAT_EQ(1.0f, out_data[0 * 4 + 3]);
// Convert the primaries from XYZ to xyz, and compare to the references
// given by Rec. 601.
float white_xyz_sum = out_data[1 * 4 + 0] + out_data[1 * 4 + 1] + out_data[1 * 4 + 2];
float white_x = out_data[1 * 4 + 0] / white_xyz_sum;
float white_y = out_data[1 * 4 + 1] / white_xyz_sum;
EXPECT_NEAR(0.3127, white_x, 1e-3);
EXPECT_NEAR(0.3290, white_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[1 * 4 + 3]);
float red_xyz_sum = out_data[2 * 4 + 0] + out_data[2 * 4 + 1] + out_data[2 * 4 + 2];
float red_x = out_data[2 * 4 + 0] / red_xyz_sum;
float red_y = out_data[2 * 4 + 1] / red_xyz_sum;
EXPECT_NEAR(0.640, red_x, 1e-3);
EXPECT_NEAR(0.330, red_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[2 * 4 + 3]);
float green_xyz_sum = out_data[3 * 4 + 0] + out_data[3 * 4 + 1] + out_data[3 * 4 + 2];
float green_x = out_data[3 * 4 + 0] / green_xyz_sum;
float green_y = out_data[3 * 4 + 1] / green_xyz_sum;
EXPECT_NEAR(0.290, green_x, 1e-3);
EXPECT_NEAR(0.600, green_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[3 * 4 + 3]);
float blue_xyz_sum = out_data[4 * 4 + 0] + out_data[4 * 4 + 1] + out_data[4 * 4 + 2];
float blue_x = out_data[4 * 4 + 0] / blue_xyz_sum;
float blue_y = out_data[4 * 4 + 1] / blue_xyz_sum;
EXPECT_NEAR(0.150, blue_x, 1e-3);
EXPECT_NEAR(0.060, blue_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[4 * 4 + 3]);
}
TEST(ColorspaceConversionEffectTest, Rec2020_Primaries) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
};
float out_data[4 * 5];
EffectChainTester tester(data, 1, 5, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_REC_2020, GAMMA_LINEAR);
tester.run(out_data, GL_RGBA, COLORSPACE_XYZ, GAMMA_LINEAR);
// Black should stay black.
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 0]);
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 1]);
EXPECT_FLOAT_EQ(0.0f, out_data[0 * 4 + 2]);
EXPECT_FLOAT_EQ(1.0f, out_data[0 * 4 + 3]);
// Convert the primaries from XYZ to xyz, and compare to the references
// given by Rec. 2020.
float white_xyz_sum = out_data[1 * 4 + 0] + out_data[1 * 4 + 1] + out_data[1 * 4 + 2];
float white_x = out_data[1 * 4 + 0] / white_xyz_sum;
float white_y = out_data[1 * 4 + 1] / white_xyz_sum;
EXPECT_NEAR(0.3127, white_x, 1e-3);
EXPECT_NEAR(0.3290, white_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[1 * 4 + 3]);
float red_xyz_sum = out_data[2 * 4 + 0] + out_data[2 * 4 + 1] + out_data[2 * 4 + 2];
float red_x = out_data[2 * 4 + 0] / red_xyz_sum;
float red_y = out_data[2 * 4 + 1] / red_xyz_sum;
EXPECT_NEAR(0.708, red_x, 1e-3);
EXPECT_NEAR(0.292, red_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[2 * 4 + 3]);
float green_xyz_sum = out_data[3 * 4 + 0] + out_data[3 * 4 + 1] + out_data[3 * 4 + 2];
float green_x = out_data[3 * 4 + 0] / green_xyz_sum;
float green_y = out_data[3 * 4 + 1] / green_xyz_sum;
EXPECT_NEAR(0.170, green_x, 1e-3);
EXPECT_NEAR(0.797, green_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[3 * 4 + 3]);
float blue_xyz_sum = out_data[4 * 4 + 0] + out_data[4 * 4 + 1] + out_data[4 * 4 + 2];
float blue_x = out_data[4 * 4 + 0] / blue_xyz_sum;
float blue_y = out_data[4 * 4 + 1] / blue_xyz_sum;
EXPECT_NEAR(0.131, blue_x, 1e-3);
EXPECT_NEAR(0.046, blue_y, 1e-3);
EXPECT_FLOAT_EQ(1.0f, out_data[4 * 4 + 3]);
}
TEST(ColorspaceConversionEffectTest, sRGBToRec601_525) {
float data[] = {
0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 0.5f,
};
// I have to admit that most of these come from the code itself;
// however, they do make sense if you look at the two gamuts
// in xy space.
float expected_data[] = {
// Black should stay black.
0.0f, 0.0f, 0.0f, 1.0f,
// White should stay white (both use the D65 white point).
1.0f, 1.0f, 1.0f, 1.0f,
// sRGB red is slightly out-of-gamut for Rec. 601/525.
1.064f, -0.020f, 0.0f, 1.0f,
// Green too.
-0.055f, 1.036f, 0.004f, 1.0f,
// The blues are much closer; it _is_ still out-of-gamut,
// but not actually more saturated (farther from the
// white point).
-0.010f, -0.017f, 0.994f, 1.0f,
// Cyan is a mix of green and blue. Note: The alpha is kept.
-0.065f, 1.0195f, 0.998f, 0.5f,
};
float out_data[4 * 6];
EffectChainTester tester(data, 1, 6, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
tester.run(out_data, GL_RGBA, COLORSPACE_REC_601_525, GAMMA_LINEAR);
expect_equal(expected_data, out_data, 4, 6);
}
} // namespace movit