1 /* 2 * Copyright (C) 2021 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 INTERFACES_INNERKITS_INCLUDE_IMAGE_SOURCE_H 17 #define INTERFACES_INNERKITS_INCLUDE_IMAGE_SOURCE_H 18 19 #include <cstdint> 20 #include <iostream> 21 #include <map> 22 #include <memory> 23 #include <mutex> 24 #include <optional> 25 #include <set> 26 27 #include "decode_listener.h" 28 #include "image_type.h" 29 #include "incremental_pixel_map.h" 30 #include "peer_listener.h" 31 #include "pixel_map.h" 32 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) 33 #include "picture.h" 34 #endif 35 36 namespace OHOS { 37 namespace MultimediaPlugin { 38 constexpr float EPSILON = 1e-6; 39 40 class PluginServer; 41 } // namespace MultimediaPlugin 42 } // namespace OHOS 43 44 namespace OHOS { 45 namespace ImagePlugin { 46 class AbsImageFormatAgent; 47 class AbsImageDecoder; 48 struct DataStreamBuffer; 49 struct PixelDecodeOptions; 50 struct PlImageInfo; 51 struct DecodeContext; 52 } // namespace ImagePlugin 53 } // namespace OHOS 54 55 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) 56 namespace OHOS::HDI::Display::Graphic::Common::V1_0 { 57 enum CM_ColorSpaceType : int32_t; 58 } 59 #else 60 enum CM_ColorSpaceType : int32_t; 61 #endif 62 63 namespace OHOS { 64 namespace Media { 65 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) 66 using namespace HDI::Display::Graphic::Common::V1_0; 67 #endif 68 class ImageEvent; 69 struct SourceOptions { 70 std::string formatHint; 71 int32_t baseDensity = 0; 72 PixelFormat pixelFormat = PixelFormat::UNKNOWN; 73 Size size; 74 }; 75 76 struct IncrementalSourceOptions { 77 SourceOptions sourceOptions; 78 IncrementalMode incrementalMode = IncrementalMode::FULL_DATA; 79 }; 80 81 struct NinePatchInfo { 82 void *ninePatch = nullptr; 83 size_t patchSize = 0; 84 }; 85 86 enum class DecodeEvent : int32_t { 87 EVENT_COMPLETE_DECODE = 0, 88 EVENT_PARTIAL_DECODE = 1, 89 EVENT_HEADER_DECODE = 2, 90 EVENT_LAST = 3 91 }; 92 93 enum class ImageDecodingState : int32_t { 94 UNRESOLVED = 0, 95 BASE_INFO_ERROR = 1, 96 BASE_INFO_PARSED = 2, 97 IMAGE_DECODING = 3, 98 IMAGE_ERROR = 4, 99 PARTIAL_IMAGE = 5, 100 IMAGE_DECODED = 6 101 }; 102 103 enum class SourceDecodingState : int32_t { 104 UNRESOLVED = 0, 105 SOURCE_ERROR = 1, 106 UNKNOWN_FORMAT = 2, 107 FORMAT_RECOGNIZED = 3, 108 UNSUPPORTED_FORMAT = 4, 109 FILE_INFO_ERROR = 5, 110 FILE_INFO_DECODED = 6, 111 IMAGE_DECODING = 7, 112 ALL_IMAGES_ERROR = 8 113 }; 114 115 enum class SourceInfoState : int32_t { 116 SOURCE_ERROR = 0, 117 SOURCE_INCOMPLETE = 1, 118 UNKNOWN_FORMAT = 2, 119 UNSUPPORTED_FORMAT = 3, 120 FILE_INFO_ERROR = 4, 121 FILE_INFO_PARSED = 5 122 }; 123 124 struct ImageDecodingStatus { 125 ImageInfo imageInfo; 126 ImageDecodingState imageState = ImageDecodingState::UNRESOLVED; 127 }; 128 129 struct SourceInfo { 130 int32_t baseDensity = 0; 131 uint32_t topLevelImageNum = 0; 132 std::string encodedFormat; 133 SourceInfoState state = SourceInfoState::SOURCE_ERROR; 134 }; 135 136 struct IncrementalDecodingContext { 137 std::unique_ptr<ImagePlugin::AbsImageDecoder> decoder; 138 ImageDecodingState IncrementalState = ImageDecodingState::UNRESOLVED; 139 uint8_t decodingProgress = 0; 140 }; 141 142 struct PixelMapAddrInfos { 143 uint8_t *addr; 144 uint8_t *context; 145 uint32_t size; 146 AllocatorType type; 147 CustomFreePixelMap func; 148 }; 149 150 struct ASTCInfo { 151 Size size; 152 Size blockFootprint; 153 }; 154 155 class SourceStream; 156 enum class ImageHdrType; 157 struct HdrMetadata; 158 class MetadataAccessor; 159 class ExifMetadata; 160 struct StreamInfo; 161 162 class ImageSource { 163 public: 164 ~ImageSource(); 165 NATIVEEXPORT static uint32_t GetSupportedFormats(std::set<std::string> &formats); 166 NATIVEEXPORT static std::unique_ptr<ImageSource> CreateImageSource(std::unique_ptr<std::istream> is, 167 const SourceOptions &opts, uint32_t &errorCode); 168 NATIVEEXPORT static std::unique_ptr<ImageSource> CreateImageSource(const uint8_t *data, uint32_t size, 169 const SourceOptions &opts, uint32_t &errorCode, bool isUserBuffer = false); 170 NATIVEEXPORT static std::unique_ptr<ImageSource> CreateImageSource(const std::string &pathName, 171 const SourceOptions &opts, uint32_t &errorCode); 172 NATIVEEXPORT static std::unique_ptr<ImageSource> CreateImageSource(const int fd, const SourceOptions &opts, 173 uint32_t &errorCode); 174 NATIVEEXPORT static std::unique_ptr<ImageSource> CreateImageSource( 175 const int fd, int32_t offset, int32_t length, const SourceOptions &opts, uint32_t &errorCode); 176 NATIVEEXPORT static std::unique_ptr<ImageSource> CreateIncrementalImageSource(const IncrementalSourceOptions &opts, 177 uint32_t &errorCode); 178 NATIVEEXPORT static bool IsASTC(const uint8_t *fileData, size_t fileSize); 179 180 NATIVEEXPORT static bool GetASTCInfo(const uint8_t *fileData, size_t fileSize, ASTCInfo& astcInfo); 181 182 NATIVEEXPORT static bool IsSupportGenAstc(); 183 184 NATIVEEXPORT static CM_ColorSpaceType ConvertColorSpaceType(ColorManager::ColorSpaceName colorSpace, bool base); 185 186 NATIVEEXPORT static void SetVividMetaColor(HdrMetadata& metadata, CM_ColorSpaceType base, 187 CM_ColorSpaceType gainmap, CM_ColorSpaceType hdr); 188 CreatePixelMap(const DecodeOptions & opts,uint32_t & errorCode)189 NATIVEEXPORT std::unique_ptr<PixelMap> CreatePixelMap(const DecodeOptions &opts, uint32_t &errorCode) 190 { 191 return CreatePixelMapEx(0, opts, errorCode); 192 } 193 NATIVEEXPORT AllocatorType ConvertAutoAllocatorType(const DecodeOptions &opts); 194 NATIVEEXPORT std::unique_ptr<PixelMap> CreatePixelMapEx(uint32_t index, const DecodeOptions &opts, 195 uint32_t &errorCode); 196 NATIVEEXPORT std::unique_ptr<PixelMap> CreatePixelMap(uint32_t index, const DecodeOptions &opts, 197 uint32_t &errorCode); 198 NATIVEEXPORT std::unique_ptr<IncrementalPixelMap> CreateIncrementalPixelMap(uint32_t index, 199 const DecodeOptions &opts, 200 uint32_t &errorCode); 201 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) 202 NATIVEEXPORT std::unique_ptr<Picture> CreatePicture(const DecodingOptionsForPicture &opts, uint32_t &errorCode); 203 NATIVEEXPORT std::unique_ptr<Picture> CreatePictureAtIndex(uint32_t index, uint32_t &errorCode); 204 #endif 205 // for incremental source. 206 NATIVEEXPORT uint32_t UpdateData(const uint8_t *data, uint32_t size, bool isCompleted); 207 // for obtaining basic image information without decoding image data. GetImageInfo(ImageInfo & imageInfo)208 NATIVEEXPORT uint32_t GetImageInfo(ImageInfo &imageInfo) 209 { 210 return GetImageInfo(0, imageInfo); 211 } 212 NATIVEEXPORT uint32_t GetImageInfo(uint32_t index, ImageInfo &imageInfo); 213 NATIVEEXPORT uint32_t GetImageInfoFromExif(uint32_t index, ImageInfo &imageInfo); 214 NATIVEEXPORT const SourceInfo &GetSourceInfo(uint32_t &errorCode); 215 NATIVEEXPORT void RegisterListener(PeerListener *listener); 216 NATIVEEXPORT void UnRegisterListener(PeerListener *listener); 217 NATIVEEXPORT DecodeEvent GetDecodeEvent(); 218 NATIVEEXPORT void AddDecodeListener(DecodeListener *listener); 219 NATIVEEXPORT void RemoveDecodeListener(DecodeListener *listener); 220 NATIVEEXPORT bool IsIncrementalSource(); 221 NATIVEEXPORT uint32_t GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value); 222 NATIVEEXPORT uint32_t GetImagePropertyString(uint32_t index, const std::string &key, std::string &value); 223 NATIVEEXPORT uint32_t GetImagePropertyStringBySync(uint32_t index, const std::string &key, std::string &value); 224 NATIVEEXPORT uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value, 225 const std::string &path); 226 NATIVEEXPORT uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value, 227 const int fd); 228 NATIVEEXPORT uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value, 229 uint8_t *data, uint32_t size); 230 NATIVEEXPORT uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value); 231 NATIVEEXPORT uint32_t ModifyImagePropertyEx(uint32_t index, const std::string &key, const std::string &value); 232 NATIVEEXPORT uint32_t RemoveImageProperties(uint32_t index, const std::set<std::string> &keys, 233 const std::string &path); 234 NATIVEEXPORT uint32_t RemoveImageProperties(uint32_t index, const std::set<std::string> &keys, 235 const int fd); 236 NATIVEEXPORT uint32_t RemoveImageProperties(uint32_t index, const std::set<std::string> &keys, 237 uint8_t *data, uint32_t size); 238 NATIVEEXPORT const NinePatchInfo &GetNinePatchInfo() const; 239 NATIVEEXPORT void SetMemoryUsagePreference(const MemoryUsagePreference preference); 240 NATIVEEXPORT MemoryUsagePreference GetMemoryUsagePreference(); 241 NATIVEEXPORT uint32_t GetFilterArea(const int &privacyType, std::vector<std::pair<uint32_t, uint32_t>> &ranges); 242 NATIVEEXPORT uint32_t GetFilterArea(const std::vector<std::string> &exifKeys, 243 std::vector<std::pair<uint32_t, uint32_t>> &ranges); 244 NATIVEEXPORT std::unique_ptr<std::vector<std::unique_ptr<PixelMap>>> CreatePixelMapList(const DecodeOptions &opts, 245 uint32_t &errorCode); 246 NATIVEEXPORT std::unique_ptr<std::vector<int32_t>> GetDelayTime(uint32_t &errorCode); 247 NATIVEEXPORT std::unique_ptr<std::vector<int32_t>> GetDisposalType(uint32_t &errorCode); 248 NATIVEEXPORT int32_t GetLoopCount(uint32_t &errorCode); 249 NATIVEEXPORT uint32_t GetFrameCount(uint32_t &errorCode); 250 #ifdef IMAGE_PURGEABLE_PIXELMAP 251 NATIVEEXPORT size_t GetSourceSize() const; 252 #endif 253 void SetSource(const std::string &source); 254 NATIVEEXPORT bool IsHdrImage(); 255 256 NATIVEEXPORT std::shared_ptr<ExifMetadata> GetExifMetadata(); 257 NATIVEEXPORT void SetExifMetadata(std::shared_ptr<ExifMetadata> &ptr); 258 NATIVEEXPORT static void ContextToAddrInfos(ImagePlugin::DecodeContext &context, PixelMapAddrInfos &addrInfos); 259 NATIVEEXPORT static bool IsYuvFormat(PixelFormat format); 260 NATIVEEXPORT bool IsDecodeHdrImage(const DecodeOptions &opts); 261 NATIVEEXPORT uint64_t GetImageId(); 262 NATIVEEXPORT bool IsSvgUseDma(const DecodeOptions &opts); 263 NATIVEEXPORT bool IsSupportAllocatorType(DecodeOptions& decOps, int32_t allocatorType); 264 265 private: 266 DISALLOW_COPY_AND_MOVE(ImageSource); 267 using FormatAgentMap = std::map<std::string, ImagePlugin::AbsImageFormatAgent *>; 268 using ImageStatusMap = std::map<uint32_t, ImageDecodingStatus>; 269 using IncrementalRecordMap = std::map<PixelMap *, IncrementalDecodingContext>; 270 ImageSource(std::unique_ptr<SourceStream> &&stream, const SourceOptions &opts); 271 uint32_t CheckEncodedFormat(ImagePlugin::AbsImageFormatAgent &agent); 272 uint32_t GetData(ImagePlugin::DataStreamBuffer &outData, size_t size); 273 static FormatAgentMap InitClass(); 274 uint32_t GetEncodedFormat(const std::string &formatHint, std::string &format); 275 uint32_t DecodeImageInfo(uint32_t index, ImageStatusMap::iterator &iter); 276 uint32_t DecodeSourceInfo(bool isAcquiredImageNum); 277 uint32_t InitMainDecoder(); 278 ImagePlugin::AbsImageDecoder *CreateDecoder(uint32_t &errorCode); 279 void CopyOptionsToPlugin(const DecodeOptions &opts, ImagePlugin::PixelDecodeOptions &plOpts); 280 void CopyOptionsToProcOpts(const DecodeOptions &opts, DecodeOptions &procOpts, PixelMap &pixelMap); 281 uint32_t CheckFormatHint(const std::string &formatHint, FormatAgentMap::iterator &formatIter); 282 uint32_t GetSourceInfo(); 283 uint32_t OnSourceRecognized(bool isAcquiredImageNum); 284 uint32_t OnSourceUnresolved(); 285 uint32_t SetDecodeOptions(std::unique_ptr<ImagePlugin::AbsImageDecoder> &decoder, uint32_t index, 286 const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo); 287 uint32_t UpdatePixelMapInfo(const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo, PixelMap &pixelMap); 288 uint32_t UpdatePixelMapInfo(const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo, 289 PixelMap &pixelMap, int32_t fitDensity, bool isReUsed = false); 290 // declare friend class, only IncrementalPixelMap can call PromoteDecoding function. 291 friend class IncrementalPixelMap; 292 uint32_t PromoteDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap, ImageDecodingState &state, 293 uint8_t &decodeProgress); 294 void DetachIncrementalDecoding(PixelMap &pixelMap); 295 ImageStatusMap::iterator GetValidImageStatus(uint32_t index, uint32_t &errorCode); 296 uint32_t AddIncrementalContext(PixelMap &pixelMap, IncrementalRecordMap::iterator &iterator); 297 uint32_t DoIncrementalDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap, 298 IncrementalDecodingContext &recordContext); 299 void SetIncrementalSource(const bool isIncrementalSource); 300 bool IsStreamCompleted(); 301 uint32_t GetImagePropertyCommon(uint32_t index, const std::string &key, std::string &value); 302 FinalOutputStep GetFinalOutputStep(const DecodeOptions &opts, PixelMap &pixelMap, bool hasNinePatch); 303 bool HasDensityChange(const DecodeOptions &opts, ImageInfo &srcImageInfo, bool hasNinePatch); 304 bool ImageSizeChange(int32_t width, int32_t height, int32_t desiredWidth, int32_t desiredHeight); 305 bool ImageConverChange(const Rect &cropRect, ImageInfo &dstImageInfo, ImageInfo &srcImageInfo); 306 void Reset(); 307 static std::unique_ptr<SourceStream> DecodeBase64(const uint8_t *data, uint32_t size); 308 static std::unique_ptr<SourceStream> DecodeBase64(const std::string &data); 309 bool IsSpecialYUV(); 310 bool GetImageInfoForASTC(ImageInfo& imageInfo, const uint8_t *sourceFilePtr); 311 bool ConvertYUV420ToRGBA(uint8_t *data, uint32_t size, bool isSupportOdd, bool isAddUV, uint32_t &errorCode); 312 std::unique_ptr<PixelMap> CreatePixelMapForYUV(uint32_t &errorCode); 313 std::unique_ptr<PixelMap> CreatePixelMapForASTC(uint32_t &errorCode, const DecodeOptions &opts); 314 bool CompressToAstcFromPixelmap(const DecodeOptions &opts, std::unique_ptr<PixelMap> &rgbaPixelmap, 315 std::unique_ptr<AbsMemory> &dstMemory); 316 std::unique_ptr<PixelMap> CreatePixelAstcFromImageFile(uint32_t index, const DecodeOptions &opts, 317 uint32_t &errorCode); 318 uint32_t GetFormatExtended(std::string &format); 319 static std::unique_ptr<ImageSource> DoImageSourceCreate( 320 std::function<std::unique_ptr<SourceStream>(void)> stream, 321 const SourceOptions &opts, uint32_t &errorCode, const std::string traceName = ""); 322 std::unique_ptr<PixelMap> CreatePixelMapExtended(uint32_t index, const DecodeOptions &opts, 323 uint32_t &errorCode); 324 std::unique_ptr<PixelMap> CreatePixelMapByInfos(ImagePlugin::PlImageInfo &plInfo, 325 ImagePlugin::DecodeContext& context, uint32_t &errorCode); 326 bool ApplyGainMap(ImageHdrType hdrType, ImagePlugin::DecodeContext& baseCtx, 327 ImagePlugin::DecodeContext& hdrCtx, float scale); 328 bool ComposeHdrImage(ImageHdrType hdrType, ImagePlugin::DecodeContext& baseCtx, 329 ImagePlugin::DecodeContext& gainMapCtx, ImagePlugin::DecodeContext& hdrCtx, HdrMetadata metadata); 330 uint32_t SetGainMapDecodeOption(std::unique_ptr<ImagePlugin::AbsImageDecoder>& decoder, 331 ImagePlugin::PlImageInfo& plInfo, float scale); 332 ImagePlugin::DecodeContext DecodeImageDataToContext(uint32_t index, ImageInfo info, 333 ImagePlugin::PlImageInfo& outInfo, uint32_t& errorCode); 334 bool DecodeJpegGainMap(ImageHdrType hdrType, float scale, 335 ImagePlugin::DecodeContext& gainMapCtx, HdrMetadata& metadata); 336 void DumpInputData(const std::string& fileSuffix = "dat"); 337 static uint64_t GetNowTimeMicroSeconds(); 338 uint32_t ModifyImageProperty(std::shared_ptr<MetadataAccessor> metadataAccessor, 339 const std::string &key, const std::string &value); 340 uint32_t RemoveImageProperties(std::shared_ptr<MetadataAccessor> metadataAccessor, 341 const std::set<std::string> &key); 342 uint32_t ModifyImageProperty(const std::string &key, const std::string &value); 343 uint32_t CreatExifMetadataByImageSource(bool addFlag = false); 344 uint32_t CreateExifMetadata(uint8_t *buffer, const uint32_t size, bool addFlag, bool hasOriginalFd = false); 345 void SetDecodeInfoOptions(uint32_t index, const DecodeOptions &opts, const ImageInfo &info, ImageEvent &imageEvent); 346 void SetDecodeInfoOptions(uint32_t index, const DecodeOptions &opts, const ImagePlugin::PlImageInfo &plInfo, 347 ImageEvent &imageEvent); 348 void UpdateDecodeInfoOptions(const ImagePlugin::DecodeContext &context, ImageEvent &imageEvent); 349 void SetImageEventHeifParseErr(ImageEvent &event); 350 bool CheckDecodeOptions(Size imageSize, bool &needAisr, bool &needHdr); 351 uint32_t DecodeImageDataToContext(uint32_t index, ImageInfo &info, ImagePlugin::PlImageInfo &plInfo, 352 ImagePlugin::DecodeContext &context, uint32_t &errorCode); 353 void TransformSizeWithDensity(const Size &srcSize, int32_t srcDensity, const Size &wantSize, 354 int32_t wantDensity, Size &dstSize); 355 uint32_t DoAiHdrProcessDl(const ImagePlugin::DecodeContext &srcCtx, ImagePlugin::DecodeContext &dstCtx, 356 bool needAisr, bool needHdr); 357 uint32_t ImageAiProcess(Size imageSize, const DecodeOptions &opts, bool isHdr, 358 ImagePlugin::DecodeContext &context, ImagePlugin::PlImageInfo &plInfo); 359 ImagePlugin::DecodeContext DecodeImageDataToContextExtended(uint32_t index, ImageInfo &info, 360 ImagePlugin::PlImageInfo &plInfo, ImageEvent &imageEvent, uint32_t &errorCode); 361 void SetPixelMapColorSpace(ImagePlugin::DecodeContext& context, std::unique_ptr<PixelMap>& pixelMap, 362 std::unique_ptr<ImagePlugin::AbsImageDecoder>& decoder); 363 bool IsSingleHdrImage(ImageHdrType type); 364 bool IsDualHdrImage(ImageHdrType type); 365 ImagePlugin::DecodeContext HandleSingleHdrImage(ImageHdrType decodedHdrType, 366 ImagePlugin::DecodeContext& context, ImagePlugin::PlImageInfo& plInfo); 367 ImagePlugin::DecodeContext HandleDualHdrImage(ImageHdrType decodedHdrType, ImageInfo info, 368 ImagePlugin::DecodeContext& context, ImagePlugin::PlImageInfo& plInfo); 369 ImagePlugin::DecodeContext InitDecodeContext(const DecodeOptions &opts, const ImageInfo &info, 370 const MemoryUsagePreference &preference, bool hasDesiredSizeOptions, ImagePlugin::PlImageInfo& plInfo); 371 bool ParseHdrType(); 372 bool PrereadSourceStream(); 373 void SetDmaContextYuvInfo(ImagePlugin::DecodeContext& context); 374 uint8_t* ReadSourceBuffer(uint32_t bufferSize, uint32_t &errorCode); 375 void SetSrcFd(const int& fd); 376 void SetSrcFilePath(const std::string& pathName); 377 void SetSrcBuffer(const uint8_t* buffer, uint32_t size); 378 bool CheckDecodeOptions(const DecodeOptions &opts); 379 bool CheckAllocatorTypeValid(const DecodeOptions &opts); 380 bool CheckCropRectValid(const DecodeOptions &opts); 381 void InitDecoderForJpeg(); 382 void RefreshImageSourceByPathName(); 383 std::string GetPixelMapName(PixelMap* pixelMap); 384 385 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) 386 void SpecialSetComposeBuffer(ImagePlugin::DecodeContext &baseCtx, sptr<SurfaceBuffer>& baseSptr, 387 sptr<SurfaceBuffer>& gainmapSptr, sptr<SurfaceBuffer>& hdrSptr, HdrMetadata& metadata); 388 void SetHdrMetadataForPicture(std::unique_ptr<Picture> &picture); 389 void DecodeHeifAuxiliaryPictures(const std::set<AuxiliaryPictureType> &auxTypes, std::unique_ptr<Picture> &picture, 390 uint32_t &errorCode); 391 void DecodeJpegAuxiliaryPicture(std::set<AuxiliaryPictureType> &auxTypes, std::unique_ptr<Picture> &picture, 392 uint32_t &errorCode); 393 bool CheckJpegSourceStream(StreamInfo &streamInfo); 394 uint32_t CreatePictureAtIndexPreCheck(uint32_t index, const ImageInfo &info); 395 uint32_t SetGifMetadataForPicture(std::unique_ptr<Picture> &picture, uint32_t index); 396 #endif 397 398 const std::string NINE_PATCH = "ninepatch"; 399 const std::string SKIA_DECODER = "SKIA_DECODER"; 400 static MultimediaPlugin::PluginServer &pluginServer_; 401 static FormatAgentMap formatAgentMap_; 402 std::unique_ptr<SourceStream> sourceStreamPtr_; 403 SourceDecodingState decodeState_ = SourceDecodingState::UNRESOLVED; 404 SourceInfo sourceInfo_; 405 SourceOptions sourceOptions_; 406 NinePatchInfo ninePatchInfo_; 407 ImageStatusMap imageStatusMap_; 408 IncrementalRecordMap incDecodingMap_; 409 // The main decoder is responsible for ordinary decoding (non-Incremental decoding), 410 // as well as decoding SourceInfo and ImageInfo. 411 std::unique_ptr<ImagePlugin::AbsImageDecoder> mainDecoder_; 412 std::unique_ptr<ImagePlugin::AbsImageDecoder> jpegGainmapDecoder_; 413 DecodeOptions opts_; 414 std::set<PeerListener *> listeners_; 415 DecodeEvent decodeEvent_ = DecodeEvent::EVENT_COMPLETE_DECODE; 416 std::map<int32_t, int32_t> decodeEventMap_; 417 std::set<DecodeListener *> decodeListeners_; 418 std::mutex listenerMutex_; 419 std::mutex decodingMutex_; 420 std::mutex fileMutex_; 421 bool isIncrementalSource_ = false; 422 bool isIncrementalCompleted_ = false; 423 bool hasDesiredSizeOptions = false; 424 MemoryUsagePreference preference_ = MemoryUsagePreference::DEFAULT; 425 std::optional<bool> isAstc_; 426 uint64_t imageId_; // generated from the last six bits of the current timestamp 427 ImageHdrType sourceHdrType_; // source image hdr type; 428 std::shared_ptr<ExifMetadata> exifMetadata_ = nullptr; 429 std::string source_; // Image source fd buffer etc 430 bool isExifReadFailed_ = false; 431 uint32_t exifReadStatus_ = 0; 432 uint32_t heifParseErr_ = 0; 433 std::string srcFilePath_ = ""; 434 int srcFd_ = -1; 435 uint8_t* srcBuffer_ = nullptr; 436 uint32_t srcBufferSize_ = 0; 437 }; 438 } // namespace Media 439 } // namespace OHOS 440 441 #endif // INTERFACES_INNERKITS_INCLUDE_IMAGE_SOURCE_H 442