blob: ff61c0857414d64c449026754d5ed1a349f51d32 [file] [log] [blame]
Nick Deakin0db53ee2023-05-19 17:14:45 -04001/*
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#include <ultrahdr/icc.h>
19#include <ultrahdr/ultrahdr.h>
20#include <utils/Log.h>
21
22namespace android::ultrahdr {
23
24class IccHelperTest : public testing::Test {
25public:
26 IccHelperTest();
27 ~IccHelperTest();
28protected:
29 virtual void SetUp();
30 virtual void TearDown();
31};
32
33IccHelperTest::IccHelperTest() {}
34
35IccHelperTest::~IccHelperTest() {}
36
37void IccHelperTest::SetUp() {}
38
39void IccHelperTest::TearDown() {}
40
41TEST_F(IccHelperTest, iccWriteThenRead) {
42 sp<DataStruct> iccBt709 = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB,
43 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 sp<DataStruct> iccP3 = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_P3);
50 ASSERT_NE(iccP3->getLength(), 0);
51 ASSERT_NE(iccP3->getData(), nullptr);
52 EXPECT_EQ(IccHelper::readIccColorGamut(iccP3->getData(), iccP3->getLength()),
53 ULTRAHDR_COLORGAMUT_P3);
54
55 sp<DataStruct> iccBt2100 = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB,
56 ULTRAHDR_COLORGAMUT_BT2100);
57 ASSERT_NE(iccBt2100->getLength(), 0);
58 ASSERT_NE(iccBt2100->getData(), nullptr);
59 EXPECT_EQ(IccHelper::readIccColorGamut(iccBt2100->getData(), iccBt2100->getLength()),
60 ULTRAHDR_COLORGAMUT_BT2100);
61}
62
63TEST_F(IccHelperTest, iccEndianness) {
64 sp<DataStruct> icc = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_BT709);
65 size_t profile_size = icc->getLength() - kICCIdentifierSize;
66
67 uint8_t* icc_bytes = reinterpret_cast<uint8_t*>(icc->getData()) + kICCIdentifierSize;
68 uint32_t encoded_size = static_cast<uint32_t>(icc_bytes[0]) << 24 |
69 static_cast<uint32_t>(icc_bytes[1]) << 16 |
70 static_cast<uint32_t>(icc_bytes[2]) << 8 |
71 static_cast<uint32_t>(icc_bytes[3]);
72
73 EXPECT_EQ(static_cast<size_t>(encoded_size), profile_size);
74}
75
76} // namespace android::ultrahdr
77