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_BOX_H
17 #define PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_HEIF_PARSER_ITEM_PROPERTY_BOX_H
18 
19 #include "box/heif_box.h"
20 
21 namespace OHOS {
22 namespace ImagePlugin {
23 struct PropertyAssociation {
24     bool essential;
25     uint16_t propertyIndex;
26 };
27 
28 struct PropertyEntry {
29     heif_item_id itemId;
30     std::vector<PropertyAssociation> associations;
31 };
32 
33 class HeifIprpBox : public HeifBox {
34 public:
HeifIprpBox()35     HeifIprpBox() : HeifBox(BOX_TYPE_IPRP) {}
36 
37 protected:
38     heif_error ParseContentChildren(HeifStreamReader &reader, uint32_t &recursionCount) override;
39 };
40 
41 class HeifIpcoBox : public HeifBox {
42 public:
HeifIpcoBox()43     HeifIpcoBox() : HeifBox(BOX_TYPE_IPCO) {}
44 
45     heif_error GetProperties(heif_item_id itemId,
46                         const std::shared_ptr<class HeifIpmaBox> &,
47                         std::vector<std::shared_ptr<HeifBox>> &outProperties) const;
48 
49     std::shared_ptr<HeifBox> GetProperty(heif_item_id itemId,
50                                          const std::shared_ptr<class HeifIpmaBox> &,
51                                          uint32_t boxType) const;
52 
53 protected:
54     heif_error ParseContentChildren(HeifStreamReader &reader, uint32_t &recursionCount) override;
55 };
56 
57 class HeifIpmaBox : public HeifFullBox {
58 public:
HeifIpmaBox()59     HeifIpmaBox() : HeifFullBox(BOX_TYPE_IPMA) {}
60 
61     const std::vector<PropertyAssociation> *GetProperties(heif_item_id itemId) const;
62 
63     void AddProperty(heif_item_id itemId,
64                      PropertyAssociation assoc);
65 
66     void InferFullBoxVersion() override;
67 
68     heif_error Write(HeifStreamWriter &writer) const override;
69 
70     void MergeImpaBoxes(const HeifIpmaBox &b);
71 
72 protected:
73     heif_error ParseContent(HeifStreamReader &reader) override;
74 
75     std::vector<PropertyEntry> entries_;
76 };
77 } // namespace ImagePlugin
78 } // namespace OHOS
79 
80 #endif // PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_HEIF_PARSER_ITEM_PROPERTY_BOX_H
81