1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_HEIF_PARSER_ITEM_PROPERTY_COLOR_BOX_H
17 #define PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_HEIF_PARSER_ITEM_PROPERTY_COLOR_BOX_H
18 
19 #include "box/heif_box.h"
20 
21 namespace OHOS {
22 namespace ImagePlugin {
23 class HeifColorProfile {
24 public:
25     virtual ~HeifColorProfile() = default;
26 
27     virtual uint32_t GetProfileType() const = 0;
28 
29     virtual heif_error Write(HeifStreamWriter& writer) const = 0;
30 };
31 
32 class HeifRawColorProfile : public HeifColorProfile {
33 public:
HeifRawColorProfile(uint32_t type,const std::vector<uint8_t> & data)34     HeifRawColorProfile(uint32_t type, const std::vector<uint8_t>& data) : profileType_(type), data_(data) {}
35 
GetProfileType()36     uint32_t GetProfileType() const override { return profileType_; }
37 
GetData()38     const std::vector<uint8_t>& GetData() const { return data_; }
39 
40     heif_error Write(HeifStreamWriter& writer) const override;
41 
42 private:
43     uint32_t profileType_;
44     std::vector<uint8_t> data_;
45 };
46 
47 
48 class HeifNclxColorProfile : public HeifColorProfile {
49 public:
HeifNclxColorProfile(uint16_t colorPrimaries,uint16_t transferCharacteristics,uint16_t matrixCoefficients,uint8_t fullRangeFlag)50     HeifNclxColorProfile(uint16_t colorPrimaries, uint16_t transferCharacteristics,
51         uint16_t matrixCoefficients, uint8_t fullRangeFlag)
52         : colorPrimaries_(colorPrimaries), transferCharacteristics_(transferCharacteristics),
53         matrixCoefficients_(matrixCoefficients), fullRangeFlag_(fullRangeFlag) {};
54 
GetProfileType()55     uint32_t GetProfileType() const override { return BOX_TYPE_NCLX; }
56 
57     heif_error Write(HeifStreamWriter& writer) const override;
GetColorPrimaries()58     uint16_t GetColorPrimaries() const { return colorPrimaries_; };
GetTransferCharacteristics()59     uint16_t GetTransferCharacteristics() const { return transferCharacteristics_; };
GetMatrixCoefficients()60     uint16_t GetMatrixCoefficients() const { return matrixCoefficients_; };
GetFullRangeFlag()61     uint8_t GetFullRangeFlag() const { return fullRangeFlag_; };
62 
63 private:
64     const static uint16_t NCLX_DATA_UNSPECIFIED = 2;
65     uint16_t colorPrimaries_ = NCLX_DATA_UNSPECIFIED;
66     uint16_t transferCharacteristics_ = NCLX_DATA_UNSPECIFIED;
67     uint16_t matrixCoefficients_ = NCLX_DATA_UNSPECIFIED;
68     uint8_t fullRangeFlag_ = 1;
69 };
70 
71 class HeifColrBox : public HeifBox {
72 public:
HeifColrBox()73     HeifColrBox() : HeifBox(BOX_TYPE_COLR) {}
74 
GetColorProfileType()75     uint32_t GetColorProfileType() const { return colorProfile_->GetProfileType(); }
76 
GetColorProfile()77     const std::shared_ptr<const HeifColorProfile>& GetColorProfile() const { return colorProfile_; }
78 
SetColorProfile(const std::shared_ptr<const HeifColorProfile> & prof)79     void SetColorProfile(const std::shared_ptr<const HeifColorProfile>& prof) { colorProfile_ = prof; }
80 
81     heif_error Write(HeifStreamWriter& writer) const override;
82 
83 protected:
84     heif_error ParseContent(HeifStreamReader& reader) override;
85 
86 private:
87     std::shared_ptr<const HeifColorProfile> colorProfile_;
88 };
89 } // namespace ImagePlugin
90 } // namespace OHOS
91 
92 #endif // PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_HEIF_PARSER_ITEM_PROPERTY_COLOR_BOX_H
93