diff --git a/frameworks/kits/taihe/BUILD.gn b/frameworks/kits/taihe/BUILD.gn index 3912e5cac0857a79f83df41c7bfd47d6102e4a85..dd9f90bdb681974df94a7a6a1cf4e7a15e42fba6 100644 --- a/frameworks/kits/taihe/BUILD.gn +++ b/frameworks/kits/taihe/BUILD.gn @@ -69,19 +69,20 @@ template("image_taihe_shared_library") { sources = get_target_outputs(":run_taihe") sources += [ - "${image_subsystem}/frameworks/innerkitsimpl/accessor/src/exif_metadata_formatter.cpp", - "src/auxiliary_picture_taihe.cpp", - "src/image_creator_taihe.cpp", - "src/image_packer_taihe.cpp", - "src/image_receiver_taihe.cpp", - "src/image_source_taihe.cpp", - "src/image_taihe.cpp", - "src/image_taihe_utils.cpp", - "src/metadata_taihe.cpp", - "src/picture_taihe.cpp", - "src/pixel_map_taihe.cpp", - "src/transfer_taihe.cpp", - ] + extra_sources + "${image_subsystem}/frameworks/innerkitsimpl/accessor/src/exif_metadata_formatter.cpp", + "${image_subsystem}/frameworks/kits/js/common/image_error_convert.cpp", + "src/auxiliary_picture_taihe.cpp", + "src/image_creator_taihe.cpp", + "src/image_packer_taihe.cpp", + "src/image_receiver_taihe.cpp", + "src/image_source_taihe.cpp", + "src/image_taihe.cpp", + "src/image_taihe_utils.cpp", + "src/metadata_taihe.cpp", + "src/picture_taihe.cpp", + "src/pixel_map_taihe.cpp", + "src/transfer_taihe.cpp", + ] + extra_sources deps = [ ":run_taihe", diff --git a/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe b/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe index 023cd71b5c0aa2b76eb020bef067b1bd593f4f0f..113053ad37b428f52b15b9a31f164e7a7305d2d7 100644 --- a/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe +++ b/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe @@ -426,6 +426,7 @@ enum AuxiliaryPictureType: i32 { enum MetadataType: i32 { EXIF_METADATA = 1, FRAGMENT_METADATA = 2, + GIF_METADATA = 5 } enum FragmentMapPropertyKey: String { @@ -435,6 +436,11 @@ enum FragmentMapPropertyKey: String { HEIGHT = "FragmentImageHeight" } +enum GifPropertyKey: String { + GIF_DELAY_TIME = "GifDelayTime", + GIF_DISPOSAL_TYPE = "GifDisposalType" +} + struct DecodingOptionsForPicture { desiredAuxiliaryPictures: Array; } @@ -712,12 +718,13 @@ interface ImageSource { @gen_promise("getFrameCount") GetFrameCountSync(): i32; - @gen_promise("getImageProperty") - GetImagePropertySync(key: PropertyKey, options: Optional): String; + @promise GetImageProperty(key: PropertyKey, options: Optional): String; @gen_promise("getImageProperties") GetImagePropertiesSync(key: Array): @record Map; + GetImagePropertySync(key: PropertyKey): String; + @gen_promise("modifyImageProperty") ModifyImagePropertySync(key: PropertyKey, value: String): void; @@ -735,6 +742,10 @@ interface ImageSource { @gen_promise("createPicture") CreatePictureSync(options: Optional): Picture; + @promise CreatePictureAtIndex(index: i32): Optional; + + @promise CreateWideGamutSdrPixelMap(): PixelMap; + @get GetSupportedFormats(): Array; } @@ -993,6 +1004,10 @@ function CreateIncrementalSourceByArrayBufferOption(buf: @arraybuffer Array, @overload("createImageSource") function CreateImageSourceByRawFileDescriptorOption(rawfile: @sts_type("resourceManager.RawFileDescriptor") Opaque, options: Optional): ImageSource; +function GetImageSourceSupportedFormats(): Array; + +function GetImagePackerSupportedFormats(): Array; + // For legacy ANI backward compatibility function CreateImageSourceByPtr(ptr: i64): ImageSource; @@ -1010,4 +1025,6 @@ function CreatePictureByPtr(ptr: i64): Picture; function CreatePictureFromParcel(sequence: @sts_type("rpc.MessageSequence") Opaque): Picture; -function CreateAuxiliaryPicture(buffer: @arraybuffer Array, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture; \ No newline at end of file +function CreateAuxiliaryPicture(buffer: @arraybuffer Array, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture; + +@promise function CreatePictureByHdrAndSdrPixelMap(hdrPixelMap: PixelMap, sdrPixelMap: PixelMap): Picture; \ No newline at end of file diff --git a/frameworks/kits/taihe/include/image_source_taihe.h b/frameworks/kits/taihe/include/image_source_taihe.h index fd390e743aec3e3828598697408f3bd266ba289e..d827136766d7438c0a04ed48c497a6a8fdefd0b9 100644 --- a/frameworks/kits/taihe/include/image_source_taihe.h +++ b/frameworks/kits/taihe/include/image_source_taihe.h @@ -42,20 +42,23 @@ public: PixelMap CreatePixelMapSync(); PixelMap CreatePixelMapUsingAllocatorSync(optional_view options, optional_view allocatorType); + PixelMap CreateWideGamutSdrPixelMap(); array CreatePixelMapListSync(); array CreatePixelMapListSyncWithOptions(DecodingOptions const& options); array CreatePixelMapListSyncWithOptionalOptions(optional_view options); array GetDelayTimeListSync(); array GetDisposalTypeListSync(); int32_t GetFrameCountSync(); - string GetImagePropertySync(PropertyKey key, optional_view options); + string GetImageProperty(PropertyKey key, optional_view options); map GetImagePropertiesSync(array_view key); + string GetImagePropertySync(PropertyKey key); void ModifyImagePropertySync(PropertyKey key, string_view value); void ModifyImagePropertiesSync(map_view records); 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 CreatePictureAtIndex(int32_t index); #endif array GetSupportedFormats(); diff --git a/frameworks/kits/taihe/src/image_packer_taihe.cpp b/frameworks/kits/taihe/src/image_packer_taihe.cpp index d418440b5e3fe881e18a9503a491703e6557eec4..4d544447cef172cfa72fd5c7901984588983bf0d 100644 --- a/frameworks/kits/taihe/src/image_packer_taihe.cpp +++ b/frameworks/kits/taihe/src/image_packer_taihe.cpp @@ -796,6 +796,17 @@ ImagePacker CreateImagePacker() std::shared_ptr imagePacker = std::make_shared(); return make_holder(imagePacker); } + +array GetImagePackerSupportedFormats() +{ + std::set formats; + uint32_t ret = OHOS::Media::ImagePacker::GetSupportedFormats(formats); + if (ret != OHOS::Media::SUCCESS) { + ImageTaiheUtils::ThrowExceptionError("Fail to get decode supported formats"); + } + return ImageTaiheUtils::ToTaiheArrayString(std::vector(formats.begin(), formats.end())); +} } // namespace ANI::Image -TH_EXPORT_CPP_API_CreateImagePacker(CreateImagePacker); \ No newline at end of file +TH_EXPORT_CPP_API_CreateImagePacker(CreateImagePacker); +TH_EXPORT_CPP_API_GetImagePackerSupportedFormats(GetImagePackerSupportedFormats); \ No newline at end of file diff --git a/frameworks/kits/taihe/src/image_source_taihe.cpp b/frameworks/kits/taihe/src/image_source_taihe.cpp index 43eb28cb7b93600547f4e35bbf6ff0ef61a88e7d..1bbf850c85ee00b6d1f74900b09aeacf6ed3ab55 100644 --- a/frameworks/kits/taihe/src/image_source_taihe.cpp +++ b/frameworks/kits/taihe/src/image_source_taihe.cpp @@ -16,6 +16,7 @@ #include "ani_color_space_object_convertor.h" #include "image_common.h" #include "image_dfx.h" +#include "image_error_convert.h" #include "image_log.h" #include "image_source_taihe.h" #include "image_source_taihe_ani.h" @@ -576,6 +577,44 @@ PixelMap ImageSourceImpl::CreatePixelMapUsingAllocatorSync(optional_view pixelMap; + auto incPixelMap = this->GetIncrementalPixelMap(); + if (incPixelMap != nullptr) { + IMAGE_LOGD("Get Incremental PixelMap!!!"); + pixelMap = incPixelMap; + } else { + if (nativeImgSrc == nullptr) { + IMAGE_LOGE("Invailed args"); + pixelMap = nullptr; + status = OHOS::Media::ERROR; + } else { + decodeOpts.invokeType = OHOS::Media::JS_INTERFACE; + pixelMap = nativeImgSrc->CreatePixelMapEx(index, decodeOpts, status); + } + } + if (status != OHOS::Media::SUCCESS || pixelMap == nullptr) { + IMAGE_LOGE("Create PixelMap error"); + if (status != OHOS::Media::SUCCESS) { + IMAGE_LOGE("CreateWideGamutSdrPixelMap error"); + Image_ErrorCode apiErrorCode = ConvertToErrorCode(status); + std::string apiErrorMsg = GetErrorCodeMsg(apiErrorCode); + ImageTaiheUtils::ThrowExceptionError(apiErrorCode, apiErrorMsg); + } + return make_holder(); + } + return make_holder(std::move(pixelMap)); +} + static bool CheckAsyncContext(std::unique_ptr &taiheContext, bool check) { if (taiheContext == nullptr) { @@ -806,9 +845,9 @@ static void GenerateErrMsg(std::unique_ptr &context, st } } -string ImageSourceImpl::GetImagePropertySync(PropertyKey key, optional_view options) +string ImageSourceImpl::GetImageProperty(PropertyKey key, optional_view options) { - OHOS::Media::ImageTrace imageTrace("ImageSourceImpl::GetImagePropertySync"); + OHOS::Media::ImageTrace imageTrace("ImageSourceImpl::GetImagePropertyImpl"); std::unique_ptr context = std::make_unique(); if (nativeImgSrc == nullptr) { @@ -834,6 +873,34 @@ string ImageSourceImpl::GetImagePropertySync(PropertyKey key, optional_viewvalueStr; } +string ImageSourceImpl::GetImagePropertySync(PropertyKey key) +{ + OHOS::Media::ImageTrace imageTrace("ImageSourceImpl::GetImagePropertySync"); + IMAGE_LOGD("GetImagePropertySync IN"); + + std::string propertyKey = key.get_value(); + std::string value = ""; + + if (nativeImgSrc != nullptr) { + uint32_t ret = nativeImgSrc->GetImagePropertyStringBySync(NUM_0, propertyKey, value); + if (ret == OHOS::Media::ERR_IMAGE_PROPERTY_NOT_EXIST) { + IMAGE_LOGE("%{public}s: Unsupported metadata, errorCode=%{public}u", __func__, ret); + ImageTaiheUtils::ThrowExceptionError(IMAGE_SOURCE_UNSUPPORTED_METADATA, "Unsupported metadata"); + } + if (ret == OHOS::Media::ERR_IMAGE_SOURCE_DATA) { + IMAGE_LOGE("%{public}s: Unsupported MIME type, errorCode=%{public}u", __func__, ret); + ImageTaiheUtils::ThrowExceptionError(IMAGE_SOURCE_UNSUPPORTED_MIMETYPE, "Unsupported MIME type"); + } + if (ret == OHOS::Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT) { + IMAGE_LOGE("%{public}s: Bad source, errorCode=%{public}u", __func__, ret); + ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_SOURCE, "Bad source"); + } + } else { + ImageTaiheUtils::ThrowExceptionError("empty native image source"); + } + return value; +} + static void GetImagePropertiesExecute(std::unique_ptr &context) { if (context == nullptr) { @@ -1258,6 +1325,24 @@ Picture ImageSourceImpl::CreatePictureSync(optional_view ImageSourceImpl::CreatePictureAtIndex(int32_t index) +{ + if (nativeImgSrc == nullptr) { + ImageTaiheUtils::ThrowExceptionError("empty native rImageSource"); + return optional(std::nullopt); + } + + uint32_t errCode = OHOS::Media::ERR_MEDIA_INVALID_VALUE; + auto picture = nativeImgSrc->CreatePictureAtIndex(index, errCode); + if (errCode != OHOS::Media::SUCCESS || picture == nullptr) { + auto errMsg = OHOS::Media::ImageErrorConvert::CreatePictureAtIndexMakeErrMsg(errCode); + ImageTaiheUtils::ThrowExceptionError(errMsg.first, errMsg.second); + return optional(std::nullopt); + } + auto res = make_holder(std::move(picture)); + return optional(std::in_place, res); +} #endif array ImageSourceImpl::GetSupportedFormats() @@ -1430,6 +1515,16 @@ ImageSource CreateImageSourceByPtr(int64_t ptr) { return taihe::make_holder(ptr); } + +array GetImageSourceSupportedFormats() +{ + std::set formats; + uint32_t ret = OHOS::Media::ImageSource::GetSupportedFormats(formats); + if (ret != OHOS::Media::SUCCESS) { + ImageTaiheUtils::ThrowExceptionError("Fail to get decode supported formats"); + } + return ImageTaiheUtils::ToTaiheArrayString(std::vector(formats.begin(), formats.end())); +} } // namespace ANI::Image TH_EXPORT_CPP_API_CreateImageSourceByUri(CreateImageSourceByUri); @@ -1441,4 +1536,5 @@ TH_EXPORT_CPP_API_CreateImageSourceByArrayBufferOption(CreateImageSourceByArrayB TH_EXPORT_CPP_API_CreateImageSourceByRawFileDescriptorOption(CreateImageSourceByRawFileDescriptorOption); TH_EXPORT_CPP_API_CreateIncrementalSourceByArrayBuffer(CreateIncrementalSourceByArrayBuffer); TH_EXPORT_CPP_API_CreateIncrementalSourceByArrayBufferOption(CreateIncrementalSourceByArrayBufferOption); -TH_EXPORT_CPP_API_CreateImageSourceByPtr(CreateImageSourceByPtr); \ No newline at end of file +TH_EXPORT_CPP_API_CreateImageSourceByPtr(CreateImageSourceByPtr); +TH_EXPORT_CPP_API_GetImageSourceSupportedFormats(GetImageSourceSupportedFormats); \ No newline at end of file diff --git a/frameworks/kits/taihe/src/picture_taihe.cpp b/frameworks/kits/taihe/src/picture_taihe.cpp index eeeed8a41a8145226cbfe86bb8b5f5174f309aa1..8b022010be454cfd79f8e4d44ad48f711c168eaa 100644 --- a/frameworks/kits/taihe/src/picture_taihe.cpp +++ b/frameworks/kits/taihe/src/picture_taihe.cpp @@ -202,7 +202,7 @@ void PictureImpl::SetMetadataSync(MetadataType metadataType, weak::Metadata meta OHOS::Media::MetadataType type; uint32_t typeValue = metadataType.get_value(); - if (typeValue == static_cast(OHOS::Media::MetadataType::EXIF)) { + if (OHOS::Media::Picture::IsValidPictureMetadataType(static_cast(typeValue))) { type = OHOS::Media::MetadataType(typeValue); } else { ImageTaiheUtils::ThrowExceptionError(IMAGE_UNSUPPORTED_METADATA, "Unsupport MetadataType"); @@ -216,8 +216,7 @@ void PictureImpl::SetMetadataSync(MetadataType metadataType, weak::Metadata meta } std::shared_ptr imageMetadata = metadataImpl->GetNativeMetadata(); - int32_t status = nativePicture_->SetExifMetadata( - std::reinterpret_pointer_cast(imageMetadata)); + int32_t status = nativePicture_->SetMetadata(type, imageMetadata); if (status != OHOS::Media::SUCCESS) { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERROR, "Set Metadata failed!"); } @@ -232,12 +231,12 @@ Metadata PictureImpl::GetMetadataSync(MetadataType metadataType) } uint32_t typeValue = metadataType.get_value(); - if (typeValue != static_cast(OHOS::Media::MetadataType::EXIF)) { + if (!OHOS::Media::Picture::IsValidPictureMetadataType(static_cast(typeValue))) { ImageTaiheUtils::ThrowExceptionError(IMAGE_UNSUPPORTED_METADATA, "Unsupport MetadataType"); return make_holder(); } - auto imageMetadata = std::reinterpret_pointer_cast(nativePicture_->GetExifMetadata()); + auto imageMetadata = nativePicture_->GetMetadata(static_cast(typeValue)); if (imageMetadata == nullptr) { ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERROR, "Get Metadata failed!"); return make_holder(); @@ -331,8 +330,42 @@ Picture CreatePictureByPtr(int64_t aniPtr) return make_holder(aniPtr); } +Picture CreatePictureByHdrAndSdrPixelMap(weak::PixelMap hdrPixelMap, weak::PixelMap sdrPixelMap) +{ + IMAGE_LOGD("CreatePictureByHdrAndSdrPixelMap IN"); + if (hdrPixelMap.is_error()) { + ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "Get arg hdr Pixelmap failed"); + return make_holder(nullptr); + } + if (sdrPixelMap.is_error()) { + ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "Get arg sdr Pixelmap failed"); + return make_holder(nullptr); + } + + PixelMapImpl* hdrPixelMapImpl = reinterpret_cast(hdrPixelMap->GetImplPtr()); + PixelMapImpl* sdrPixelMapImpl = reinterpret_cast(sdrPixelMap->GetImplPtr()); + if (hdrPixelMapImpl == nullptr) { + ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "Get arg hdr Pixelmap failed"); + return make_holder(nullptr); + } + if (sdrPixelMapImpl == nullptr) { + ImageTaiheUtils::ThrowExceptionError(IMAGE_BAD_PARAMETER, "Get arg sdr Pixelmap failed"); + return make_holder(nullptr); + } + + auto nativeHdrPixelMap = hdrPixelMapImpl->GetNativePtr(); + auto nativeSdrPixelMap = sdrPixelMapImpl->GetNativePtr(); + auto picture = OHOS::Media::Picture::CreatePictureByHdrAndSdrPixelMap(nativeHdrPixelMap, nativeSdrPixelMap); + if (picture == nullptr) { + ImageTaiheUtils::ThrowExceptionError(OHOS::Media::ERROR, "Create picture failed!"); + return make_holder(nullptr); + } + IMAGE_LOGD("CreatePictureByHdrAndSdrPixelMap OUT"); + return make_holder(std::move(picture)); +} } // namespace ANI::Image TH_EXPORT_CPP_API_CreatePictureByPixelMap(CreatePictureByPixelMap); TH_EXPORT_CPP_API_CreatePictureFromParcel(CreatePictureFromParcel); -TH_EXPORT_CPP_API_CreatePictureByPtr(CreatePictureByPtr); \ No newline at end of file +TH_EXPORT_CPP_API_CreatePictureByPtr(CreatePictureByPtr); +TH_EXPORT_CPP_API_CreatePictureByHdrAndSdrPixelMap(CreatePictureByHdrAndSdrPixelMap); \ No newline at end of file