1 /*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <gtest/gtest.h>
18
19 #include "ultrahdr/icc.h"
20
21 namespace ultrahdr {
22
23 class IccHelperTest : public testing::Test {
24 public:
25 IccHelperTest();
26 ~IccHelperTest();
27
28 protected:
29 virtual void SetUp();
30 virtual void TearDown();
31 };
32
IccHelperTest()33 IccHelperTest::IccHelperTest() {}
34
~IccHelperTest()35 IccHelperTest::~IccHelperTest() {}
36
SetUp()37 void IccHelperTest::SetUp() {}
38
TearDown()39 void IccHelperTest::TearDown() {}
40
TEST_F(IccHelperTest,iccWriteThenRead)41 TEST_F(IccHelperTest, iccWriteThenRead) {
42 std::shared_ptr<DataStruct> iccBt709 = IccHelper::writeIccProfile(UHDR_CT_SRGB, UHDR_CG_BT_709);
43 ASSERT_NE(iccBt709->getLength(), 0);
44 ASSERT_NE(iccBt709->getData(), nullptr);
45 EXPECT_EQ(IccHelper::readIccColorGamut(iccBt709->getData(), iccBt709->getLength()),
46 UHDR_CG_BT_709);
47
48 std::shared_ptr<DataStruct> iccP3 = IccHelper::writeIccProfile(UHDR_CT_SRGB, UHDR_CG_DISPLAY_P3);
49 ASSERT_NE(iccP3->getLength(), 0);
50 ASSERT_NE(iccP3->getData(), nullptr);
51 EXPECT_EQ(IccHelper::readIccColorGamut(iccP3->getData(), iccP3->getLength()), UHDR_CG_DISPLAY_P3);
52
53 std::shared_ptr<DataStruct> iccBt2100 = IccHelper::writeIccProfile(UHDR_CT_SRGB, UHDR_CG_BT_2100);
54 ASSERT_NE(iccBt2100->getLength(), 0);
55 ASSERT_NE(iccBt2100->getData(), nullptr);
56 EXPECT_EQ(IccHelper::readIccColorGamut(iccBt2100->getData(), iccBt2100->getLength()),
57 UHDR_CG_BT_2100);
58 }
59
TEST_F(IccHelperTest,iccEndianness)60 TEST_F(IccHelperTest, iccEndianness) {
61 std::shared_ptr<DataStruct> icc = IccHelper::writeIccProfile(UHDR_CT_SRGB, UHDR_CG_BT_709);
62 size_t profile_size = icc->getLength() - kICCIdentifierSize;
63
64 uint8_t* icc_bytes = reinterpret_cast<uint8_t*>(icc->getData()) + kICCIdentifierSize;
65 uint32_t encoded_size =
66 static_cast<uint32_t>(icc_bytes[0]) << 24 | static_cast<uint32_t>(icc_bytes[1]) << 16 |
67 static_cast<uint32_t>(icc_bytes[2]) << 8 | static_cast<uint32_t>(icc_bytes[3]);
68
69 EXPECT_EQ(static_cast<size_t>(encoded_size), profile_size);
70 }
71
72 } // namespace ultrahdr
73