From 15f30509dc92c4f3ff1441afacfd593ff9c1e453 Mon Sep 17 00:00:00 2001 From: zhaona45 Date: Thu, 21 Aug 2025 15:56:25 +0800 Subject: [PATCH] test Signed-off-by: zhaona45 Change-Id: I8e2bd17ca3ea9dd4e9e8b5f8200fd6e512f08485 --- .../kits/js/common/image_source_napi.cpp | 180 ++++++++++++++++++ .../js/common/include/image_source_napi.h | 2 + 2 files changed, 182 insertions(+) diff --git a/frameworks/kits/js/common/image_source_napi.cpp b/frameworks/kits/js/common/image_source_napi.cpp index e367d1d6a..94b28410d 100644 --- a/frameworks/kits/js/common/image_source_napi.cpp +++ b/frameworks/kits/js/common/image_source_napi.cpp @@ -512,6 +512,14 @@ static std::string GetStringArgumentForModify(napi_env env, napi_value value) return strValue; } +// for Exif Input 64K +static int32_t GetIntArgumentForModify(napi_env env, napi_value value) +{ + int32_t valueInt = 0; + napi_get_value_int32(env, value, &valueInt); + return valueInt; +} + static void ImageSourceCallbackRoutine(napi_env env, ImageSourceAsyncContext* &context, const napi_value &valueParam) { napi_value result[NUM_2] = {0}; @@ -896,9 +904,11 @@ std::vector ImageSourceNapi::RegisterNapi() DECLARE_NAPI_FUNCTION("getImageInfoSync", GetImageInfoSync), DECLARE_NAPI_FUNCTION("modifyImageProperty", ModifyImageProperty), DECLARE_NAPI_FUNCTION("modifyImageProperties", ModifyImageProperty), + DECLARE_NAPI_FUNCTION("modifyImagePropertyInt", ModifyImagePropertyInt), DECLARE_NAPI_FUNCTION("getImageProperty", GetImageProperty), DECLARE_NAPI_FUNCTION("getImagePropertySync", GetImagePropertySync), DECLARE_NAPI_FUNCTION("getImageProperties", GetImageProperty), + DECLARE_NAPI_FUNCTION("getImagePropertyInt", GetImagePropertyInt), DECLARE_NAPI_FUNCTION("getDelayTimeList", GetDelayTime), DECLARE_NAPI_FUNCTION("getDisposalTypeList", GetDisposalType), DECLARE_NAPI_FUNCTION("getFrameCount", GetFrameCount), @@ -2475,6 +2485,25 @@ static void ModifyImagePropertyExecute(napi_env env, void *data) context->status = context->rImageSource->ModifyImagePropertyEx(context->index, context->keyStr, context->valueStr); } +static void ModifyImagePropertyIntExecute(napi_env env, void *data) +{ + auto context = static_cast(data); + if (context == nullptr) { + IMAGE_LOGE("empty context"); + return; + } + context->valueStr = std::to_string(context->valueInt); + IMAGE_LOGD("ModifyImagePropertyIntExecute CheckExifDataValue"); + uint32_t status = CheckExifDataValue(context->keyStr, context->valueStr, context->errMsg); + IMAGE_LOGD("ModifyImagePropertyIntExecute Check ret status: %{public}d", status); + if (status != SUCCESS) { + IMAGE_LOGE("There is invalid exif data parameter"); + context->status = status; + return; + } + context->status = context->rImageSource->ModifyImagePropertyEx(context->index, context->keyStr, context->valueStr); +} + static void GetImagePropertiesExecute(napi_env env, void *data) { auto context = static_cast(data); @@ -2549,6 +2578,46 @@ static std::unique_ptr UnwrapContextForModify(napi_env return context; } +static std::unique_ptr UnwrapIntContextForModify(napi_env env, napi_callback_info info) +{ + IMAGE_LOGE("%{public}s In", __func__); + napi_status status; + napi_value thisVar = nullptr; + napi_value argValue[NUM_2] = {0}; + size_t argCount = NUM_2; + IMG_JS_ARGS(env, info, status, argCount, argValue, thisVar); + IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), nullptr, IMAGE_LOGE("fail to napi_get_cb_info")); + std::unique_ptr context = std::make_unique(); + status = napi_unwrap(env, thisVar, reinterpret_cast(&context->constructor_)); + IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, context->constructor_), nullptr, IMAGE_LOGE("fail to unwrap context")); + context->rImageSource = context->constructor_->nativeImgSrc; + IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, context->rImageSource), nullptr, IMAGE_LOGE("empty native rImageSource")); + if (argCount < NUM_1 || argCount > NUM_2) { + IMAGE_LOGE("argCount mismatch"); + return nullptr; + } + if (ImageNapiUtils::getType(env, argValue[NUM_0]) == napi_string) { + context->keyStr = GetStringArgument(env, argValue[NUM_0]); + } else { + IMAGE_LOGE("arg 0 type mismatch"); + return nullptr; + } + if (argCount == NUM_2) { + if (ImageNapiUtils::getType(env, argValue[NUM_1]) == napi_number) { + context->valueInt = GetIntArgumentForModify(env, argValue[NUM_1]); + } else { + IMAGE_LOGE("arg 1 type mismatch"); + return nullptr; + } + } + context->pathName = ImageSourceNapi::filePath_; + context->fdIndex = ImageSourceNapi::fileDescriptor_; + context->sourceBuffer = ImageSourceNapi::fileBuffer_; + context->sourceBufferSize = ImageSourceNapi::fileBufferSize_; + IMAGE_LOGE("%{public}s out", __func__); + return context; +} + napi_value ImageSourceNapi::ModifyImageProperty(napi_env env, napi_callback_info info) { napi_value result = nullptr; @@ -2584,6 +2653,36 @@ napi_value ImageSourceNapi::ModifyImageProperty(napi_env env, napi_callback_info return result; } +napi_value ImageSourceNapi::ModifyImagePropertyInt(napi_env env, napi_callback_info info) +{ + IMAGE_LOGE("%{public}s In", __func__); + napi_value result = nullptr; + napi_get_undefined(env, &result); + + napi_status status; + std::unique_ptr asyncContext = UnwrapIntContextForModify(env, info); + if (asyncContext == nullptr) { + return ImageNapiUtils::ThrowExceptionError(env, COMMON_ERR_INVALID_PARAMETER, "async context unwrap failed"); + } + + if (asyncContext->callbackRef == nullptr) { + napi_create_promise(env, &(asyncContext->deferred), &result); + } else { + napi_get_undefined(env, &result); + } + + IMG_CREATE_CREATE_ASYNC_WORK(env, status, "ModifyImagePropertyInt", + ModifyImagePropertyIntExecute, + reinterpret_cast(ModifyImagePropertyComplete), + asyncContext, + asyncContext->work); + + + IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), + nullptr, IMAGE_LOGE("fail to create async work")); + return result; +} + napi_value ImageSourceNapi::GetImageProperty(napi_env env, napi_callback_info info) { ImageTrace imageTrace("ImageSourceNapi::GetImageProperty"); @@ -2626,6 +2725,87 @@ napi_value ImageSourceNapi::GetImageProperty(napi_env env, napi_callback_info in return result; } +static void GetImagePropertyIntComplete(napi_env env, napi_status status, ImageSourceAsyncContext *context) +{ + if (context == nullptr) { + IMAGE_LOGE("context is nullptr"); + return; + } + + napi_value result[NUM_2] = {0}; + napi_value retVal; + napi_value callback = nullptr; + + napi_get_undefined(env, &result[NUM_0]); + napi_get_undefined(env, &result[NUM_1]); + + if (context->status == SUCCESS) { + napi_create_int32(env, context->valueInt, &result[NUM_1]); + } else { + std::string errMsg; + GenerateErrMsg(context, errMsg); + ImageNapiUtils::CreateErrorObj(env, result[NUM_0], context->status, errMsg); + + if (!context->defaultValueStr.empty()) { + napi_create_int32(env, 0, &result[NUM_1]); + context->status = SUCCESS; + } + } + + if (context->deferred) { + if (context->status == SUCCESS) { + napi_resolve_deferred(env, context->deferred, result[NUM_1]); + } else { + napi_reject_deferred(env, context->deferred, result[NUM_0]); + } + } else { + IMAGE_LOGD("call callback function"); + napi_get_reference_value(env, context->callbackRef, &callback); + napi_call_function(env, nullptr, callback, NUM_2, result, &retVal); + napi_delete_reference(env, context->callbackRef); + } + + napi_delete_async_work(env, context->work); + delete context; + context = nullptr; +} + +napi_value ImageSourceNapi::GetImagePropertyInt(napi_env env, napi_callback_info info) +{ + ImageTrace imageTrace("ImageSourceNapi::GetImagePropertyInt"); + napi_value result = nullptr; + napi_get_undefined(env, &result); + + napi_status status; + std::unique_ptr asyncContext = UnwrapContext(env, info); + if (asyncContext == nullptr) { + return ImageNapiUtils::ThrowExceptionError(env, COMMON_ERR_INVALID_PARAMETER, "async context unwrap failed"); + } + + if (asyncContext->callbackRef == nullptr) { + napi_create_promise(env, &(asyncContext->deferred), &result); + } else { + napi_get_undefined(env, &result); + } + + + IMG_CREATE_CREATE_ASYNC_WORK(env, status, "GetImagePropertyInt", + [](napi_env env, void *data) { + auto context = static_cast(data); + context->status = context->rImageSource->GetImagePropertyString(context->index, + context->keyStr, + context->valueStr); + context->valueInt = std::stoi(context->valueStr); + }, + reinterpret_cast(GetImagePropertyIntComplete), + asyncContext, + asyncContext->work); + + IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), + nullptr, IMAGE_LOGE("fail to create async work")); + return result; +} + napi_value ImageSourceNapi::GetImagePropertySync(napi_env env, napi_callback_info info) { ImageTrace imageTrace("ImageSourceNapi::GetImagePropertySync"); diff --git a/interfaces/kits/js/common/include/image_source_napi.h b/interfaces/kits/js/common/include/image_source_napi.h index d3cc22700..3b1921886 100644 --- a/interfaces/kits/js/common/include/image_source_napi.h +++ b/interfaces/kits/js/common/include/image_source_napi.h @@ -70,7 +70,9 @@ private: static napi_value CreatePixelMap(napi_env env, napi_callback_info info); static napi_value CreatePixelMapSync(napi_env env, napi_callback_info info); static napi_value ModifyImageProperty(napi_env env, napi_callback_info info); + static napi_value ModifyImagePropertyInt(napi_env env, napi_callback_info info); static napi_value GetImageProperty(napi_env env, napi_callback_info info); + static napi_value GetImagePropertyInt(napi_env env, napi_callback_info info); static napi_value GetImagePropertySync(napi_env env, napi_callback_info info); static napi_value UpdateData(napi_env env, napi_callback_info info); static napi_value Release(napi_env env, napi_callback_info info); -- Gitee