xref: /aosp_15_r20/external/libwebm/webm_parser/tests/colour_parser_test.cc (revision 103e46e4cd4b6efcf6001f23fa8665fb110abf8d)
1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #include "src/colour_parser.h"
9 
10 #include "gtest/gtest.h"
11 
12 #include "test_utils/element_parser_test.h"
13 #include "webm/id.h"
14 
15 using webm::Colour;
16 using webm::ColourParser;
17 using webm::ElementParserTest;
18 using webm::Id;
19 using webm::MasteringMetadata;
20 using webm::MatrixCoefficients;
21 using webm::Primaries;
22 using webm::Range;
23 using webm::TransferCharacteristics;
24 
25 namespace {
26 
27 class ColourParserTest : public ElementParserTest<ColourParser, Id::kColour> {};
28 
TEST_F(ColourParserTest,DefaultParse)29 TEST_F(ColourParserTest, DefaultParse) {
30   ParseAndVerify();
31 
32   const Colour colour = parser_.value();
33 
34   EXPECT_FALSE(colour.matrix_coefficients.is_present());
35   EXPECT_EQ(MatrixCoefficients::kUnspecified,
36             colour.matrix_coefficients.value());
37 
38   EXPECT_FALSE(colour.bits_per_channel.is_present());
39   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.bits_per_channel.value());
40 
41   EXPECT_FALSE(colour.chroma_subsampling_x.is_present());
42   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_subsampling_x.value());
43 
44   EXPECT_FALSE(colour.chroma_subsampling_y.is_present());
45   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_subsampling_y.value());
46 
47   EXPECT_FALSE(colour.cb_subsampling_x.is_present());
48   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.cb_subsampling_x.value());
49 
50   EXPECT_FALSE(colour.cb_subsampling_y.is_present());
51   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.cb_subsampling_y.value());
52 
53   EXPECT_FALSE(colour.chroma_siting_x.is_present());
54   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_siting_x.value());
55 
56   EXPECT_FALSE(colour.chroma_siting_y.is_present());
57   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_siting_y.value());
58 
59   EXPECT_FALSE(colour.range.is_present());
60   EXPECT_EQ(Range::kUnspecified, colour.range.value());
61 
62   EXPECT_FALSE(colour.transfer_characteristics.is_present());
63   EXPECT_EQ(TransferCharacteristics::kUnspecified,
64             colour.transfer_characteristics.value());
65 
66   EXPECT_FALSE(colour.primaries.is_present());
67   EXPECT_EQ(Primaries::kUnspecified, colour.primaries.value());
68 
69   EXPECT_FALSE(colour.max_cll.is_present());
70   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.max_cll.value());
71 
72   EXPECT_FALSE(colour.max_fall.is_present());
73   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.max_fall.value());
74 
75   EXPECT_FALSE(colour.mastering_metadata.is_present());
76   EXPECT_EQ(MasteringMetadata{}, colour.mastering_metadata.value());
77 }
78 
TEST_F(ColourParserTest,DefaultValues)79 TEST_F(ColourParserTest, DefaultValues) {
80   SetReaderData({
81       0x55, 0xB1,  // ID = 0x55B1 (MatrixCoefficients).
82       0x80,  // Size = 0.
83 
84       0x55, 0xB2,  // ID = 0x55B2 (BitsPerChannel).
85       0x80,  // Size = 0.
86 
87       0x55, 0xB3,  // ID = 0x55B3 (ChromaSubsamplingHorz).
88       0x80,  // Size = 0.
89 
90       0x55, 0xB4,  // ID = 0x55B4 (ChromaSubsamplingVert).
91       0x80,  // Size = 0.
92 
93       0x55, 0xB5,  // ID = 0x55B5 (CbSubsamplingHorz).
94       0x80,  // Size = 0.
95 
96       0x55, 0xB6,  // ID = 0x55B6 (CbSubsamplingVert).
97       0x80,  // Size = 0.
98 
99       0x55, 0xB7,  // ID = 0x55B7 (ChromaSitingHorz).
100       0x80,  // Size = 0.
101 
102       0x55, 0xB8,  // ID = 0x55B8 (ChromaSitingVert).
103       0x80,  // Size = 0.
104 
105       0x55, 0xB9,  // ID = 0x55B9 (Range).
106       0x80,  // Size = 0.
107 
108       0x55, 0xBA,  // ID = 0x55BA (TransferCharacteristics).
109       0x80,  // Size = 0.
110 
111       0x55, 0xBB,  // ID = 0x55BB (Primaries).
112       0x80,  // Size = 0.
113 
114       0x55, 0xBC,  // ID = 0x55BC (MaxCLL).
115       0x80,  // Size = 0.
116 
117       0x55, 0xBD,  // ID = 0x55BD (MaxFALL).
118       0x80,  // Size = 0.
119 
120       0x55, 0xD0,  // ID = 0x55D0 (MasteringMetadata).
121       0x80,  // Size = 0.
122   });
123 
124   ParseAndVerify();
125 
126   const Colour colour = parser_.value();
127 
128   EXPECT_TRUE(colour.matrix_coefficients.is_present());
129   EXPECT_EQ(MatrixCoefficients::kUnspecified,
130             colour.matrix_coefficients.value());
131 
132   EXPECT_TRUE(colour.bits_per_channel.is_present());
133   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.bits_per_channel.value());
134 
135   EXPECT_TRUE(colour.chroma_subsampling_x.is_present());
136   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_subsampling_x.value());
137 
138   EXPECT_TRUE(colour.chroma_subsampling_y.is_present());
139   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_subsampling_y.value());
140 
141   EXPECT_TRUE(colour.cb_subsampling_x.is_present());
142   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.cb_subsampling_x.value());
143 
144   EXPECT_TRUE(colour.cb_subsampling_y.is_present());
145   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.cb_subsampling_y.value());
146 
147   EXPECT_TRUE(colour.chroma_siting_x.is_present());
148   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_siting_x.value());
149 
150   EXPECT_TRUE(colour.chroma_siting_y.is_present());
151   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.chroma_siting_y.value());
152 
153   EXPECT_TRUE(colour.range.is_present());
154   EXPECT_EQ(Range::kUnspecified, colour.range.value());
155 
156   EXPECT_TRUE(colour.transfer_characteristics.is_present());
157   EXPECT_EQ(TransferCharacteristics::kUnspecified,
158             colour.transfer_characteristics.value());
159 
160   EXPECT_TRUE(colour.primaries.is_present());
161   EXPECT_EQ(Primaries::kUnspecified, colour.primaries.value());
162 
163   EXPECT_TRUE(colour.max_cll.is_present());
164   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.max_cll.value());
165 
166   EXPECT_TRUE(colour.max_fall.is_present());
167   EXPECT_EQ(static_cast<std::uint64_t>(0), colour.max_fall.value());
168 
169   EXPECT_TRUE(colour.mastering_metadata.is_present());
170   EXPECT_EQ(MasteringMetadata{}, colour.mastering_metadata.value());
171 }
172 
TEST_F(ColourParserTest,CustomValues)173 TEST_F(ColourParserTest, CustomValues) {
174   SetReaderData({
175       0x55, 0xB1,  // ID = 0x55B1 (MatrixCoefficients).
176       0x81,  // Size = 1.
177       0x01,  // Body (value = BT.709).
178 
179       0x55, 0xB2,  // ID = 0x55B2 (BitsPerChannel).
180       0x81,  // Size = 1.
181       0x02,  // Body (value = 2).
182 
183       0x55, 0xB3,  // ID = 0x55B3 (ChromaSubsamplingHorz).
184       0x81,  // Size = 1.
185       0x03,  // Body (value = 3).
186 
187       0x55, 0xB4,  // ID = 0x55B4 (ChromaSubsamplingVert).
188       0x81,  // Size = 1.
189       0x04,  // Body (value = 4).
190 
191       0x55, 0xB5,  // ID = 0x55B5 (CbSubsamplingHorz).
192       0x81,  // Size = 1.
193       0x05,  // Body (value = 5).
194 
195       0x55, 0xB6,  // ID = 0x55B6 (CbSubsamplingVert).
196       0x81,  // Size = 1.
197       0x06,  // Body (value = 6).
198 
199       0x55, 0xB7,  // ID = 0x55B7 (ChromaSitingHorz).
200       0x81,  // Size = 1.
201       0x01,  // Body (value = 1).
202 
203       0x55, 0xB8,  // ID = 0x55B8 (ChromaSitingVert).
204       0x81,  // Size = 1.
205       0x02,  // Body (value = 2).
206 
207       0x55, 0xB9,  // ID = 0x55B9 (Range).
208       0x81,  // Size = 1.
209       0x03,  // Body (value = 3 (derived)).
210 
211       0x55, 0xBA,  // ID = 0x55BA (TransferCharacteristics).
212       0x81,  // Size = 1.
213       0x04,  // Body (value = BT.470‑6 System M with display gamma 2.2).
214 
215       0x55, 0xBB,  // ID = 0x55BB (Primaries).
216       0x81,  // Size = 1.
217       0x05,  // Body (value =  BT.470‑6 System B, G).
218 
219       0x55, 0xBC,  // ID = 0x55BC (MaxCLL).
220       0x81,  // Size = 1.
221       0x06,  // Body (value = 6).
222 
223       0x55, 0xBD,  // ID = 0x55BD (MaxFALL).
224       0x81,  // Size = 1.
225       0x07,  // Body (value = 7).
226 
227       0x55, 0xD0,  // ID = 0x55D0 (MasteringMetadata).
228       0x87,  // Size = 7.
229 
230       0x55, 0xD1,  //   ID = 0x55D1 (PrimaryRChromaticityX).
231       0x84,  //   Size = 4.
232       0x3F, 0x80, 0x00, 0x00,  //   Body (value = 1).
233   });
234 
235   ParseAndVerify();
236 
237   const Colour colour = parser_.value();
238 
239   EXPECT_TRUE(colour.matrix_coefficients.is_present());
240   EXPECT_EQ(MatrixCoefficients::kBt709, colour.matrix_coefficients.value());
241 
242   EXPECT_TRUE(colour.bits_per_channel.is_present());
243   EXPECT_EQ(static_cast<std::uint64_t>(2), colour.bits_per_channel.value());
244 
245   EXPECT_TRUE(colour.chroma_subsampling_x.is_present());
246   EXPECT_EQ(static_cast<std::uint64_t>(3), colour.chroma_subsampling_x.value());
247 
248   EXPECT_TRUE(colour.chroma_subsampling_y.is_present());
249   EXPECT_EQ(static_cast<std::uint64_t>(4), colour.chroma_subsampling_y.value());
250 
251   EXPECT_TRUE(colour.cb_subsampling_x.is_present());
252   EXPECT_EQ(static_cast<std::uint64_t>(5), colour.cb_subsampling_x.value());
253 
254   EXPECT_TRUE(colour.cb_subsampling_y.is_present());
255   EXPECT_EQ(static_cast<std::uint64_t>(6), colour.cb_subsampling_y.value());
256 
257   EXPECT_TRUE(colour.chroma_siting_x.is_present());
258   EXPECT_EQ(static_cast<std::uint64_t>(1), colour.chroma_siting_x.value());
259 
260   EXPECT_TRUE(colour.chroma_siting_y.is_present());
261   EXPECT_EQ(static_cast<std::uint64_t>(2), colour.chroma_siting_y.value());
262 
263   EXPECT_TRUE(colour.range.is_present());
264   EXPECT_EQ(Range::kDerived, colour.range.value());
265 
266   EXPECT_TRUE(colour.transfer_characteristics.is_present());
267   EXPECT_EQ(TransferCharacteristics::kGamma22curve,
268             colour.transfer_characteristics.value());
269 
270   EXPECT_TRUE(colour.primaries.is_present());
271   EXPECT_EQ(Primaries::kBt470Bg, colour.primaries.value());
272 
273   EXPECT_TRUE(colour.max_cll.is_present());
274   EXPECT_EQ(static_cast<std::uint64_t>(6), colour.max_cll.value());
275 
276   EXPECT_TRUE(colour.max_fall.is_present());
277   EXPECT_EQ(static_cast<std::uint64_t>(7), colour.max_fall.value());
278 
279   MasteringMetadata mastering_metadata{};
280   mastering_metadata.primary_r_chromaticity_x.Set(1.0, true);
281   EXPECT_TRUE(colour.mastering_metadata.is_present());
282   EXPECT_EQ(mastering_metadata, colour.mastering_metadata.value());
283 }
284 
285 }  // namespace
286