aboutsummaryrefslogtreecommitdiff
path: root/api/video/test/color_space_unittest.cc
blob: ae66b018f5f130ebdc2429d6598ed9f1360e01b7 (plain)
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
/*
 *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "api/video/color_space.h"

#include <stdint.h>

#include "test/gtest.h"

namespace webrtc {
TEST(ColorSpace, TestSettingPrimariesFromUint8) {
  ColorSpace color_space;
  EXPECT_TRUE(color_space.set_primaries_from_uint8(
      static_cast<uint8_t>(ColorSpace::PrimaryID::kBT470BG)));
  EXPECT_EQ(ColorSpace::PrimaryID::kBT470BG, color_space.primaries());
  EXPECT_FALSE(color_space.set_primaries_from_uint8(3));
  EXPECT_FALSE(color_space.set_primaries_from_uint8(23));
  EXPECT_FALSE(color_space.set_primaries_from_uint8(64));
}

TEST(ColorSpace, TestSettingTransferFromUint8) {
  ColorSpace color_space;
  EXPECT_TRUE(color_space.set_transfer_from_uint8(
      static_cast<uint8_t>(ColorSpace::TransferID::kBT2020_10)));
  EXPECT_EQ(ColorSpace::TransferID::kBT2020_10, color_space.transfer());
  EXPECT_FALSE(color_space.set_transfer_from_uint8(3));
  EXPECT_FALSE(color_space.set_transfer_from_uint8(19));
  EXPECT_FALSE(color_space.set_transfer_from_uint8(128));
}

TEST(ColorSpace, TestSettingMatrixFromUint8) {
  ColorSpace color_space;
  EXPECT_TRUE(color_space.set_matrix_from_uint8(
      static_cast<uint8_t>(ColorSpace::MatrixID::kCDNCLS)));
  EXPECT_EQ(ColorSpace::MatrixID::kCDNCLS, color_space.matrix());
  EXPECT_FALSE(color_space.set_matrix_from_uint8(3));
  EXPECT_FALSE(color_space.set_matrix_from_uint8(15));
  EXPECT_FALSE(color_space.set_matrix_from_uint8(255));
}

TEST(ColorSpace, TestSettingRangeFromUint8) {
  ColorSpace color_space;
  EXPECT_TRUE(color_space.set_range_from_uint8(
      static_cast<uint8_t>(ColorSpace::RangeID::kFull)));
  EXPECT_EQ(ColorSpace::RangeID::kFull, color_space.range());
  EXPECT_FALSE(color_space.set_range_from_uint8(4));
}

TEST(ColorSpace, TestSettingChromaSitingHorizontalFromUint8) {
  ColorSpace color_space;
  EXPECT_TRUE(color_space.set_chroma_siting_horizontal_from_uint8(
      static_cast<uint8_t>(ColorSpace::ChromaSiting::kCollocated)));
  EXPECT_EQ(ColorSpace::ChromaSiting::kCollocated,
            color_space.chroma_siting_horizontal());
  EXPECT_FALSE(color_space.set_chroma_siting_horizontal_from_uint8(3));
}

TEST(ColorSpace, TestSettingChromaSitingVerticalFromUint8) {
  ColorSpace color_space;
  EXPECT_TRUE(color_space.set_chroma_siting_vertical_from_uint8(
      static_cast<uint8_t>(ColorSpace::ChromaSiting::kHalf)));
  EXPECT_EQ(ColorSpace::ChromaSiting::kHalf,
            color_space.chroma_siting_vertical());
  EXPECT_FALSE(color_space.set_chroma_siting_vertical_from_uint8(3));
}

TEST(ColorSpace, TestAsStringFunction) {
  ColorSpace color_space(
      ColorSpace::PrimaryID::kBT709, ColorSpace::TransferID::kBT709,
      ColorSpace::MatrixID::kBT709, ColorSpace::RangeID::kLimited);
  EXPECT_EQ(
      color_space.AsString(),
      "{primaries:kBT709, transfer:kBT709, matrix:kBT709, range:kLimited}");
}

}  // namespace webrtc