From c5907b4836f54a3fdc579a8d0aeadfe70e9c21d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=B9=94=E5=BC=82?= Date: Thu, 24 Jul 2025 16:35:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E9=9D=99=E6=80=81=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈乔异 --- frameworks/kits/taihe/BUILD.gn | 8 ++++ .../idl/ohos.multimedia.image.image.taihe | 14 ++++++ frameworks/kits/taihe/src/pixel_map_taihe.cpp | 46 ++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/frameworks/kits/taihe/BUILD.gn b/frameworks/kits/taihe/BUILD.gn index 49ced9a7c..5fe3c319e 100644 --- a/frameworks/kits/taihe/BUILD.gn +++ b/frameworks/kits/taihe/BUILD.gn @@ -62,7 +62,9 @@ template("image_taihe_shared_library") { include_dirs = [ "include", + "${image_subsystem}/frameworks/kits/js/common/include", "${image_subsystem}/interfaces/innerkits/include", + "${image_subsystem}/interfaces/kits/js/common/include", "${image_subsystem}/interfaces/kits/native/include/image", "${image_subsystem}/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder", ] @@ -70,6 +72,8 @@ template("image_taihe_shared_library") { sources = get_target_outputs(":run_taihe") sources += [ "${image_subsystem}/frameworks/innerkitsimpl/accessor/src/exif_metadata_formatter.cpp", + "${image_subsystem}/frameworks/kits/js/common/image_napi_utils.cpp", + "${image_subsystem}/frameworks/kits/js/common/pixel_map_napi.cpp", "src/auxiliary_picture_taihe.cpp", "src/image_creator_taihe.cpp", "src/image_packer_taihe.cpp", @@ -91,19 +95,23 @@ template("image_taihe_shared_library") { external_deps = [ "c_utils:utils", + "drivers_interface_display:libdisplay_commontype_proxy_1.0", "eventhandler:libeventhandler", "graphic_2d:EGL", "graphic_2d:ani_color_space_object_convertor", "graphic_2d:color_manager", + "graphic_2d:color_space_object_convertor", "graphic_2d:librender_service_base", "graphic_2d:librender_service_client", "graphic_surface:surface", "graphic_surface:sync_fence", "hilog:libhilog", "hitrace:hitrace_meter", + "ipc:ipc_napi", "ipc:ipc_single", "ipc:rpc_ani", "libjpeg-turbo:turbojpeg", + "napi:ace_napi", "runtime_core:ani_helpers", ] diff --git a/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe b/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe index a98595f9a..b39964188 100644 --- a/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe +++ b/frameworks/kits/taihe/idl/ohos.multimedia.image.image.taihe @@ -895,6 +895,20 @@ function CreatePixelMapFromSurfaceByIdAndRegionSync(surfaceId: String, region: R function CreatePixelMapFromParcel(sequence: @sts_type("rpc.MessageSequence") Opaque): PixelMap; +function PixelMapTransferStaticImpl(input: @sts_type("ESValue") Opaque): PixelMap; + +function PixelMapTransferDynamicImpl(input: PixelMap): @sts_type("Any") Opaque; + +@!sts_inject(""" +export function pixelMapTransferStatic(input: Any): Object { + return pixelMapTransferStaticImpl(ESValue.wrap(input)); +} + +export function pixelMapTransferDynamic(input: Object): Any { + return pixelMapTransferDynamicImpl(input as PixelMap); +} +""") + @overload("createImageSource") function CreateImageSourceByUri(uri: String): ImageSource; diff --git a/frameworks/kits/taihe/src/pixel_map_taihe.cpp b/frameworks/kits/taihe/src/pixel_map_taihe.cpp index 8152ad67b..ddcf02ab6 100644 --- a/frameworks/kits/taihe/src/pixel_map_taihe.cpp +++ b/frameworks/kits/taihe/src/pixel_map_taihe.cpp @@ -21,8 +21,11 @@ #include "image_log.h" #include "image_taihe_utils.h" #include "image_utils.h" +#include "interop_js/arkts_interop_js_api.h" +#include "interop_js/arkts_esvalue.h" #include "media_errors.h" #include "message_parcel.h" +#include "pixel_map_napi.h" #include "pixel_map_taihe_ani.h" #include "taihe/runtime.hpp" #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) @@ -181,6 +184,45 @@ PixelMap CreatePixelMapFromParcel(uintptr_t sequence) return Unmarshalling(sequence); } +PixelMap PixelMapTransferStaticImpl(uintptr_t input) { + ani_object esValue = reinterpret_cast(input); + void* nativePtr = nullptr; + if (!arkts_esvalue_unwrap(get_env(), esValue, &nativePtr) || nativePtr == nullptr) { + ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Unwrap ESValue failed"); + return make_holder(); + } + + auto pixelMapNapi = reinterpret_cast*>(nativePtr)->lock(); + if (pixelMapNapi == nullptr) { + ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Transfer PixelMap failed"); + return make_holder(); + } + + return make_holder(pixelMapNapi->GetPixelNapiInner()); +} + +uintptr_t PixelMapTransferDynamicImpl(weak::PixelMap input) { + PixelMapImpl* implPtr = reinterpret_cast(input->GetImplPtr()); + std::shared_ptr pixelMap = implPtr->GetNativePtr(); + implPtr = nullptr; + napi_env jsEnv; + if (!arkts_napi_scope_open(get_env(), &jsEnv)) { + ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "NAPI scope open failed"); + return 0; + } + + napi_value pixelMapJs = Media::PixelMapNapi::CreatePixelMap(jsEnv, pixelMap); + napi_valuetype type; + napi_typeof(jsEnv, pixelMapJs, &type); + if (type == napi_undefined) { + ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "PixelMapNapi create failed"); + arkts_napi_scope_close_n(jsEnv, 0, nullptr, nullptr); + return 0; + } + + return reinterpret_cast(pixelMapJs); +} + PixelMapImpl::PixelMapImpl() {} PixelMapImpl::PixelMapImpl(array_view const& colors, InitializationOptions const& etsOptions) @@ -822,4 +864,6 @@ TH_EXPORT_CPP_API_CreatePixelMapByOptionsSync(ANI::Image::CreatePixelMapByOption 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_CreatePixelMapFromParcel(ANI::Image::CreatePixelMapFromParcel); \ No newline at end of file +TH_EXPORT_CPP_API_CreatePixelMapFromParcel(ANI::Image::CreatePixelMapFromParcel); +TH_EXPORT_CPP_API_PixelMapTransferStaticImpl(ANI::Image::PixelMapTransferStaticImpl); +TH_EXPORT_CPP_API_PixelMapTransferDynamicImpl(ANI::Image::PixelMapTransferDynamicImpl); \ No newline at end of file -- Gitee