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
16#ifndef OHOS_HDI_CODEC_IMAGE_V2_0_CODEC_HEIF_HELPER
17#define OHOS_HDI_CODEC_IMAGE_V2_0_CODEC_HEIF_HELPER
18
19#include <vector>
20#include "command_parser.h"
21#include "buffer_helper.h"
22
23namespace OHOS::VDI::HEIF {
24class HeifEncoderHelper {
25public:
26    explicit HeifEncoderHelper(const CommandOpt& opt) : encodeOpt_(opt) {}
27    ~HeifEncoderHelper() = default;
28    void DoEncode();
29private:
30    enum ImgType {
31        PRIMARY_IMG,
32        AUXILIARY_IMG,
33        THUMBNAIL_IMG,
34        GAIN_MAP,
35        T_MAP
36    };
37    enum MetaType {
38        EXIF_DATA,
39        USER_DATA
40    };
41private:
42    void Reset();
43    bool AssembleParamForTmap();
44    bool AssembleParamForPrimaryImg();
45    bool AssembleParamForOtherImg(uint32_t primaryImgId);
46    bool AssembleParamForMetaData(uint32_t primaryImgId);
47    uint32_t GetNextId() { return id_++; }
48    bool FillImageItem(ImgType type, OHOS::HDI::Codec::Image::V2_0::ImageItem& item);
49    bool FillMetaItem(const std::string& metaFile, MetaType type, OHOS::HDI::Codec::Image::V2_0::MetaItem& item);
50    static bool AddPropOnlyForTmap(ByteWriter& bw);
51    bool AddPropMirrorAndRotate(ByteWriter& bw);
52    bool CreateImgParam(ImgType type, std::vector<uint8_t>& props);
53    bool AllocOutputBuffer(OHOS::HDI::Codec::Image::V2_0::SharedBuffer& output);
54private:
55    CommandOpt encodeOpt_;
56    std::vector<OHOS::HDI::Codec::Image::V2_0::ImageItem> inputImgs_;
57    std::vector<OHOS::HDI::Codec::Image::V2_0::MetaItem> inputMetas_;
58    std::vector<OHOS::HDI::Codec::Image::V2_0::ItemRef> refs_;
59    uint32_t id_ = 0;
60    BufferHelper bufferHelper_;
61};
62} // OHOS::VDI::HEIF
63#endif // OHOS_HDI_CODEC_IMAGE_V2_0_CODEC_HEIF_HELPER