• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_IMAGE_SOURCE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_IMAGE_SOURCE_H
18 
19 #include "base/image/pixel_map.h"
20 #include "base/memory/ace_type.h"
21 #include "core/components/common/layout/constants.h"
22 
23 namespace OHOS::Ace {
24 
25 #if defined(ACE_STATIC)
26 struct DecodeOptions {
27     PixelFormat desiredFormat = PixelFormat::RGBA_8888;
28 };
29 #endif
30 
31 struct PixelMapConfig {
32     AIImageQuality imageQuality = AIImageQuality::NONE;
33     bool isHdrDecoderNeed = false;
34     PixelFormat photoDecodeFormat = PixelFormat::UNKNOWN;
35 
36     bool operator==(const PixelMapConfig& other) const
37     {
38         return (imageQuality == other.imageQuality) && (isHdrDecoderNeed == other.isHdrDecoderNeed) &&
39                (photoDecodeFormat == other.photoDecodeFormat);
40     }
41 
42     bool operator!=(const PixelMapConfig& other) const
43     {
44         return !(*this == other);
45     }
46 };
47 
48 class PixelMap;
49 
50 class ACE_FORCE_EXPORT ImageSource : public AceType {
51     DECLARE_ACE_TYPE(ImageSource, AceType);
52 
53 public:
54     using Size = std::pair<int32_t, int32_t>;
55 
56     static RefPtr<ImageSource> Create(int32_t fd);
57     static RefPtr<ImageSource> Create(const uint8_t* data, uint32_t size, uint32_t& errorCode);
58     static RefPtr<ImageSource> Create(const std::string& filePath);
59     static bool IsAstc(const uint8_t* data, size_t size);
60     static Size GetASTCInfo(const uint8_t* data, size_t size);
61 
62     virtual std::string GetProperty(const std::string& key) = 0;
63 
64     virtual RefPtr<PixelMap> CreatePixelMap(
65         const Size& size, uint32_t& errorCode, const PixelMapConfig& pixelMapConfig = {}) = 0;
66     virtual RefPtr<PixelMap> CreatePixelMap(
67         uint32_t index, const Size& size, uint32_t& errorCode, const PixelMapConfig& pixelMapConfig = {}) = 0;
68 #if defined(ACE_STATIC)
69     /**
70      * @description: only for 1.2
71      * @param options decode options
72      * @return refptr pixelmap
73      */
CreatePixelMap(const DecodeOptions & options)74     virtual RefPtr<PixelMap> CreatePixelMap(const DecodeOptions& options)
75     {
76         return nullptr;
77     }
78 #endif
79     virtual RefPtr<PixelMap> CreatePixelMap() = 0;
80     virtual Size GetImageSize() = 0;
81     virtual uint32_t GetFrameCount() = 0;
82     virtual std::string GetEncodedFormat() = 0;
83 };
84 } // namespace OHOS::Ace
85 
86 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_IMAGE_SOURCE_H
87