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/mastering_metadata_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::ElementParserTest;
16 using webm::Id;
17 using webm::MasteringMetadata;
18 using webm::MasteringMetadataParser;
19 
20 namespace {
21 
22 class MasteringMetadataParserTest
23     : public ElementParserTest<MasteringMetadataParser,
24                                Id::kMasteringMetadata> {};
25 
TEST_F(MasteringMetadataParserTest,DefaultParse)26 TEST_F(MasteringMetadataParserTest, DefaultParse) {
27   ParseAndVerify();
28 
29   const MasteringMetadata mastering_metadata = parser_.value();
30 
31   EXPECT_FALSE(mastering_metadata.primary_r_chromaticity_x.is_present());
32   EXPECT_EQ(0, mastering_metadata.primary_r_chromaticity_x.value());
33 
34   EXPECT_FALSE(mastering_metadata.primary_r_chromaticity_y.is_present());
35   EXPECT_EQ(0, mastering_metadata.primary_r_chromaticity_y.value());
36 
37   EXPECT_FALSE(mastering_metadata.primary_g_chromaticity_x.is_present());
38   EXPECT_EQ(0, mastering_metadata.primary_g_chromaticity_x.value());
39 
40   EXPECT_FALSE(mastering_metadata.primary_g_chromaticity_y.is_present());
41   EXPECT_EQ(0, mastering_metadata.primary_g_chromaticity_y.value());
42 
43   EXPECT_FALSE(mastering_metadata.primary_b_chromaticity_x.is_present());
44   EXPECT_EQ(0, mastering_metadata.primary_b_chromaticity_x.value());
45 
46   EXPECT_FALSE(mastering_metadata.primary_b_chromaticity_y.is_present());
47   EXPECT_EQ(0, mastering_metadata.primary_b_chromaticity_y.value());
48 
49   EXPECT_FALSE(mastering_metadata.white_point_chromaticity_x.is_present());
50   EXPECT_EQ(0, mastering_metadata.white_point_chromaticity_x.value());
51 
52   EXPECT_FALSE(mastering_metadata.white_point_chromaticity_y.is_present());
53   EXPECT_EQ(0, mastering_metadata.white_point_chromaticity_y.value());
54 
55   EXPECT_FALSE(mastering_metadata.luminance_max.is_present());
56   EXPECT_EQ(0, mastering_metadata.luminance_max.value());
57 
58   EXPECT_FALSE(mastering_metadata.luminance_min.is_present());
59   EXPECT_EQ(0, mastering_metadata.luminance_min.value());
60 }
61 
TEST_F(MasteringMetadataParserTest,DefaultValues)62 TEST_F(MasteringMetadataParserTest, DefaultValues) {
63   SetReaderData({
64       0x55, 0xD1,  // ID = 0x55D1 (PrimaryRChromaticityX).
65       0x80,  // Size = 0.
66 
67       0x55, 0xD2,  // ID = 0x55D2 (PrimaryRChromaticityY).
68       0x80,  // Size = 0.
69 
70       0x55, 0xD3,  // ID = 0x55D3 (PrimaryGChromaticityX).
71       0x80,  // Size = 0.
72 
73       0x55, 0xD4,  // ID = 0x55D4 (PrimaryGChromaticityY).
74       0x80,  // Size = 0.
75 
76       0x55, 0xD5,  // ID = 0x55D5 (PrimaryBChromaticityX).
77       0x80,  // Size = 0.
78 
79       0x55, 0xD6,  // ID = 0x55D6 (PrimaryBChromaticityY).
80       0x80,  // Size = 0.
81 
82       0x55, 0xD7,  // ID = 0x55D7 (WhitePointChromaticityX).
83       0x80,  // Size = 0.
84 
85       0x55, 0xD8,  // ID = 0x55D8 (WhitePointChromaticityY).
86       0x80,  // Size = 0.
87 
88       0x55, 0xD9,  // ID = 0x55D9 (LuminanceMax).
89       0x80,  // Size = 0.
90 
91       0x55, 0xDA,  // ID = 0x55DA (LuminanceMin).
92       0x80,  // Size = 0.
93   });
94 
95   ParseAndVerify();
96 
97   const MasteringMetadata mastering_metadata = parser_.value();
98 
99   EXPECT_TRUE(mastering_metadata.primary_r_chromaticity_x.is_present());
100   EXPECT_EQ(0, mastering_metadata.primary_r_chromaticity_x.value());
101 
102   EXPECT_TRUE(mastering_metadata.primary_r_chromaticity_y.is_present());
103   EXPECT_EQ(0, mastering_metadata.primary_r_chromaticity_y.value());
104 
105   EXPECT_TRUE(mastering_metadata.primary_g_chromaticity_x.is_present());
106   EXPECT_EQ(0, mastering_metadata.primary_g_chromaticity_x.value());
107 
108   EXPECT_TRUE(mastering_metadata.primary_g_chromaticity_y.is_present());
109   EXPECT_EQ(0, mastering_metadata.primary_g_chromaticity_y.value());
110 
111   EXPECT_TRUE(mastering_metadata.primary_b_chromaticity_x.is_present());
112   EXPECT_EQ(0, mastering_metadata.primary_b_chromaticity_x.value());
113 
114   EXPECT_TRUE(mastering_metadata.primary_b_chromaticity_y.is_present());
115   EXPECT_EQ(0, mastering_metadata.primary_b_chromaticity_y.value());
116 
117   EXPECT_TRUE(mastering_metadata.white_point_chromaticity_x.is_present());
118   EXPECT_EQ(0, mastering_metadata.white_point_chromaticity_x.value());
119 
120   EXPECT_TRUE(mastering_metadata.white_point_chromaticity_y.is_present());
121   EXPECT_EQ(0, mastering_metadata.white_point_chromaticity_y.value());
122 
123   EXPECT_TRUE(mastering_metadata.luminance_max.is_present());
124   EXPECT_EQ(0, mastering_metadata.luminance_max.value());
125 
126   EXPECT_TRUE(mastering_metadata.luminance_min.is_present());
127   EXPECT_EQ(0, mastering_metadata.luminance_min.value());
128 }
129 
TEST_F(MasteringMetadataParserTest,CustomValues)130 TEST_F(MasteringMetadataParserTest, CustomValues) {
131   SetReaderData({
132       0x55, 0xD1,  // ID = 0x55D1 (PrimaryRChromaticityX).
133       0x84,  // Size = 4.
134       0x3E, 0x00, 0x00, 0x00,  // Body (value = 0.125).
135 
136       0x55, 0xD2,  // ID = 0x55D2 (PrimaryRChromaticityY).
137       0x84,  // Size = 4.
138       0x3E, 0x80, 0x00, 0x00,  // Body (value = 0.25).
139 
140       0x55, 0xD3,  // ID = 0x55D3 (PrimaryGChromaticityX).
141       0x84,  // Size = 4.
142       0x3E, 0xC0, 0x00, 0x00,  // Body (value = 0.375).
143 
144       0x55, 0xD4,  // ID = 0x55D4 (PrimaryGChromaticityY).
145       0x84,  // Size = 4.
146       0x3F, 0x00, 0x00, 0x00,  // Body (value = 0.5).
147 
148       0x55, 0xD5,  // ID = 0x55D5 (PrimaryBChromaticityX).
149       0x84,  // Size = 4.
150       0x3F, 0x20, 0x00, 0x00,  // Body (value = 0.625).
151 
152       0x55, 0xD6,  // ID = 0x55D6 (PrimaryBChromaticityY).
153       0x84,  // Size = 4.
154       0x3F, 0x40, 0x00, 0x00,  // Body (value = 0.75).
155 
156       0x55, 0xD7,  // ID = 0x55D7 (WhitePointChromaticityX).
157       0x84,  // Size = 4.
158       0x3F, 0x60, 0x00, 0x00,  // Body (value = 0.875).
159 
160       0x55, 0xD8,  // ID = 0x55D8 (WhitePointChromaticityY).
161       0x84,  // Size = 4.
162       0x3F, 0x80, 0x00, 0x00,  // Body (value = 1).
163 
164       0x55, 0xD9,  // ID = 0x55D9 (LuminanceMax).
165       0x84,  // Size = 4.
166       0x40, 0x00, 0x00, 0x00,  // Body (value = 2).
167 
168       0x55, 0xDA,  // ID = 0x55DA (LuminanceMin).
169       0x84,  // Size = 4.
170       0x40, 0x40, 0x00, 0x00,  // Body (value = 3).
171   });
172 
173   ParseAndVerify();
174 
175   const MasteringMetadata mastering_metadata = parser_.value();
176 
177   EXPECT_TRUE(mastering_metadata.primary_r_chromaticity_x.is_present());
178   EXPECT_EQ(0.125, mastering_metadata.primary_r_chromaticity_x.value());
179 
180   EXPECT_TRUE(mastering_metadata.primary_r_chromaticity_y.is_present());
181   EXPECT_EQ(0.25, mastering_metadata.primary_r_chromaticity_y.value());
182 
183   EXPECT_TRUE(mastering_metadata.primary_g_chromaticity_x.is_present());
184   EXPECT_EQ(0.375, mastering_metadata.primary_g_chromaticity_x.value());
185 
186   EXPECT_TRUE(mastering_metadata.primary_g_chromaticity_y.is_present());
187   EXPECT_EQ(0.5, mastering_metadata.primary_g_chromaticity_y.value());
188 
189   EXPECT_TRUE(mastering_metadata.primary_b_chromaticity_x.is_present());
190   EXPECT_EQ(0.625, mastering_metadata.primary_b_chromaticity_x.value());
191 
192   EXPECT_TRUE(mastering_metadata.primary_b_chromaticity_y.is_present());
193   EXPECT_EQ(0.75, mastering_metadata.primary_b_chromaticity_y.value());
194 
195   EXPECT_TRUE(mastering_metadata.white_point_chromaticity_x.is_present());
196   EXPECT_EQ(0.875, mastering_metadata.white_point_chromaticity_x.value());
197 
198   EXPECT_TRUE(mastering_metadata.white_point_chromaticity_y.is_present());
199   EXPECT_EQ(1.0, mastering_metadata.white_point_chromaticity_y.value());
200 
201   EXPECT_TRUE(mastering_metadata.luminance_max.is_present());
202   EXPECT_EQ(2.0, mastering_metadata.luminance_max.value());
203 
204   EXPECT_TRUE(mastering_metadata.luminance_min.is_present());
205   EXPECT_EQ(3.0, mastering_metadata.luminance_min.value());
206 }
207 
208 }  // namespace
209