xref: /aosp_15_r20/external/webrtc/api/video/test/color_space_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "api/video/color_space.h"
12 
13 #include <stdint.h>
14 
15 #include "test/gtest.h"
16 
17 namespace webrtc {
TEST(ColorSpace,TestSettingPrimariesFromUint8)18 TEST(ColorSpace, TestSettingPrimariesFromUint8) {
19   ColorSpace color_space;
20   EXPECT_TRUE(color_space.set_primaries_from_uint8(
21       static_cast<uint8_t>(ColorSpace::PrimaryID::kBT470BG)));
22   EXPECT_EQ(ColorSpace::PrimaryID::kBT470BG, color_space.primaries());
23   EXPECT_FALSE(color_space.set_primaries_from_uint8(3));
24   EXPECT_FALSE(color_space.set_primaries_from_uint8(23));
25   EXPECT_FALSE(color_space.set_primaries_from_uint8(64));
26 }
27 
TEST(ColorSpace,TestSettingTransferFromUint8)28 TEST(ColorSpace, TestSettingTransferFromUint8) {
29   ColorSpace color_space;
30   EXPECT_TRUE(color_space.set_transfer_from_uint8(
31       static_cast<uint8_t>(ColorSpace::TransferID::kBT2020_10)));
32   EXPECT_EQ(ColorSpace::TransferID::kBT2020_10, color_space.transfer());
33   EXPECT_FALSE(color_space.set_transfer_from_uint8(3));
34   EXPECT_FALSE(color_space.set_transfer_from_uint8(19));
35   EXPECT_FALSE(color_space.set_transfer_from_uint8(128));
36 }
37 
TEST(ColorSpace,TestSettingMatrixFromUint8)38 TEST(ColorSpace, TestSettingMatrixFromUint8) {
39   ColorSpace color_space;
40   EXPECT_TRUE(color_space.set_matrix_from_uint8(
41       static_cast<uint8_t>(ColorSpace::MatrixID::kCDNCLS)));
42   EXPECT_EQ(ColorSpace::MatrixID::kCDNCLS, color_space.matrix());
43   EXPECT_FALSE(color_space.set_matrix_from_uint8(3));
44   EXPECT_FALSE(color_space.set_matrix_from_uint8(15));
45   EXPECT_FALSE(color_space.set_matrix_from_uint8(255));
46 }
47 
TEST(ColorSpace,TestSettingRangeFromUint8)48 TEST(ColorSpace, TestSettingRangeFromUint8) {
49   ColorSpace color_space;
50   EXPECT_TRUE(color_space.set_range_from_uint8(
51       static_cast<uint8_t>(ColorSpace::RangeID::kFull)));
52   EXPECT_EQ(ColorSpace::RangeID::kFull, color_space.range());
53   EXPECT_FALSE(color_space.set_range_from_uint8(4));
54 }
55 
TEST(ColorSpace,TestSettingChromaSitingHorizontalFromUint8)56 TEST(ColorSpace, TestSettingChromaSitingHorizontalFromUint8) {
57   ColorSpace color_space;
58   EXPECT_TRUE(color_space.set_chroma_siting_horizontal_from_uint8(
59       static_cast<uint8_t>(ColorSpace::ChromaSiting::kCollocated)));
60   EXPECT_EQ(ColorSpace::ChromaSiting::kCollocated,
61             color_space.chroma_siting_horizontal());
62   EXPECT_FALSE(color_space.set_chroma_siting_horizontal_from_uint8(3));
63 }
64 
TEST(ColorSpace,TestSettingChromaSitingVerticalFromUint8)65 TEST(ColorSpace, TestSettingChromaSitingVerticalFromUint8) {
66   ColorSpace color_space;
67   EXPECT_TRUE(color_space.set_chroma_siting_vertical_from_uint8(
68       static_cast<uint8_t>(ColorSpace::ChromaSiting::kHalf)));
69   EXPECT_EQ(ColorSpace::ChromaSiting::kHalf,
70             color_space.chroma_siting_vertical());
71   EXPECT_FALSE(color_space.set_chroma_siting_vertical_from_uint8(3));
72 }
73 
74 }  // namespace webrtc
75