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