From 656bd00137e9d87edd3e698ea72f9c1652fe10e0 Mon Sep 17 00:00:00 2001 From: zhang-xiaobo1997 Date: Sat, 19 Feb 2022 18:35:55 +0800 Subject: [PATCH 1/3] Modify for Packing inf api 7 Signed-off-by: zhang-xiaobo1997 --- .../kits/js/common/image_packer_napi.cpp | 69 ++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/frameworks/kits/js/common/image_packer_napi.cpp b/frameworks/kits/js/common/image_packer_napi.cpp index 0f114c1cd..650b617c5 100644 --- a/frameworks/kits/js/common/image_packer_napi.cpp +++ b/frameworks/kits/js/common/image_packer_napi.cpp @@ -42,6 +42,8 @@ const int PARAM0 = 0; const int PARAM1 = 1; const int PARAM2 = 2; const int32_t SIZE = 100; +const int32_t TypeImageSource = 1; +const int32_t TypePixelMap = 2; struct ImagePackerAsyncContext { napi_env env; @@ -341,6 +343,41 @@ static bool parsePackOptions(napi_env env, napi_value root, PackOption* opts) return true; } +static int32_t ParserPackingArguments(napi_env env, napi_value argv) +{ + napi_value constructor = nullptr; + napi_value global = nullptr; + bool isInstance = false; + napi_status ret = napi_invalid_arg; + + napi_get_global(env, &global); + + ret = napi_get_named_property(env, global, "ImageSourceNapi", &constructor); + if (ret != napi_ok) { + HiLog::Error(LABEL, "Get ImageSourceNapi property failed!"); + } + + ret = napi_instanceof(env, argv, constructor, &isInstance); + if (ret == napi_ok && isInstance) { + HiLog::Debug(LABEL, "This is ImageSourceNapi type!"); + return TypeImageSource; + } + + ret = napi_get_named_property(env, global, "PixelMapNapi", &constructor); + if (ret != napi_ok) { + HiLog::Error(LABEL, "Get PixelMapNapi property failed!"); + } + + ret = napi_instanceof(env, argv, constructor, &isInstance); + if (ret == napi_ok && isInstance) { + HiLog::Debug(LABEL, "This is PixelMapNapi type!"); + return TypePixelMap; + } + + HiLog::Error(LABEL, "Inalued type!"); + return TypePixelMap; +} + napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) { napi_status status; @@ -349,6 +386,7 @@ napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) napi_value argv[ARGS_THREE] = {0}; napi_value thisVar = nullptr; int32_t refCount = 1; + int32_t packType = TypeImageSource; std::shared_ptr imagesourceObj = nullptr; std::unique_ptr pixelMap = nullptr; @@ -366,13 +404,20 @@ napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) for (size_t i = PARAM0; i < argc; i++) { napi_valuetype argvType = ImageNapiUtils::getType(env, argv[i]); if (i == PARAM0 && argvType == napi_object) { - std::shared_ptr imageSourceNapi = std::make_unique(); - status = napi_unwrap(env, argv[i], reinterpret_cast(&imageSourceNapi)); - IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, imageSourceNapi), nullptr, - HiLog::Error(LABEL, "fail to unwrap ImageSourceNapi")); - asyncContext->rImageSource = imageSourceNapi->nativeImgSrc; - IMG_NAPI_CHECK_RET_D(IMG_IS_OK(asyncContext->rImageSource == nullptr), nullptr, - HiLog::Error(LABEL, "fail to napi_get rImageSource")); + packType = ParserPackingArguments(env, argv[0]); + if (packType == TypeImageSource) { + std::shared_ptr imageSourceNapi = std::make_unique(); + status = napi_unwrap(env, argv[i], reinterpret_cast(&imageSourceNapi)); + IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, imageSourceNapi), nullptr, + HiLog::Error(LABEL, "fail to unwrap ImageSourceNapi")); + asyncContext->rImageSource = imageSourceNapi->nativeImgSrc; + IMG_NAPI_CHECK_RET_D(IMG_IS_OK(asyncContext->rImageSource == nullptr), nullptr, + HiLog::Error(LABEL, "fail to napi_get rImageSource")); + } else { + asyncContext->rPixelMap = PixelMapNapi::GetPixelMap(env, argv[i]); + IMG_NAPI_CHECK_RET_D(IMG_IS_OK(asyncContext->rPixelMap == nullptr), nullptr, + HiLog::Error(LABEL, "fail to napi_get rPixelMap")); + } } else if (i == PARAM1 && ImageNapiUtils::getType(env, argv[i]) == napi_object) { IMG_NAPI_CHECK_RET_D(parsePackOptions(env, argv[i], &(asyncContext->packOption)), nullptr, HiLog::Error(LABEL, "PackOptions mismatch")); @@ -389,8 +434,14 @@ napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) } ImageNapiUtils::HicheckerReport(); - IMG_CREATE_CREATE_ASYNC_WORK(env, status, "Packing", - PackingExec, PackingComplete, asyncContext, asyncContext->work); + + if (packType == TypeImageSource) { + IMG_CREATE_CREATE_ASYNC_WORK(env, status, "Packing", + PackingExec, PackingComplete, asyncContext, asyncContext->work); + } else { + IMG_CREATE_CREATE_ASYNC_WORK(env, status, "PackingFromPixelMap", + PackingFromPixelMapExec, PackingComplete, asyncContext, asyncContext->work); + } IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), nullptr, HiLog::Error(LABEL, "fail to create async work")); -- Gitee From 10e82c26fd6bb3d2dbb3c4f264488ed3f67093e8 Mon Sep 17 00:00:00 2001 From: zhang-xiaobo1997 Date: Mon, 28 Feb 2022 23:26:33 +0800 Subject: [PATCH 2/3] defalt image source Signed-off-by: zhang-xiaobo1997 --- frameworks/kits/js/common/image_packer_napi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/kits/js/common/image_packer_napi.cpp b/frameworks/kits/js/common/image_packer_napi.cpp index 650b617c5..2472b62db 100644 --- a/frameworks/kits/js/common/image_packer_napi.cpp +++ b/frameworks/kits/js/common/image_packer_napi.cpp @@ -375,7 +375,7 @@ static int32_t ParserPackingArguments(napi_env env, napi_value argv) } HiLog::Error(LABEL, "Inalued type!"); - return TypePixelMap; + return TypeImageSource; } napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) -- Gitee From f8f6b3abc867b9dd6723a8d617f3965d32a012b3 Mon Sep 17 00:00:00 2001 From: zhang-xiaobo1997 Date: Tue, 1 Mar 2022 12:02:41 +0800 Subject: [PATCH 3/3] modify for review Signed-off-by: zhang-xiaobo1997 --- frameworks/kits/js/common/image_packer_napi.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frameworks/kits/js/common/image_packer_napi.cpp b/frameworks/kits/js/common/image_packer_napi.cpp index 2472b62db..b1f555b87 100644 --- a/frameworks/kits/js/common/image_packer_napi.cpp +++ b/frameworks/kits/js/common/image_packer_napi.cpp @@ -42,8 +42,8 @@ const int PARAM0 = 0; const int PARAM1 = 1; const int PARAM2 = 2; const int32_t SIZE = 100; -const int32_t TypeImageSource = 1; -const int32_t TypePixelMap = 2; +const int32_t TYPE_IMAGE_SOURCE = 1; +const int32_t TYPE_PIXEL_MAP = 2; struct ImagePackerAsyncContext { napi_env env; @@ -360,7 +360,7 @@ static int32_t ParserPackingArguments(napi_env env, napi_value argv) ret = napi_instanceof(env, argv, constructor, &isInstance); if (ret == napi_ok && isInstance) { HiLog::Debug(LABEL, "This is ImageSourceNapi type!"); - return TypeImageSource; + return TYPE_IMAGE_SOURCE; } ret = napi_get_named_property(env, global, "PixelMapNapi", &constructor); @@ -371,11 +371,11 @@ static int32_t ParserPackingArguments(napi_env env, napi_value argv) ret = napi_instanceof(env, argv, constructor, &isInstance); if (ret == napi_ok && isInstance) { HiLog::Debug(LABEL, "This is PixelMapNapi type!"); - return TypePixelMap; + return TYPE_PIXEL_MAP; } HiLog::Error(LABEL, "Inalued type!"); - return TypeImageSource; + return TYPE_IMAGE_SOURCE; } napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) @@ -386,7 +386,7 @@ napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) napi_value argv[ARGS_THREE] = {0}; napi_value thisVar = nullptr; int32_t refCount = 1; - int32_t packType = TypeImageSource; + int32_t packType = TYPE_IMAGE_SOURCE; std::shared_ptr imagesourceObj = nullptr; std::unique_ptr pixelMap = nullptr; @@ -405,7 +405,7 @@ napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) napi_valuetype argvType = ImageNapiUtils::getType(env, argv[i]); if (i == PARAM0 && argvType == napi_object) { packType = ParserPackingArguments(env, argv[0]); - if (packType == TypeImageSource) { + if (packType == TYPE_IMAGE_SOURCE) { std::shared_ptr imageSourceNapi = std::make_unique(); status = napi_unwrap(env, argv[i], reinterpret_cast(&imageSourceNapi)); IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, imageSourceNapi), nullptr, @@ -435,7 +435,7 @@ napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) ImageNapiUtils::HicheckerReport(); - if (packType == TypeImageSource) { + if (packType == TYPE_IMAGE_SOURCE) { IMG_CREATE_CREATE_ASYNC_WORK(env, status, "Packing", PackingExec, PackingComplete, asyncContext, asyncContext->work); } else { -- Gitee