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