From c7b02daa2c031d19c673a536f346b649308c0cb2 Mon Sep 17 00:00:00 2001 From: lyujiayi <654765554@qq.com> Date: Thu, 24 Jul 2025 22:46:45 +0800 Subject: [PATCH] fix: modify the overload method Signed-off-by: lyujiayi <654765554@qq.com> --- .../idl/ohos.multimedia.image.image.taihe | 59 ++++++++++------ .../kits/taihe/include/pixel_map_taihe.h | 15 ++++- frameworks/kits/taihe/src/pixel_map_taihe.cpp | 67 +++++++++++++++++-- 3 files changed, 112 insertions(+), 29 deletions(-) diff --git a/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe b/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe index 6f1fa6a92..73a6e9e2f 100644 --- a/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe +++ b/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe @@ -482,9 +482,11 @@ interface PixelMap { @gen_promise("writePixels") WritePixelsSync(area: PositionArea): void; - @gen_async("createAlphaPixelmap") - @gen_promise("createAlphaPixelmap") CreateAlphaPixelmapSync(): PixelMap; + @static_overload("createAlphaPixelmap") + @async CreateAlphaPixelmapWithCallback(): PixelMap; + @static_overload("createAlphaPixelmap") + @promise CreateAlphaPixelmapReturnsPromise(): PixelMap; GetBytesNumberPerRow(): i32; @@ -492,26 +494,37 @@ interface PixelMap { GetDensity(): i32; - @gen_async("scale") - @gen_promise("scale") - @overload("scaleSync") - ScaleSync(x: f64, y: f64): void; + @static_overload("scale") + @async ScaleWithCallback(x: f64, y: f64): void; + @static_overload("scale") + @promise ScaleReturnsPromise(x: f64, y: f64): void; - @gen_promise("scale") - @overload("scaleSync") - ScaleWithAntiAliasingSync(x: f64, y: f64, level: AntiAliasingLevel): void; + @static_overload("scaleSync") + ScaleSyncWithXY(x: f64, y: f64): void; + + @static_overload("scale") + @promise ScaleWithLevelReturnsPromise(x: f64, y: f64, level: AntiAliasingLevel): void; + + @static_overload("scaleSync") + ScaleSyncWithXYLevel(x: f64, y: f64, level: AntiAliasingLevel): void; - @gen_async("crop") - @gen_promise("crop") CropSync(region: Region): void; + @static_overload("crop") + @async CropWithCallback(region: Region): void; + @static_overload("crop") + @promise CropReturnsPromise(region: Region): void; - @gen_async("rotate") - @gen_promise("rotate") RotateSync(angle: f64): void; + @static_overload("rotate") + @async RotateWithCallback(angle: f64): void; + @static_overload("rotate") + @promise RotateReturnsPromise(angle: f64): void; - @gen_async("flip") - @gen_promise("flip") FlipSync(horizontal: bool, vertical: bool): void; + @static_overload("flip") + @async FlipWithCallback(horizontal: bool, vertical: bool): void; + @static_overload("flip") + @promise FlipReturnsPromise(horizontal: bool, vertical: bool): void; @gen_async("opacity") @gen_promise("opacity") @@ -878,20 +891,22 @@ function MakeEmptyImageInfo(): ImageInfo; @gen_async("createPixelMap") @gen_promise("createPixelMap") -@overload("createPixelMapSync") function CreatePixelMapByBufferAndOptionsSync(colors: @arraybuffer Array, options: InitializationOptions): PixelMap; -@overload("createPixelMapSync") -function CreatePixelMapByOptionsSync(options: InitializationOptions): PixelMap; +@static_overload("createPixelMapSync") +function CreatePixelMapSyncWithColorsOptions(colors: @arraybuffer Array, options: InitializationOptions): PixelMap; + +@static_overload("createPixelMapSync") +function CreatePixelMapSyncWithOptions(options: InitializationOptions): PixelMap; // For legacy ANI backward compatibility function CreatePixelMapByPtr(ptr: i64): PixelMap; -@overload("createPixelMapFromSurfaceSync") -function CreatePixelMapFromSurfaceByIdSync(surfaceId: String): PixelMap; +@static_overload("createPixelMapFromSurfaceSync") +function CreatePixelMapFromSurfaceSyncWithSurfaceId(surfaceId: String): PixelMap; -@overload("createPixelMapFromSurfaceSync") -function CreatePixelMapFromSurfaceByIdAndRegionSync(surfaceId: String, region: Region): PixelMap; +@static_overload("createPixelMapFromSurfaceSync") +function CreatePixelMapFromSurfaceSyncWithSurfaceIdRegion(surfaceId: String, region: Region): PixelMap; function CreatePixelMapFromParcel(sequence: @sts_type("rpc.MessageSequence") Opaque): PixelMap; diff --git a/frameworks/kits/taihe/include/pixel_map_taihe.h b/frameworks/kits/taihe/include/pixel_map_taihe.h index e4b64a83b..b151240e7 100644 --- a/frameworks/kits/taihe/include/pixel_map_taihe.h +++ b/frameworks/kits/taihe/include/pixel_map_taihe.h @@ -46,14 +46,25 @@ public: void WriteBufferToPixelsSync(array_view src); void WritePixelsSync(weak::PositionArea area); PixelMap CreateAlphaPixelmapSync(); + PixelMap CreateAlphaPixelmapWithCallback(); + PixelMap CreateAlphaPixelmapReturnsPromise(); int32_t GetBytesNumberPerRow(); int32_t GetPixelBytesNumber(); int32_t GetDensity(); - void ScaleSync(double x, double y); - void ScaleWithAntiAliasingSync(double x, double y, AntiAliasingLevel level); + void ScaleSyncWithXY(double x, double y); + void ScaleWithCallback(double x, double y); + void ScaleReturnsPromise(double x, double y); + void ScaleSyncWithXYLevel(double x, double y, AntiAliasingLevel level); + void ScaleWithLevelReturnsPromise(double x, double y, AntiAliasingLevel level); void CropSync(ohos::multimedia::image::image::Region const& region); + void CropWithCallback(ohos::multimedia::image::image::Region const& region); + void CropReturnsPromise(ohos::multimedia::image::image::Region const& region); void RotateSync(double angle); + void RotateWithCallback(double angle); + void RotateReturnsPromise(double angle); void FlipSync(bool horizontal, bool vertical); + void FlipWithCallback(bool horizontal, bool vertical); + void FlipReturnsPromise(bool horizontal, bool vertical); void OpacitySync(double rate); void SetMemoryNameSync(string_view name); void SetTransferDetached(bool detached); diff --git a/frameworks/kits/taihe/src/pixel_map_taihe.cpp b/frameworks/kits/taihe/src/pixel_map_taihe.cpp index 8152ad67b..21c43b513 100644 --- a/frameworks/kits/taihe/src/pixel_map_taihe.cpp +++ b/frameworks/kits/taihe/src/pixel_map_taihe.cpp @@ -371,6 +371,16 @@ PixelMap PixelMapImpl::CreateAlphaPixelmapSync() return make_holder(std::move(alphaPixelMap)); } +PixelMap PixelMapImpl::CreateAlphaPixelmapWithCallback() +{ + return this->CreateAlphaPixelmapSync(); +} + +PixelMap PixelMapImpl::CreateAlphaPixelmapReturnsPromise() +{ + return this->CreateAlphaPixelmapSync(); +} + int32_t PixelMapImpl::GetBytesNumberPerRow() { if (nativePixelMap_ == nullptr) { @@ -413,7 +423,7 @@ int32_t PixelMapImpl::GetDensity() return nativePixelMap_->GetBaseDensity(); } -void PixelMapImpl::ScaleSync(double x, double y) +void PixelMapImpl::ScaleSyncWithXY(double x, double y) { if (nativePixelMap_ == nullptr) { IMAGE_LOGE("[%{public}s] Native PixelMap is nullptr", __func__); @@ -427,7 +437,17 @@ void PixelMapImpl::ScaleSync(double x, double y) nativePixelMap_->scale(static_cast(x), static_cast(y)); } -void PixelMapImpl::ScaleWithAntiAliasingSync(double x, double y, AntiAliasingLevel level) +void PixelMapImpl::ScaleWithCallback(double x, double y) +{ + return this->ScaleSyncWithXY(x, y); +} + +void PixelMapImpl::ScaleReturnsPromise(double x, double y) +{ + return this->ScaleSyncWithXY(x, y); +} + +void PixelMapImpl::ScaleSyncWithXYLevel(double x, double y, AntiAliasingLevel level) { if (nativePixelMap_ == nullptr) { IMAGE_LOGE("[%{public}s] Native PixelMap is nullptr", __func__); @@ -441,6 +461,11 @@ void PixelMapImpl::ScaleWithAntiAliasingSync(double x, double y, AntiAliasingLev nativePixelMap_->scale(static_cast(x), static_cast(y), Media::AntiAliasingOption(level.get_value())); } +void PixelMapImpl::ScaleWithLevelReturnsPromise(double x, double y, AntiAliasingLevel level) +{ + return this->ScaleSyncWithXYLevel(x, y, level); +} + void PixelMapImpl::CropSync(ohos::multimedia::image::image::Region const& region) { if (nativePixelMap_ == nullptr) { @@ -459,6 +484,16 @@ void PixelMapImpl::CropSync(ohos::multimedia::image::image::Region const& region } } +void PixelMapImpl::CropWithCallback(ohos::multimedia::image::image::Region const& region) +{ + return this->CropSync(region); +} + +void PixelMapImpl::CropReturnsPromise(ohos::multimedia::image::image::Region const& region) +{ + return this->CropSync(region); +} + void PixelMapImpl::RotateSync(double angle) { if (nativePixelMap_ == nullptr) { @@ -473,6 +508,16 @@ void PixelMapImpl::RotateSync(double angle) nativePixelMap_->rotate(static_cast(angle)); } +void PixelMapImpl::RotateWithCallback(double angle) +{ + return this->RotateSync(angle); +} + +void PixelMapImpl::RotateReturnsPromise(double angle) +{ + return this->RotateSync(angle); +} + void PixelMapImpl::FlipSync(bool horizontal, bool vertical) { if (nativePixelMap_ == nullptr) { @@ -487,6 +532,16 @@ void PixelMapImpl::FlipSync(bool horizontal, bool vertical) nativePixelMap_->flip(horizontal, vertical); } +void PixelMapImpl::FlipWithCallback(bool horizontal, bool vertical) +{ + return this->FlipSync(horizontal, vertical); +} + +void PixelMapImpl::FlipReturnsPromise(bool horizontal, bool vertical) +{ + return this->FlipSync(horizontal, vertical); +} + void PixelMapImpl::OpacitySync(double rate) { if (nativePixelMap_ == nullptr) { @@ -818,8 +873,10 @@ void PixelMapImpl::Release() TH_EXPORT_CPP_API_MakeEmptySize(ANI::Image::MakeEmptySize); TH_EXPORT_CPP_API_MakeEmptyImageInfo(ANI::Image::MakeEmptyImageInfo); TH_EXPORT_CPP_API_CreatePixelMapByBufferAndOptionsSync(ANI::Image::CreatePixelMapByBufferAndOptionsSync); -TH_EXPORT_CPP_API_CreatePixelMapByOptionsSync(ANI::Image::CreatePixelMapByOptionsSync); +TH_EXPORT_CPP_API_CreatePixelMapSyncWithColorsOptions(ANI::Image::CreatePixelMapByBufferAndOptionsSync); +TH_EXPORT_CPP_API_CreatePixelMapSyncWithOptions(ANI::Image::CreatePixelMapByOptionsSync); TH_EXPORT_CPP_API_CreatePixelMapByPtr(ANI::Image::CreatePixelMapByPtr); -TH_EXPORT_CPP_API_CreatePixelMapFromSurfaceByIdSync(ANI::Image::CreatePixelMapFromSurfaceByIdSync); -TH_EXPORT_CPP_API_CreatePixelMapFromSurfaceByIdAndRegionSync(ANI::Image::CreatePixelMapFromSurfaceByIdAndRegionSync); +TH_EXPORT_CPP_API_CreatePixelMapFromSurfaceSyncWithSurfaceId(ANI::Image::CreatePixelMapFromSurfaceByIdSync); +TH_EXPORT_CPP_API_CreatePixelMapFromSurfaceSyncWithSurfaceIdRegion( \ + ANI::Image::CreatePixelMapFromSurfaceByIdAndRegionSync); TH_EXPORT_CPP_API_CreatePixelMapFromParcel(ANI::Image::CreatePixelMapFromParcel); \ No newline at end of file -- Gitee