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 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 #ifndef ENCODE_HEIF_HELPER_FUZZ
16 #define ENCODE_HEIF_HELPER_FUZZ
17 
18 #include <vector>
19 #include "encode_buffer_helper.h"
20 
21 namespace OHOS::VDI::HEIF {
22 enum ImgType {
23     PRIMARY_IMG,
24     AUXILIARY_IMG,
25     THUMBNAIL_IMG,
26     GAIN_MAP,
27     T_MAP
28 };
29 enum MetaType {
30     EXIF_DATA,
31     USER_DATA
32 };
33 class HeifEncodeHelper {
34 public:
HeifEncodeHelper()35     HeifEncodeHelper() {};
~HeifEncodeHelper()36     ~HeifEncodeHelper() {};
37     void Reset();
38     bool AssembleParamForTmap(uint8_t *data, size_t size);
39     bool AssembleParamForPrimaryImg(uint8_t *data, size_t size);
40     bool AssembleParamForOtherImg(uint32_t primaryImgId, uint8_t *data, size_t size);
41     bool AssembleParamForMetaData(uint32_t primaryImgId, uint8_t *data, size_t size);
42     bool FillImageItem(ImgType type, OHOS::HDI::Codec::Image::V2_0::ImageItem& item, uint8_t *data, size_t size);
43     OHOS::HDI::Codec::Image::V2_0::ItemRef FillRefItem(OHOS::HDI::Codec::Image::V2_0::ItemRef item,
44                                                        uint8_t *data, size_t size);
45     bool FillMetaItem(MetaType type, OHOS::HDI::Codec::Image::V2_0::MetaItem& item, uint8_t *data, size_t size);
46     bool AllocOutputBuffer(OHOS::HDI::Codec::Image::V2_0::SharedBuffer& output);
47 public:
48     std::vector<OHOS::HDI::Codec::Image::V2_0::ImageItem> inputImgs_;
49     std::vector<OHOS::HDI::Codec::Image::V2_0::MetaItem> inputMetas_;
50     std::vector<OHOS::HDI::Codec::Image::V2_0::ItemRef> refs_;
51     uint32_t id_ = 0;
52     EncodeBufferHelper bufferHelper_;
53 };
54 } // OHOS::VDI::HEIF
55 #endif // ENCODE_HEIF_HELPER_FUZZ