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