• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef IMAGE_SOURCE_H
16 #define IMAGE_SOURCE_H
17 
18 #include "ffi_remote_data.h"
19 #include "image_ffi.h"
20 #include "image_source.h"
21 #include "image_type.h"
22 
23 namespace OHOS {
24 namespace Media {
25 class ImageSourceImpl : public OHOS::FFI::FFIData {
26     DECL_TYPE(ImageSourceImpl, OHOS::FFI::FFIData)
27 public:
28     explicit ImageSourceImpl(std::unique_ptr<ImageSource> ptr_);
~ImageSourceImpl()29     ~ImageSourceImpl() override
30     {
31         nativeImgSrc = nullptr;
32     }
33     ImageSourceImpl(std::unique_ptr<ImageSource> imageSource, std::unique_ptr<IncrementalPixelMap> pixelMap);
34     std::shared_ptr<ImageSource> nativeImgSrc = nullptr;
GetIncrementalPixelMap()35     std::shared_ptr<IncrementalPixelMap> GetIncrementalPixelMap()
36     {
37         return navIncPixelMap_;
38     }
39     uint32_t GetImageInfo(uint32_t index, ImageInfo& imageInfo);
40     uint32_t GetSupportedFormats(std::set<std::string>& formats);
41 
42     uint32_t GetImageProperty(std::string key, uint32_t index, std::string& defaultValue);
43     uint32_t GetImageProperties(std::vector<std::string> keyStrArray, std::vector<std::string>& valueStrArray);
44     uint32_t ModifyImageProperty(std::string key, std::string value);
45     uint32_t ModifyImageProperties(char** keyStrArray, char** valueStrArray, int64_t arraySize);
46     uint32_t GetFrameCount(uint32_t& errorCode);
47     uint32_t UpdateData(uint8_t* data, uint32_t size, bool isCompleted);
48     int64_t CreatePixelMap(uint32_t index, DecodeOptions& opts, uint32_t& errorCode);
49     std::vector<int64_t> CreatePixelMapList(uint32_t index, DecodeOptions opts, uint32_t* errorCode);
50     std::unique_ptr<std::vector<int32_t>> GetDelayTime(uint32_t* errorCode);
51     std::unique_ptr<std::vector<int32_t>> GetDisposalTypeList(uint32_t* errorCode);
52 
53     void SetPathName(std::string pathName);
54     void SetFd(int fd);
55     void SetBuffer(uint8_t* data, uint32_t size);
Release()56     void Release() {}
57 
58     static std::unique_ptr<ImageSource> CreateImageSource(std::string uri, uint32_t* errCode);
59     static std::unique_ptr<ImageSource> CreateImageSourceWithOption(
60         std::string uri, SourceOptions& opts, uint32_t* errCode);
61     static std::unique_ptr<ImageSource> CreateImageSource(int fd, uint32_t* errCode);
62     static std::unique_ptr<ImageSource> CreateImageSourceWithOption(int fd, SourceOptions& opts, uint32_t* errCode);
63     static std::unique_ptr<ImageSource> CreateImageSource(uint8_t* data, uint32_t size, uint32_t* errCode);
64     static std::unique_ptr<ImageSource> CreateImageSourceWithOption(
65         uint8_t* data, uint32_t size, SourceOptions& opts, uint32_t* errCode);
66     static std::unique_ptr<ImageSource> CreateImageSource(
67         const int fd, int32_t offset, int32_t length, const SourceOptions& opts, uint32_t& errorCode);
68     static std::tuple<std::unique_ptr<ImageSource>, std::unique_ptr<IncrementalPixelMap>> CreateIncrementalSource(
69         const uint8_t* data, uint32_t size, SourceOptions& opts, uint32_t& errorCode);
70 
71 private:
72     std::shared_ptr<IncrementalPixelMap> navIncPixelMap_ = nullptr;
73     uint32_t index_ = 0;
74     std::string pathName_ = "";
75     int fd_ = -1; // INVALID_FD
76     uint8_t* buffer_ = nullptr;
77     size_t bufferSize_ = 0;
78 };
79 } // namespace Media
80 } // namespace OHOS
81 
82 #endif