• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 =
43       IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_BT709);
44   ASSERT_NE(iccBt709->getLength(), 0);
45   ASSERT_NE(iccBt709->getData(), nullptr);
46   EXPECT_EQ(IccHelper::readIccColorGamut(iccBt709->getData(), iccBt709->getLength()),
47             ULTRAHDR_COLORGAMUT_BT709);
48 
49   std::shared_ptr<DataStruct> iccP3 =
50       IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_P3);
51   ASSERT_NE(iccP3->getLength(), 0);
52   ASSERT_NE(iccP3->getData(), nullptr);
53   EXPECT_EQ(IccHelper::readIccColorGamut(iccP3->getData(), iccP3->getLength()),
54             ULTRAHDR_COLORGAMUT_P3);
55 
56   std::shared_ptr<DataStruct> iccBt2100 =
57       IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_BT2100);
58   ASSERT_NE(iccBt2100->getLength(), 0);
59   ASSERT_NE(iccBt2100->getData(), nullptr);
60   EXPECT_EQ(IccHelper::readIccColorGamut(iccBt2100->getData(), iccBt2100->getLength()),
61             ULTRAHDR_COLORGAMUT_BT2100);
62 }
63 
TEST_F(IccHelperTest,iccEndianness)64 TEST_F(IccHelperTest, iccEndianness) {
65   std::shared_ptr<DataStruct> icc =
66       IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_BT709);
67   size_t profile_size = icc->getLength() - kICCIdentifierSize;
68 
69   uint8_t* icc_bytes = reinterpret_cast<uint8_t*>(icc->getData()) + kICCIdentifierSize;
70   uint32_t encoded_size =
71       static_cast<uint32_t>(icc_bytes[0]) << 24 | static_cast<uint32_t>(icc_bytes[1]) << 16 |
72       static_cast<uint32_t>(icc_bytes[2]) << 8 | static_cast<uint32_t>(icc_bytes[3]);
73 
74   EXPECT_EQ(static_cast<size_t>(encoded_size), profile_size);
75 }
76 
77 }  // namespace ultrahdr
78