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#include "adapter/ohos/osal/image_packer_ohos.h"
17
18#include "base/image/pixel_map.h"
19
20namespace OHOS::Ace {
21RefPtr<ImagePacker> ImagePacker::Create()
22{
23    return MakeRefPtr<ImagePackerOhos>();
24}
25
26ImagePackerOhos::ImagePackerOhos()
27{
28    imagePacker_ = std::make_unique<Media::ImagePacker>();
29}
30
31uint32_t ImagePackerOhos::AddImage(PixelMap& pixelMap)
32{
33    return imagePacker_->AddImage(*(pixelMap.GetPixelMapSharedPtr()));
34}
35
36uint32_t ImagePackerOhos::StartPacking(uint8_t* data, uint32_t maxSize, const PackOption& option)
37{
38    Media::PackOption packOption {option.format, option.quality, option.numberHint};
39    return imagePacker_->StartPacking(data, maxSize, packOption);
40}
41
42uint32_t ImagePackerOhos::StartPacking(const std::string& filePath, const PackOption& option)
43{
44    Media::PackOption packOption {option.format, option.quality, option.numberHint};
45    return imagePacker_->StartPacking(filePath, packOption);
46}
47
48uint32_t ImagePackerOhos::FinalizePacking(int64_t& packedSize)
49{
50    return imagePacker_->FinalizePacking(packedSize);
51}
52} // namespace OHOS::Ace
53