diff --git a/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe b/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe index a98595f9a6b15ce9a374439efbd8f73421f74b02..5476254a8cfddb4f40965b588eb176202b2c6d9d 100644 --- a/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe +++ b/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe @@ -568,10 +568,10 @@ union AuxPicture { interface Picture { GetImplPtr(): i64; - GetMainPixelmap(): PixelMap; + GetMainPixelmap(): Optional; @gen_promise("getHdrComposedPixelmap") - GetHdrComposedPixelmapSync(): PixelMap; + GetHdrComposedPixelmapSync(): Optional; GetGainmapPixelmap(): GainMap; @@ -583,7 +583,7 @@ interface Picture { SetMetadataSync(metadataType: MetadataType, metadata: Metadata): void; @gen_promise("getMetadata") - GetMetadataSync(metadataType: MetadataType): Metadata; + GetMetadataSync(metadataType: MetadataType): Optional; Marshalling(sequence: @sts_type("rpc.MessageSequence") Opaque): void; @@ -597,17 +597,17 @@ interface AuxiliaryPicture { WritePixelsFromBufferSync(data: @arraybuffer Array): void; @gen_promise("readPixelsToBuffer") - ReadPixelsToBufferSync(): @arraybuffer Array; + ReadPixelsToBufferSync(): Optional<@arraybuffer Array>; - GetType(): AuxiliaryPictureType; + GetType(): Optional; @gen_promise("setMetadata") SetMetadataSync(metadataType: MetadataType, metadata: Metadata): void; @gen_promise("getMetadata") - GetMetadataSync(metadataType: MetadataType): Metadata; + GetMetadataSync(metadataType: MetadataType): Optional; - GetAuxiliaryPictureInfo(): AuxiliaryPictureInfo; + GetAuxiliaryPictureInfo(): Optional; SetAuxiliaryPictureInfo(info: AuxiliaryPictureInfo): void; @@ -624,72 +624,39 @@ interface Metadata { SetPropertiesSync(records: @record Map): void; @gen_promise("getAllProperties") - GetAllPropertiesSync(): @record Map; - + GetAllPropertiesSync(): Optional<@record Map>; + @gen_promise("clone") - CloneSync(): Metadata; + CloneSync(): Optional; } interface ImageSource { GetImplPtr(): i64; - @gen_async("getImageInfo") - @gen_promise("getImageInfoPromiseWithIndex") - GetImageInfoSyncWithIndex(index: i32): ImageInfo; - @gen_async("getImageInfo") - @gen_promise("getImageInfoPromise") - GetImageInfoSync(): ImageInfo; + @static_overload("getImageInfo") + @async GetImageInfoWithIndexCallback(index: i32): Optional; - @!sts_inject_into_interface("getImageInfoSync(index: int | undefined): ImageInfo;") - @!sts_inject_into_class("""getImageInfoSync(index: int | undefined): ImageInfo { - if (index === undefined) { - return this.getImageInfoSync(); - } else { - return this.getImageInfoSyncWithIndex(index); - } - } - """) + @static_overload("getImageInfo") + @async GetImageInfoWithCallback(): Optional; - @!sts_inject_into_interface("getImageInfo(index: int | undefined): Promise;") - @!sts_inject_into_class("""getImageInfo(index: int | undefined): Promise { - if (index === undefined) { - return this.getImageInfoPromise(); - } else { - return this.getImageInfoPromiseWithIndex(index); - } - } - """) + @static_overload("getImageInfo") + @promise GetImageInfoReturnsPromise(index: Optional): Optional; - @gen_async("createPixelMap") - @gen_promise("createPixelMapPromiseWithOptions") - CreatePixelMapSyncWithOptions(options: DecodingOptions): PixelMap; - - @gen_async("createPixelMap") - @gen_promise("createPixelMapPromise") - CreatePixelMapSync(): PixelMap; - - @!sts_inject_into_interface("createPixelMapSync(options: DecodingOptions | undefined): PixelMap;") - @!sts_inject_into_class("""createPixelMapSync(options: DecodingOptions | undefined): PixelMap { - if (options === undefined) { - return this.createPixelMapSync(); - } else { - return this.createPixelMapSyncWithOptions(options); - } - } - """) + GetImageInfoSync(index: Optional): Optional; - @!sts_inject_into_interface("createPixelMap(options: DecodingOptions | undefined): Promise;") - @!sts_inject_into_class("""createPixelMap(options: DecodingOptions | undefined): Promise { - if (options === undefined) { - return this.createPixelMapPromise(); - } else { - return this.createPixelMapPromiseWithOptions(options); - } - } - """) + @static_overload("createPixelMap") + @async CreatePixelMapWithOptionsCallback(options: DecodingOptions): Optional; + + @static_overload("createPixelMap") + @async CreatePixelMapWithCallback(): Optional; + + @static_overload("createPixelMap") + @promise CreatePixelMapReturnsPromise(options: Optional): Optional; + + CreatePixelMapSync(options: Optional): Optional; @gen_promise("createPixelMapUsingAllocator") - CreatePixelMapUsingAllocatorSync(options: Optional, allocatorType: Optional): PixelMap; + CreatePixelMapUsingAllocatorSync(options: Optional, allocatorType: Optional): Optional; @gen_async("createPixelMapList") CreatePixelMapListSync(): Array; @@ -732,7 +699,7 @@ interface ImageSource { ReleaseSync(): void; @gen_promise("createPicture") - CreatePictureSync(options: Optional): Picture; + CreatePictureSync(options: Optional): Optional; @get GetSupportedFormats(): Array; } @@ -896,31 +863,31 @@ function CreatePixelMapFromSurfaceByIdAndRegionSync(surfaceId: String, region: R function CreatePixelMapFromParcel(sequence: @sts_type("rpc.MessageSequence") Opaque): PixelMap; @overload("createImageSource") -function CreateImageSourceByUri(uri: String): ImageSource; +function CreateImageSourceByUri(uri: String): Optional; @overload("createImageSource") -function CreateImageSourceByUriOption(uri: String, options: SourceOptions): ImageSource; +function CreateImageSourceByUriOption(uri: String, options: SourceOptions): Optional; @overload("createImageSource") -function CreateImageSourceByFd(fd: i32): ImageSource; +function CreateImageSourceByFd(fd: i32): Optional; @overload("createImageSource") -function CreateImageSourceByFdOption(fd: i32, options: SourceOptions): ImageSource; +function CreateImageSourceByFdOption(fd: i32, options: SourceOptions): Optional; @overload("createImageSource") -function CreateImageSourceByArrayBuffer(buf: @arraybuffer Array): ImageSource; +function CreateImageSourceByArrayBuffer(buf: @arraybuffer Array): Optional; @overload("createImageSource") -function CreateImageSourceByArrayBufferOption(buf: @arraybuffer Array, options: SourceOptions): ImageSource; +function CreateImageSourceByArrayBufferOption(buf: @arraybuffer Array, options: SourceOptions): Optional; @overload("CreateIncrementalSource") -function CreateIncrementalSourceByArrayBuffer(buf: @arraybuffer Array): ImageSource; +function CreateIncrementalSourceByArrayBuffer(buf: @arraybuffer Array): Optional; @overload("CreateIncrementalSource") -function CreateIncrementalSourceByArrayBufferOption(buf: @arraybuffer Array, options: Optional): ImageSource; +function CreateIncrementalSourceByArrayBufferOption(buf: @arraybuffer Array, options: Optional): Optional; @overload("createImageSource") -function CreateImageSourceByRawFileDescriptorOption(rawfile: @sts_type("resourceManager.RawFileDescriptor") Opaque, options: Optional): ImageSource; +function CreateImageSourceByRawFileDescriptorOption(rawfile: @sts_type("resourceManager.RawFileDescriptor") Opaque, options: Optional): Optional; // For legacy ANI backward compatibility function CreateImageSourceByPtr(ptr: i64): ImageSource; @@ -929,7 +896,7 @@ function CreateImagePacker(): ImagePacker; function CreateImageCreator(size: Size, format: ImageFormat, capacity: i32): ImageCreator; -function CreateImageReceiver(size: Size, format: ImageFormat, capacity: i32): ImageReceiver; +function CreateImageReceiver(size: Size, format: ImageFormat, capacity: i32): Optional; @overload("createPicture") function CreatePictureByPixelMap(mainPixelmap : PixelMap): Picture; diff --git a/frameworks/kits/taihe/include/auxiliary_picture_taihe.h b/frameworks/kits/taihe/include/auxiliary_picture_taihe.h index 042bf48ac624a20ca85a9956f544f82141c15363..7fbbf311484c05387001904f982d7ade7e39cf30 100644 --- a/frameworks/kits/taihe/include/auxiliary_picture_taihe.h +++ b/frameworks/kits/taihe/include/auxiliary_picture_taihe.h @@ -36,11 +36,11 @@ public: } void WritePixelsFromBufferSync(array_view data); - array ReadPixelsToBufferSync(); - AuxiliaryPictureType GetType(); + optional> ReadPixelsToBufferSync(); + optional GetType(); void SetMetadataSync(MetadataType metadataType, weak::Metadata metadata); - Metadata GetMetadataSync(MetadataType metadataType); - AuxiliaryPictureInfo GetAuxiliaryPictureInfo(); + optional GetMetadataSync(MetadataType metadataType); + optional GetAuxiliaryPictureInfo(); void SetAuxiliaryPictureInfo(AuxiliaryPictureInfo const& info); void Release(); diff --git a/frameworks/kits/taihe/include/image_source_taihe.h b/frameworks/kits/taihe/include/image_source_taihe.h index fd390e743aec3e3828598697408f3bd266ba289e..401e4270f7f287fd15ef18da4483eb225f48cf8e 100644 --- a/frameworks/kits/taihe/include/image_source_taihe.h +++ b/frameworks/kits/taihe/include/image_source_taihe.h @@ -36,11 +36,17 @@ public: ~ImageSourceImpl(); int64_t GetImplPtr(); - ImageInfo GetImageInfoSyncWithIndex(int32_t index); - ImageInfo GetImageInfoSync(); - PixelMap CreatePixelMapSyncWithOptions(DecodingOptions const& options); - PixelMap CreatePixelMapSync(); - PixelMap CreatePixelMapUsingAllocatorSync(optional_view options, + optional GetImageInfoWithIndexCallback(int32_t index); + optional GetImageInfoWithCallback(); + optional GetImageInfoReturnsPromise(optional_view index); + optional GetImageInfoSync(optional_view index); + optional GetImageInfoInner(optional_view index, bool isSync); + optional CreatePixelMapSyncWithOptions(optional_view options, bool isSync); + optional CreatePixelMapWithOptionsCallback(DecodingOptions const& options); + optional CreatePixelMapWithCallback(); + optional CreatePixelMapReturnsPromise(optional_view options); + optional CreatePixelMapSync(optional_view options); + optional CreatePixelMapUsingAllocatorSync(optional_view options, optional_view allocatorType); array CreatePixelMapListSync(); array CreatePixelMapListSyncWithOptions(DecodingOptions const& options); @@ -55,7 +61,7 @@ public: void UpdateDataSync(array_view buf, bool isFinished, int32_t offset, int32_t length); void ReleaseSync(); #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) - Picture CreatePictureSync(optional_view options); + optional CreatePictureSync(optional_view options); #endif array GetSupportedFormats(); diff --git a/frameworks/kits/taihe/include/metadata_taihe.h b/frameworks/kits/taihe/include/metadata_taihe.h index fc6c1cbca89e72197dad26eb693108465d817e25..e781bba2510d2d0cd0b4d462737827a88259d598 100644 --- a/frameworks/kits/taihe/include/metadata_taihe.h +++ b/frameworks/kits/taihe/include/metadata_taihe.h @@ -36,8 +36,8 @@ public: map GetPropertiesSync(array_view key); void SetPropertiesSync(map_view records); - map GetAllPropertiesSync(); - Metadata CloneSync(); + optional> GetAllPropertiesSync(); + optional CloneSync(); void Release(); diff --git a/frameworks/kits/taihe/include/picture_taihe.h b/frameworks/kits/taihe/include/picture_taihe.h index e928f2b4fcb0a331e43da1d121f1082e64492b58..afe8942126ba469d2a5b578195d8322ce2b78933 100644 --- a/frameworks/kits/taihe/include/picture_taihe.h +++ b/frameworks/kits/taihe/include/picture_taihe.h @@ -35,13 +35,13 @@ public: std::shared_ptr GetNativePtr(); static Picture CreatePicture(std::shared_ptr picture); - PixelMap GetMainPixelmap(); - PixelMap GetHdrComposedPixelmapSync(); + optional GetMainPixelmap(); + optional GetHdrComposedPixelmapSync(); GainMap GetGainmapPixelmap(); void SetAuxiliaryPicture(AuxiliaryPictureType type, weak::AuxiliaryPicture auxiliaryPicture); AuxPicture GetAuxiliaryPicture(AuxiliaryPictureType type); void SetMetadataSync(MetadataType metadataType, weak::Metadata metadata); - Metadata GetMetadataSync(MetadataType metadataType); + optional GetMetadataSync(MetadataType metadataType); void Marshalling(uintptr_t sequence); void Release(); diff --git a/frameworks/kits/taihe/src/auxiliary_picture_taihe.cpp b/frameworks/kits/taihe/src/auxiliary_picture_taihe.cpp index bcb393f4b74e70e22f17a7e7a9792a409baed998..c11abdc990ac215a940313d139fc07d66cdd52c3 100644 --- a/frameworks/kits/taihe/src/auxiliary_picture_taihe.cpp +++ b/frameworks/kits/taihe/src/auxiliary_picture_taihe.cpp @@ -95,15 +95,15 @@ static bool ReadPixelsToBufferSyncExecute(std::unique_ptr ReadPixelsToBufferSyncComplete(std::unique_ptr &context) +static optional> ReadPixelsToBufferSyncComplete(std::unique_ptr &context) { - array result = array(nullptr, 0); + optional> result = optional>(std::nullopt); if (context->status == OHOS::Media::SUCCESS) { - result = ImageTaiheUtils::CreateTaiheArrayBuffer(static_cast(context->arrayBuffer), + array array = ImageTaiheUtils::CreateTaiheArrayBuffer(static_cast(context->arrayBuffer), context->arrayBufferSize); + result = optional>(std::in_place, array); } else { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERROR, "Fail to create taihe arraybuffer!"); - return array(nullptr, 0); } delete[] static_cast(context->arrayBuffer); @@ -112,22 +112,25 @@ static array ReadPixelsToBufferSyncComplete(std::unique_ptr AuxiliaryPictureImpl::GetType() { + IMAGE_LOGD("Call GetType"); if (nativeAuxiliaryPicture_ == nullptr) { IMAGE_LOGE("Native auxiliary picture is nullptr!"); - return AuxiliaryPictureType(static_cast(OHOS::Media::AuxiliaryPictureType::NONE)); + return optional(std::nullopt); } AuxiliaryPictureType::key_t auxPictureTypeKey; auto auxType = nativeAuxiliaryPicture_->GetType(); IMAGE_LOGD("AuxiliaryPictureImpl::GetType %{public}d", auxType); - if (ImageTaiheUtils::GetEnumKeyByValue(static_cast(auxType), auxPictureTypeKey)) { - return AuxiliaryPictureType(auxPictureTypeKey); - } else { - IMAGE_LOGE("Get auxiliary picture type failed"); - return AuxiliaryPictureType(static_cast( - OHOS::Media::AuxiliaryPictureType::NONE)); + if (static_cast(auxType) >= 0 && auxType <= OHOS::Media::AuxiliaryPictureType::FRAGMENT_MAP) { + if (ImageTaiheUtils::GetEnumKeyByValue(static_cast(auxType), + auxPictureTypeKey)) { + return optional(std::in_place, AuxiliaryPictureType(auxPictureTypeKey)); + } else { + IMAGE_LOGE("Get auxiliary picture type failed"); + } } + return optional(std::nullopt); } static bool CheckMetadataType(std::unique_ptr const& context) @@ -172,40 +175,45 @@ void AuxiliaryPictureImpl::SetMetadataSync(MetadataType metadataType, weak::Meta IMAGE_LOGD("[AuxiliaryPicture]SetMetadata OUT"); } -Metadata AuxiliaryPictureImpl::GetMetadataSync(MetadataType metadataType) +optional AuxiliaryPictureImpl::GetMetadataSync(MetadataType metadataType) { std::unique_ptr context = std::make_unique(); context->rAuxiliaryPicture = nativeAuxiliaryPicture_; if (context->rAuxiliaryPicture == nullptr) { ImageTaiheUtils::ThrowExceptionError("Empty native auxiliary picture."); - return make_holder(); + return optional(std::nullopt); } if (metadataType >= static_cast(OHOS::Media::MetadataType::EXIF) && metadataType <= static_cast(OHOS::Media::MetadataType::FRAGMENT)) { context->metadataType = OHOS::Media::MetadataType(metadataType.get_value()); } else { ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "Invalid args metadata type."); - return make_holder(); + return optional(std::nullopt); } if (!CheckMetadataType(context) || context->metadataType == OHOS::Media::MetadataType::EXIF) { ImageTaiheUtils::ThrowExceptionError(IMAGE_UNSUPPORTED_METADATA, "Unsupported metadata"); - return make_holder(); + return optional(std::nullopt); } context->imageMetadata = context->rAuxiliaryPicture->GetMetadata(context->metadataType); + if (context->imageMetadata == nullptr) { + ImageTaiheUtils::ThrowExceptionError("Get Metadata failed!"); + return optional(std::nullopt); + } IMAGE_LOGD("[AuxiliaryPicture]GetMetadata OUT"); - return make_holder(std::move(context->imageMetadata)); + auto res = make_holder(std::move(context->imageMetadata)); + return optional(std::in_place, res); } -array AuxiliaryPictureImpl::ReadPixelsToBufferSync() +optional> AuxiliaryPictureImpl::ReadPixelsToBufferSync() { std::unique_ptr taiheContext = std::make_unique(); taiheContext->rAuxiliaryPicture = nativeAuxiliaryPicture_; if (taiheContext->rAuxiliaryPicture == nullptr) { - ImageTaiheUtils::ThrowExceptionError("Empty native auxiliary picture."); - return array(nullptr, 0); + IMAGE_LOGE("Empty native auxiliary picture."); + return optional>(std::nullopt); } if (!ReadPixelsToBufferSyncExecute(taiheContext)) { - return array(nullptr, 0); + return optional>(std::nullopt); } return ReadPixelsToBufferSyncComplete(taiheContext); } @@ -216,7 +224,7 @@ AuxiliaryPictureInfo MakeEmptyAuxiliaryPictureInfo() {0, 0}, 0, PixelMapFormat(PixelMapFormat::key_t::UNKNOWN), 0}; } -static AuxiliaryPictureInfo ToTaiheAuxiliaryPictureInfo(const OHOS::Media::AuxiliaryPictureInfo &src, +static optional ToTaiheAuxiliaryPictureInfo(const OHOS::Media::AuxiliaryPictureInfo &src, std::shared_ptr &auxiliaryPicture) { AuxiliaryPictureInfo result = MakeEmptyAuxiliaryPictureInfo(); @@ -236,29 +244,29 @@ static AuxiliaryPictureInfo ToTaiheAuxiliaryPictureInfo(const OHOS::Media::Auxil ImageTaiheUtils::GetEnumKeyByValue(static_cast(src.pixelFormat), pixelFormatKey); result.pixelFormat = PixelMapFormat(pixelFormatKey); - if (auxiliaryPicture == nullptr) { + if (auxiliaryPicture->GetContentPixel() == nullptr) { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERR_IMAGE_DATA_ABNORMAL, "Invalid pixelmap"); - return result; + return optional(std::nullopt); } - + auto grCS = auxiliaryPicture->GetContentPixel()->InnerGetGrColorSpacePtr(); if (grCS == nullptr) { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERR_IMAGE_DATA_UNSUPPORT, "No colorspace in pixelmap"); - return result; + return optional(std::nullopt); } ani_object colorSpaceObj = OHOS::ColorManager::CreateAniColorSpaceObject(get_env(), grCS); result.colorSpace = reinterpret_cast(colorSpaceObj); - return result; + return optional(std::in_place, result); } -AuxiliaryPictureInfo AuxiliaryPictureImpl::GetAuxiliaryPictureInfo() +optional AuxiliaryPictureImpl::GetAuxiliaryPictureInfo() { if (nativeAuxiliaryPicture_ != nullptr) { return ToTaiheAuxiliaryPictureInfo( nativeAuxiliaryPicture_->GetAuxiliaryPictureInfo(), nativeAuxiliaryPicture_); } else { - ImageTaiheUtils::ThrowExceptionError("Native auxiliarypicture is nullptr!"); - return MakeEmptyAuxiliaryPictureInfo(); + IMAGE_LOGE("Native auxiliarypicture is nullptr!"); + return optional(std::nullopt); } } diff --git a/frameworks/kits/taihe/src/image_receiver_taihe.cpp b/frameworks/kits/taihe/src/image_receiver_taihe.cpp index 4308633dc15622844e71d67aaf5ce0664883645a..5fafdf396e6a01371d73e0e3996f3bbd9d643d77 100644 --- a/frameworks/kits/taihe/src/image_receiver_taihe.cpp +++ b/frameworks/kits/taihe/src/image_receiver_taihe.cpp @@ -512,20 +512,21 @@ void ImageReceiverImpl::ReleaseSync() ReleaseSyncProcess(args, this); } -ImageReceiver CreateImageReceiver(Size const& size, ImageFormat format, int32_t capacity) +optional CreateImageReceiver(Size const& size, ImageFormat format, int32_t capacity) { if (!CheckFormat(format.get_value())) { - ImageTaiheUtils::ThrowExceptionError(OHOS::Media::COMMON_ERR_INVALID_PARAMETER, "Invalid format"); - return make_holder(); + ImageTaiheUtils::ThrowExceptionError(OHOS::Media::COMMON_ERR_INVALID_PARAMETER, "Invalid type"); + return optional(std::nullopt); } std::shared_ptr imageReceiver = OHOS::Media::ImageReceiver::CreateImageReceiver( size.width, size.height, format.get_value(), capacity); if (imageReceiver == nullptr) { - ImageTaiheUtils::ThrowExceptionError("Create native image receiver failed"); - return make_holder(); + IMAGE_LOGE("Create native image receiver failed"); + return optional(std::nullopt); } - return make_holder(imageReceiver); + auto res = make_holder(imageReceiver); + return optional(std::in_place, res); } } // namespace ANI::Image diff --git a/frameworks/kits/taihe/src/image_source_taihe.cpp b/frameworks/kits/taihe/src/image_source_taihe.cpp index 9866a270fc9a2af7ed11654dfedda7d91c18e8f2..6a1936d5a71fc69805bcfdaacb457017c86bcfd5 100644 --- a/frameworks/kits/taihe/src/image_source_taihe.cpp +++ b/frameworks/kits/taihe/src/image_source_taihe.cpp @@ -180,27 +180,55 @@ int64_t ImageSourceImpl::GetImplPtr() return reinterpret_cast(this); } -ImageInfo ImageSourceImpl::GetImageInfoSyncWithIndex(int32_t index) +optional ImageSourceImpl::GetImageInfoWithIndexCallback(int32_t index) { + return GetImageInfoInner(::taihe::optional::make(index), false); +} + +optional ImageSourceImpl::GetImageInfoWithCallback() +{ + return GetImageInfoInner(::taihe::optional::make(), false); +} + +optional ImageSourceImpl::GetImageInfoReturnsPromise(optional_view index) +{ + return GetImageInfoInner(index, false); +} + +optional ImageSourceImpl::GetImageInfoSync(optional_view index) +{ + return GetImageInfoInner(index, true); +} + +optional ImageSourceImpl::GetImageInfoInner(optional_view index, bool isSync) +{ + optional res = optional(std::nullopt); + + if (nativeImgSrc == nullptr) { + IMAGE_LOGE("nativeImgSrc is nullptr"); + return res; + } + + int32_t indexValue = NUM_0; + if (index.has_value()) { + indexValue = index.value() >= NUM_0 ? index.value() : NUM_0; + } + OHOS::Media::ImageInfo imageinfo; - bool isHdr = false; - if (nativeImgSrc != nullptr) { - index = index >= NUM_0 ? index : NUM_0; - uint32_t ret = nativeImgSrc->GetImageInfo(index, imageinfo); - if (ret != OHOS::Media::SUCCESS) { + uint32_t ret = nativeImgSrc->GetImageInfo(indexValue, imageinfo); + if (ret != OHOS::Media::SUCCESS) { + if (isSync) { + IMAGE_LOGE("Inner GetImageInfo failed"); + } else { ImageTaiheUtils::ThrowExceptionError("Inner GetImageInfo failed"); } - isHdr = nativeImgSrc->IsHdrImage(); } else { - ImageTaiheUtils::ThrowExceptionError("nativeImgSrc is nullptr"); + bool isHdr = nativeImgSrc->IsHdrImage(); + auto taiheImageInfo = ImageTaiheUtils::ToTaiheImageInfo(imageinfo, isHdr); + res = optional(std::in_place, taiheImageInfo); } - return ImageTaiheUtils::ToTaiheImageInfo(imageinfo, isHdr); -} -ImageInfo ImageSourceImpl::GetImageInfoSync() -{ - int32_t index = 0; - return GetImageInfoSyncWithIndex(index); + return res; } static bool ParseRotate(DecodingOptions const& options, OHOS::Media::DecodeOptions &dst, std::string &errMsg) @@ -457,6 +485,7 @@ static void CreatePixelMapExecute(std::unique_ptr &taih if (taiheContext->errMsg.size() > 0) { IMAGE_LOGE("%{public}s errMsg: %{public}s", __func__, taiheContext->errMsg.c_str()); + taiheContext->status = OHOS::Media::ERROR; return; } @@ -470,48 +499,64 @@ static void CreatePixelMapExecute(std::unique_ptr &taih IMAGE_LOGD("CreatePixelMapExecute OUT"); } -static PixelMap CreatePixelMapComplete(std::unique_ptr &taiheContext) +static optional CreatePixelMapComplete(std::unique_ptr &taiheContext, bool isSync) { IMAGE_LOGD("CreatePixelMapComplete IN"); if (taiheContext->status == OHOS::Media::SUCCESS && taiheContext->rPixelMap != nullptr) { - return PixelMapImpl::CreatePixelMap(taiheContext->rPixelMap); + auto pixelMap = PixelMapImpl::CreatePixelMap(taiheContext->rPixelMap); + return optional(std::in_place, pixelMap); + } + if (!isSync) { + ImageTaiheUtils::ThrowExceptionError(taiheContext->errMsg); } IMAGE_LOGD("CreatePixelMapComplete OUT"); - ImageTaiheUtils::ThrowExceptionError(taiheContext->errMsg); - return make_holder(); + return optional(std::nullopt); } -PixelMap ImageSourceImpl::CreatePixelMapSyncWithOptions(DecodingOptions const& options) +optional ImageSourceImpl::CreatePixelMapSyncWithOptions(optional_view options, bool isSync) { std::unique_ptr taiheContext = std::make_unique(); taiheContext->rImageSource = nativeImgSrc; if (taiheContext->rImageSource == nullptr) { IMAGE_LOGE("%{public}s nativeImgSrc is nullptr", __func__); - ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "nativeImgSrc is nullptr"); - return make_holder(); + return optional(std::nullopt); } taiheContext->thisPtr = this; if (taiheContext->thisPtr == nullptr) { IMAGE_LOGE("%{public}s thisPtr is nullptr", __func__); - ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "thisPtr is nullptr"); - return make_holder(); + return optional(std::nullopt); } - if (!ParseDecodeOptions(options, taiheContext->decodeOpts, taiheContext->index, + DecodingOptions decodingOptions = options.value_or(DecodingOptions {}); + if (!ParseDecodeOptions(decodingOptions, taiheContext->decodeOpts, taiheContext->index, taiheContext->errMsg)) { IMAGE_LOGE("%{public}s ParseDecodeOptions failed", __func__); } ImageTaiheUtils::HicheckerReport(); CreatePixelMapExecute(taiheContext); - return CreatePixelMapComplete(taiheContext); + return CreatePixelMapComplete(taiheContext, isSync); } -PixelMap ImageSourceImpl::CreatePixelMapSync() +optional ImageSourceImpl::CreatePixelMapWithOptionsCallback(DecodingOptions const& options) { - DecodingOptions options {}; - return CreatePixelMapSyncWithOptions(options); + return CreatePixelMapSyncWithOptions(optional(std::in_place, options), false); +} + +optional ImageSourceImpl::CreatePixelMapWithCallback() +{ + return CreatePixelMapSyncWithOptions(optional(std::nullopt), false); +} + +optional ImageSourceImpl::CreatePixelMapReturnsPromise(optional_view options) +{ + return CreatePixelMapSyncWithOptions(options, false); +} + +optional ImageSourceImpl::CreatePixelMapSync(optional_view options) +{ + return CreatePixelMapSyncWithOptions(options, true); } static void CreatePixelMapUsingAllocatorSyncExecute(std::unique_ptr &taiheContext) @@ -530,31 +575,32 @@ static void CreatePixelMapUsingAllocatorSyncExecute(std::unique_ptr &taiheContext) +static optional CreatePixelMapUsingAllocatorSyncComplete(std::unique_ptr &context) { - if (taiheContext->status == OHOS::Media::SUCCESS && taiheContext->rPixelMap != nullptr) { - return PixelMapImpl::CreatePixelMap(taiheContext->rPixelMap); + if (context->status == OHOS::Media::SUCCESS && context->rPixelMap != nullptr) { + auto res = PixelMapImpl::CreatePixelMap(context->rPixelMap); + return optional(std::in_place, res); } - for (const auto &[errorCode, errMsg] : taiheContext->errMsgArray) { + for (const auto &[errorCode, errMsg] : context->errMsgArray) { ImageTaiheUtils::ThrowExceptionError(errorCode, errMsg); } - return make_holder(); + return optional(std::nullopt); } -PixelMap ImageSourceImpl::CreatePixelMapUsingAllocatorSync(optional_view options, +optional ImageSourceImpl::CreatePixelMapUsingAllocatorSync(optional_view options, optional_view allocatorType) { std::unique_ptr taiheContext = std::make_unique(); taiheContext->rImageSource = nativeImgSrc; if (taiheContext->rImageSource == nullptr) { IMAGE_LOGE("%{public}s nativeImgSrc is nullptr", __func__); - return make_holder(); + return optional(std::nullopt); } taiheContext->thisPtr = this; if (taiheContext->thisPtr == nullptr) { IMAGE_LOGE("%{public}s thisPtr is nullptr", __func__); - return make_holder(); + return optional(std::nullopt); } DecodingOptions opts = options.value_or(DecodingOptions {}); @@ -562,14 +608,14 @@ PixelMap ImageSourceImpl::CreatePixelMapUsingAllocatorSync(optional_viewerrMsg)) { IMAGE_LOGE("DecodeOptions mismatch."); ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "DecodeOptions mismatch."); - return make_holder(); + return optional(std::nullopt); } int32_t allocatorTypeInner = allocatorType.value_or(AllocatorType::key_t::AUTO); if (!taiheContext->rImageSource->IsSupportAllocatorType(taiheContext->decodeOpts, allocatorTypeInner)) { IMAGE_LOGE("Unsupported allocator type."); ImageTaiheUtils::ThrowExceptionError(IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE, "Unsupported allocator type."); - return make_holder(); + return optional(std::nullopt); } CreatePixelMapUsingAllocatorSyncExecute(taiheContext); @@ -1218,27 +1264,29 @@ static void CreatePictureExecute(std::unique_ptr &conte IMAGE_LOGD("CreatePictureExecute OUT"); } -static Picture CreatePictureComplete(std::unique_ptr &context) +static optional CreatePictureComplete(std::unique_ptr &context) { IMAGE_LOGD("CreatePictureComplete IN"); - if (context->status != OHOS::Media::SUCCESS) { + if (context->status != OHOS::Media::SUCCESS || context->rPicture == nullptr) { std::pair errorMsg(static_cast(IMAGE_DECODE_FAILED), "Create Picture error"); context->errMsgArray.insert(errorMsg); for (const auto &[errorCode, errMsg] : context->errMsgArray) { ImageTaiheUtils::ThrowExceptionError(errorCode, errMsg); } + return optional(std::nullopt); } IMAGE_LOGD("CreatePictureComplete OUT"); - return PictureImpl::CreatePicture(context->rPicture); + auto res = PictureImpl::CreatePicture(context->rPicture); + return optional(std::in_place, res); } -Picture ImageSourceImpl::CreatePictureSync(optional_view options) +optional ImageSourceImpl::CreatePictureSync(optional_view options) { std::unique_ptr taiheContext = std::make_unique(); taiheContext->thisPtr = this; if (nativeImgSrc == nullptr) { - ImageTaiheUtils::ThrowExceptionError("empty native rImageSource"); - return make_holder(); + IMAGE_LOGE("empty native rImageSource"); + return optional(std::nullopt); } taiheContext->rImageSource = nativeImgSrc; @@ -1251,7 +1299,7 @@ Picture ImageSourceImpl::CreatePictureSync(optional_viewdecodingOptsForPicture)) { ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "DecodingOptionsForPicture mismatch"); - return make_holder(); + return optional(std::nullopt); } } @@ -1277,7 +1325,7 @@ static std::string FileUrlToRawPath(const std::string &path) return path; } -ImageSource CreateImageSourceByUriOption(string_view uri, SourceOptions const& options) +optional CreateImageSourceByUriOption(string_view uri, SourceOptions const& options) { OHOS::Media::SourceOptions opts = ImageTaiheUtils::ParseSourceOptions(options); uint32_t errorCode = OHOS::Media::ERR_MEDIA_INVALID_VALUE; @@ -1286,8 +1334,8 @@ ImageSource CreateImageSourceByUriOption(string_view uri, SourceOptions const& o std::shared_ptr imageSource = OHOS::Media::ImageSource::CreateImageSource(rawPath, opts, errorCode); if (imageSource == nullptr) { - ImageTaiheUtils::ThrowExceptionError("CreateImageSourceByUriOption error"); - return make_holder(); + IMAGE_LOGE("CreateImageSourceExec error, errorCode: %{public}d", errorCode); + return optional(std::nullopt); } { std::lock_guard lock(imageSourceCrossThreadMutex_); @@ -1296,16 +1344,17 @@ ImageSource CreateImageSourceByUriOption(string_view uri, SourceOptions const& o ImageSourceImpl::fileBuffer_ = nullptr; ImageSourceImpl::fileBufferSize_ = NUM_0; } - return make_holder(imageSource); + auto res = make_holder(imageSource); + return optional(std::in_place, res); } -ImageSource CreateImageSourceByUri(string_view uri) +optional CreateImageSourceByUri(string_view uri) { SourceOptions opts {}; return CreateImageSourceByUriOption(uri, opts); } -ImageSource CreateImageSourceByFdOption(double fd, SourceOptions const& options) +optional CreateImageSourceByFdOption(double fd, SourceOptions const& options) { int32_t fdInt = static_cast(fd); OHOS::Media::SourceOptions opts = ImageTaiheUtils::ParseSourceOptions(options); @@ -1313,8 +1362,8 @@ ImageSource CreateImageSourceByFdOption(double fd, SourceOptions const& options) std::shared_ptr imageSource = OHOS::Media::ImageSource::CreateImageSource(fdInt, opts, errorCode); if (imageSource == nullptr) { - ImageTaiheUtils::ThrowExceptionError("CreateImageSourceByFdOption error"); - return make_holder(); + IMAGE_LOGE("CreateImageSourceExec error, errorCode: %{public}d", errorCode); + return optional(std::nullopt); } { std::lock_guard lock(imageSourceCrossThreadMutex_); @@ -1323,16 +1372,17 @@ ImageSource CreateImageSourceByFdOption(double fd, SourceOptions const& options) ImageSourceImpl::fileBuffer_ = nullptr; ImageSourceImpl::fileBufferSize_ = NUM_0; } - return make_holder(imageSource); + auto res = make_holder(imageSource); + return optional(std::in_place, res); } -ImageSource CreateImageSourceByFd(int32_t fd) +optional CreateImageSourceByFd(int32_t fd) { SourceOptions opts {}; return CreateImageSourceByFdOption(fd, opts); } -ImageSource CreateImageSourceByArrayBufferOption(array_view buf, SourceOptions const& options) +optional CreateImageSourceByArrayBufferOption(array_view buf, SourceOptions const& options) { OHOS::Media::SourceOptions opts = ImageTaiheUtils::ParseSourceOptions(options); uint32_t errorCode = OHOS::Media::ERR_MEDIA_INVALID_VALUE; @@ -1340,8 +1390,8 @@ ImageSource CreateImageSourceByArrayBufferOption(array_view buf, Source std::shared_ptr imageSource = OHOS::Media::ImageSource::CreateImageSource(bufPtr, buf.size(), opts, errorCode); if (imageSource == nullptr) { - ImageTaiheUtils::ThrowExceptionError("CreateImageSourceByArrayBufferOption error"); - return make_holder(); + IMAGE_LOGE("CreateImageSourceExec error, errorCode: %{public}d", errorCode); + return optional(std::nullopt); } { std::lock_guard lock(imageSourceCrossThreadMutex_); @@ -1350,16 +1400,18 @@ ImageSource CreateImageSourceByArrayBufferOption(array_view buf, Source ImageSourceImpl::fileBuffer_ = bufPtr; ImageSourceImpl::fileBufferSize_ = buf.size(); } - return make_holder(imageSource); + auto res = make_holder(imageSource); + return optional(std::in_place, res); } -ImageSource CreateImageSourceByArrayBuffer(array_view buf) +optional CreateImageSourceByArrayBuffer(array_view buf) { SourceOptions opts {}; return CreateImageSourceByArrayBufferOption(buf, opts); } -ImageSource CreateIncrementalSourceByArrayBufferOption(array_view buf, optional_view options) +optional CreateIncrementalSourceByArrayBufferOption( + array_view buf, optional_view options) { OHOS::Media::IncrementalSourceOptions incOpts; SourceOptions etsOpts = options.value_or(SourceOptions {}); @@ -1370,8 +1422,8 @@ ImageSource CreateIncrementalSourceByArrayBufferOption(array_view buf, std::shared_ptr imageSource = OHOS::Media::ImageSource::CreateIncrementalImageSource(incOpts, errorCode); if (imageSource == nullptr) { - ImageTaiheUtils::ThrowExceptionError("CreateImageSourceByArrayBufferOption error"); - return make_holder(); + IMAGE_LOGE("%{public}s error, errorCode: %{public}d", __func__, errorCode); + return optional(std::nullopt); } OHOS::Media::DecodeOptions decodeOpts; @@ -1379,20 +1431,22 @@ ImageSource CreateIncrementalSourceByArrayBufferOption(array_view buf, imageSource->CreateIncrementalPixelMap(0, decodeOpts, errorCode); if (errorCode != OHOS::Media::SUCCESS) { - ImageTaiheUtils::ThrowExceptionError("CreateIncrementalPixelMap error"); - return make_holder(); + IMAGE_LOGE("CreateIncrementalImageSource error, errorCode: %{public}d", errorCode); + return optional(std::nullopt); } - return make_holder(imageSource, navIncPixelMap); + auto res = make_holder(imageSource, navIncPixelMap); + return optional(std::in_place, res); } -ImageSource CreateIncrementalSourceByArrayBuffer(array_view buf) +optional CreateIncrementalSourceByArrayBuffer(array_view buf) { optional_view optionalView; return CreateIncrementalSourceByArrayBufferOption(buf, optionalView); } -ImageSource CreateImageSourceByRawFileDescriptorOption(uintptr_t rawfile, optional_view options) +optional CreateImageSourceByRawFileDescriptorOption( + uintptr_t rawfile, optional_view options) { int32_t fd; int64_t offset; @@ -1403,7 +1457,8 @@ ImageSource CreateImageSourceByRawFileDescriptorOption(uintptr_t rawfile, option !ImageTaiheUtils::GetPropertyLong(env, rawfileObj, "offset", offset) || !ImageTaiheUtils::GetPropertyLong(env, rawfileObj, "length", length)) { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::COMMON_ERR_INVALID_PARAMETER, "GetProperty failed"); - return make_holder(); + IMAGE_LOGD("RawFileDescriptor mismatch"); + return optional(std::nullopt); } SourceOptions etsOpts = options.value_or(SourceOptions {}); OHOS::Media::SourceOptions opts = ImageTaiheUtils::ParseSourceOptions(etsOpts); @@ -1413,8 +1468,8 @@ ImageSource CreateImageSourceByRawFileDescriptorOption(uintptr_t rawfile, option std::shared_ptr imageSource = OHOS::Media::ImageSource::CreateImageSource( fd, static_cast(offset), fileSize, opts, errorCode); if (imageSource == nullptr) { - ImageTaiheUtils::ThrowExceptionError("CreateImageSourceByRawFileDescriptorOption error"); - return make_holder(); + IMAGE_LOGE("CreateImageSourceExec error, errorCode: %{public}d", errorCode); + return optional(std::nullopt); } { std::lock_guard lock(imageSourceCrossThreadMutex_); @@ -1423,7 +1478,8 @@ ImageSource CreateImageSourceByRawFileDescriptorOption(uintptr_t rawfile, option ImageSourceImpl::fileBuffer_ = nullptr; ImageSourceImpl::fileBufferSize_ = NUM_0; } - return make_holder(imageSource); + auto res = make_holder(imageSource); + return optional(std::in_place, res); } ImageSource CreateImageSourceByPtr(int64_t ptr) diff --git a/frameworks/kits/taihe/src/metadata_taihe.cpp b/frameworks/kits/taihe/src/metadata_taihe.cpp index 30aaee77c18c36cbb90890ed0441b2070b9aaeba..955c489d20345991e4d15d54c6f0e74c63429861 100644 --- a/frameworks/kits/taihe/src/metadata_taihe.cpp +++ b/frameworks/kits/taihe/src/metadata_taihe.cpp @@ -240,43 +240,48 @@ static void GetAllPropertiesSyncExecute(std::unique_ptr &c context->status = OHOS::Media::SUCCESS; } -static map GetAllPropertiesSyncComplete(std::unique_ptr const& context) +static optional> GetAllPropertiesSyncComplete( + std::unique_ptr const& context) { map result; if (context == nullptr) { IMAGE_LOGE("Context is nullptr"); - return result; + return optional>(std::nullopt); } if (context->status == OHOS::Media::SUCCESS) { result = CreatePropertiesRecord(context->kVStrArray); } else { CreateErrorArray(context); } - return result; + return optional>(std::in_place, result); } -map MetadataImpl::GetAllPropertiesSync() +optional> MetadataImpl::GetAllPropertiesSync() { std::unique_ptr context = std::make_unique(); context->rMetadata = nativeMetadata_; map result; if (context->rMetadata == nullptr) { - ImageTaiheUtils::ThrowExceptionError("Empty native metadata."); - return result; + IMAGE_LOGE("Empty native metadata."); + return optional>(std::nullopt); } GetAllPropertiesSyncExecute(context); - result = GetAllPropertiesSyncComplete(context); - return result; + return GetAllPropertiesSyncComplete(context); } -Metadata MetadataImpl::CloneSync() +optional MetadataImpl::CloneSync() { if (nativeMetadata_ == nullptr) { - ImageTaiheUtils::ThrowExceptionError("Empty native metadata."); - return make_holder(); + IMAGE_LOGE("Empty native metadata."); + return optional(std::nullopt); } auto metadata = nativeMetadata_->CloneMetadata(); - return make_holder(std::move(metadata)); + if (metadata == nullptr) { + ImageTaiheUtils::ThrowExceptionError("Clone metadata failed."); + return optional(std::nullopt); + } + auto result = make_holder(std::move(metadata)); + return optional(std::in_place, result); } void MetadataImpl::Release() diff --git a/frameworks/kits/taihe/src/picture_taihe.cpp b/frameworks/kits/taihe/src/picture_taihe.cpp index 9780775b6ea05765a4a8580371022b2962bb5fb9..9778a01be1981bc9e4d91b9c6416f2604dae4be7 100644 --- a/frameworks/kits/taihe/src/picture_taihe.cpp +++ b/frameworks/kits/taihe/src/picture_taihe.cpp @@ -69,42 +69,44 @@ Picture PictureImpl::CreatePicture(std::shared_ptr picture return make_holder(picture); } -PixelMap PictureImpl::GetMainPixelmap() +optional PictureImpl::GetMainPixelmap() { if (nativePicture_ == nullptr) { - ImageTaiheUtils::ThrowExceptionError("Native picture is nullptr!"); - return make_holder(); + IMAGE_LOGE("Native picture is nullptr!"); + return optional(std::nullopt); } auto pixelmap = nativePicture_->GetMainPixel(); if (pixelmap == nullptr) { ImageTaiheUtils::ThrowExceptionError("Get main pixelmap failed, pixelmap is nullptr!"); - return make_holder(); + return optional(std::nullopt); } - return PixelMapImpl::CreatePixelMap(pixelmap); + auto res = PixelMapImpl::CreatePixelMap(pixelmap); + return optional(std::in_place, res); } -PixelMap PictureImpl::GetHdrComposedPixelmapSync() +optional PictureImpl::GetHdrComposedPixelmapSync() { IMAGE_LOGD("GetHdrComposedPixelMap IN"); if (nativePicture_ == nullptr) { - ImageTaiheUtils::ThrowExceptionError("Empty native pixelmap"); - return make_holder(); + IMAGE_LOGE("Empty native pixelmap"); + return optional(std::nullopt); } if (nativePicture_->GetAuxiliaryPicture(OHOS::Media::AuxiliaryPictureType::GAINMAP) == nullptr) { ImageTaiheUtils::ThrowExceptionError(IMAGE_UNSUPPORTED_OPERATION, "There is no GAINMAP"); - return make_holder(); + return optional(std::nullopt); } if (nativePicture_->GetMainPixel()->GetAllocatorType() != OHOS::Media::AllocatorType::DMA_ALLOC) { ImageTaiheUtils::ThrowExceptionError(IMAGE_UNSUPPORTED_OPERATION, "Unsupported operations"); - return make_holder(); + return optional(std::nullopt); } auto tmpixel = nativePicture_->GetHdrComposedPixelMap(); if (tmpixel == nullptr) { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERROR, "Get hdr composed pixelMap failed"); - return make_holder(); + return optional(std::nullopt); } - return PixelMapImpl::CreatePixelMap(std::move(tmpixel)); + auto res = PixelMapImpl::CreatePixelMap(std::move(tmpixel)); + return optional(std::in_place, res); } GainMap PictureImpl::GetGainmapPixelmap() @@ -113,7 +115,11 @@ GainMap PictureImpl::GetGainmapPixelmap() if (nativePicture_ != nullptr) { auto gainpixelmap = nativePicture_->GetGainmapPixelMap(); - return GainMap::make_type_gainMap(PixelMapImpl::CreatePixelMap(gainpixelmap)); + if (gainpixelmap != nullptr) { + return GainMap::make_type_gainMap(PixelMapImpl::CreatePixelMap(gainpixelmap)); + } else { + return GainMap::make_type_null(); + } } else { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERR_MEDIA_UNKNOWN, "Picture is a null pointer"); return GainMap::make_type_null(); @@ -175,6 +181,7 @@ AuxPicture PictureImpl::GetAuxiliaryPicture(AuxiliaryPictureType type) if (auxType == OHOS::Media::AuxiliaryPictureType::NONE) { ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "The type does not match the auxiliary picture type!"); + return result; } if (nativePicture_ != nullptr) { @@ -183,10 +190,10 @@ AuxPicture PictureImpl::GetAuxiliaryPicture(AuxiliaryPictureType type) result = AuxPicture::make_type_auxPicture( make_holder(std::move(auxiliaryPic))); } else { - ImageTaiheUtils::ThrowExceptionError("native auxiliary picture is nullptr!"); + IMAGE_LOGE("native auxiliary picture is nullptr!"); } } else { - ImageTaiheUtils::ThrowExceptionError("native picture is nullptr!"); + IMAGE_LOGE("native picture is nullptr!"); } return result; @@ -223,26 +230,27 @@ void PictureImpl::SetMetadataSync(MetadataType metadataType, weak::Metadata meta } } -Metadata PictureImpl::GetMetadataSync(MetadataType metadataType) +optional PictureImpl::GetMetadataSync(MetadataType metadataType) { IMAGE_LOGD("GetMetadata IN"); if (nativePicture_ == nullptr) { - ImageTaiheUtils::ThrowExceptionError("Empty native picture"); - return make_holder(); + IMAGE_LOGE("Empty native picture"); + return optional(std::nullopt); } uint32_t typeValue = metadataType.get_value(); if (typeValue != static_cast(OHOS::Media::MetadataType::EXIF)) { ImageTaiheUtils::ThrowExceptionError(IMAGE_UNSUPPORTED_METADATA, "Unsupport MetadataType"); - return make_holder(); + return optional(std::nullopt); } auto imageMetadata = std::reinterpret_pointer_cast(nativePicture_->GetExifMetadata()); if (imageMetadata == nullptr) { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERROR, "Get Metadata failed!"); - return make_holder(); + return optional(std::nullopt); } - return make_holder(imageMetadata); + auto res = make_holder(imageMetadata); + return optional(std::in_place, res); } static OHOS::MessageParcel* UnwarpMessageParcel(uintptr_t sequence)