From 97a1718add141358365eac631a19cc2be381689b Mon Sep 17 00:00:00 2001 From: zhaona45 Date: Wed, 30 Jul 2025 15:57:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8DResourceManager.RawFileDescri?= =?UTF-8?q?ptor=20number->int?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaona45 Change-Id: Ifd82184dc05acac041af8e9cab21d5a6d2a53d70 --- .../kits/taihe/include/image_taihe_utils.h | 2 ++ .../kits/taihe/src/image_source_taihe.cpp | 16 ++++++------ .../kits/taihe/src/image_taihe_utils.cpp | 25 +++++++++++++++++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/frameworks/kits/taihe/include/image_taihe_utils.h b/frameworks/kits/taihe/include/image_taihe_utils.h index 48a8e0bbe..da84c5215 100644 --- a/frameworks/kits/taihe/include/image_taihe_utils.h +++ b/frameworks/kits/taihe/include/image_taihe_utils.h @@ -36,6 +36,8 @@ public: std::string defaultValueStr; }; + static bool GetPropertyInt(ani_env *env, ani_object obj, const std::string &name, int32_t &value); + static bool GetPropertyLong(ani_env *env, ani_object obj, const std::string &name, int64_t &value); static bool GetPropertyDouble(ani_env *env, ani_object obj, const std::string &name, double &value); static ani_object ToBusinessError(ani_env *env, int32_t code, const std::string &message); diff --git a/frameworks/kits/taihe/src/image_source_taihe.cpp b/frameworks/kits/taihe/src/image_source_taihe.cpp index 2b28da0bb..9866a270f 100644 --- a/frameworks/kits/taihe/src/image_source_taihe.cpp +++ b/frameworks/kits/taihe/src/image_source_taihe.cpp @@ -1394,15 +1394,15 @@ ImageSource CreateIncrementalSourceByArrayBuffer(array_view buf) ImageSource CreateImageSourceByRawFileDescriptorOption(uintptr_t rawfile, optional_view options) { - double fd; - double offset; - double length; + int32_t fd; + int64_t offset; + int64_t length; ani_env *env = ::taihe::get_env(); ani_object rawfileObj = reinterpret_cast(rawfile); - if (!ImageTaiheUtils::GetPropertyDouble(env, rawfileObj, "fd", fd) || - !ImageTaiheUtils::GetPropertyDouble(env, rawfileObj, "offset", offset) || - !ImageTaiheUtils::GetPropertyDouble(env, rawfileObj, "length", length)) { - ImageTaiheUtils::ThrowExceptionError(OHOS::Media::COMMON_ERR_INVALID_PARAMETER, "GetPropertyDouble failed"); + if (!ImageTaiheUtils::GetPropertyInt(env, rawfileObj, "fd", fd) || + !ImageTaiheUtils::GetPropertyLong(env, rawfileObj, "offset", offset) || + !ImageTaiheUtils::GetPropertyLong(env, rawfileObj, "length", length)) { + ImageTaiheUtils::ThrowExceptionError(OHOS::Media::COMMON_ERR_INVALID_PARAMETER, "GetProperty failed"); return make_holder(); } SourceOptions etsOpts = options.value_or(SourceOptions {}); @@ -1411,7 +1411,7 @@ ImageSource CreateImageSourceByRawFileDescriptorOption(uintptr_t rawfile, option uint32_t errorCode = OHOS::Media::ERR_MEDIA_INVALID_VALUE; int32_t fileSize = static_cast(offset) + static_cast(length); std::shared_ptr imageSource = OHOS::Media::ImageSource::CreateImageSource( - static_cast(fd), static_cast(offset), fileSize, opts, errorCode); + fd, static_cast(offset), fileSize, opts, errorCode); if (imageSource == nullptr) { ImageTaiheUtils::ThrowExceptionError("CreateImageSourceByRawFileDescriptorOption error"); return make_holder(); diff --git a/frameworks/kits/taihe/src/image_taihe_utils.cpp b/frameworks/kits/taihe/src/image_taihe_utils.cpp index 26c080903..2a0b7ee7d 100644 --- a/frameworks/kits/taihe/src/image_taihe_utils.cpp +++ b/frameworks/kits/taihe/src/image_taihe_utils.cpp @@ -41,11 +41,32 @@ void ImageTaiheUtils::ThrowExceptionError(const int32_t errCode, const std::stri taihe::set_business_error(errCode, errMsg); } +bool ImageTaiheUtils::GetPropertyInt(ani_env *env, ani_object obj, const std::string &name, int32_t &value) +{ + CHECK_ERROR_RETURN_RET_LOG(env == nullptr || obj == nullptr, false, "%{public}s param is nullptr", __func__); + ani_int result {}; + CHECK_ERROR_RETURN_RET_LOG(ANI_OK != env->Object_GetPropertyByName_Int(obj, name.c_str(), &result), false, + "%{public}s Object_GetPropertyByName_Int failed.", __func__); + value = static_cast(result); + return true; +} + +bool ImageTaiheUtils::GetPropertyLong(ani_env *env, ani_object obj, const std::string &name, int64_t &value) +{ + CHECK_ERROR_RETURN_RET_LOG(env == nullptr || obj == nullptr, false, "%{public}s param is nullptr", __func__); + ani_long result {}; + CHECK_ERROR_RETURN_RET_LOG(ANI_OK != env->Object_GetPropertyByName_Long(obj, name.c_str(), &result), false, + "%{public}s Object_GetPropertyByName_Long failed.", __func__); + value = static_cast(result); + return true; +} + bool ImageTaiheUtils::GetPropertyDouble(ani_env *env, ani_object obj, const std::string &name, double &value) { CHECK_ERROR_RETURN_RET_LOG(env == nullptr || obj == nullptr, false, "%{public}s param is nullptr", __func__); - ani_double result; - env->Object_GetPropertyByName_Double(obj, name.c_str(), &result); + ani_double result {}; + CHECK_ERROR_RETURN_RET_LOG(ANI_OK != env->Object_GetPropertyByName_Double(obj, name.c_str(), &result), false, + "%{public}s Object_GetPropertyByName_Long failed.", __func__); value = static_cast(result); return true; } -- Gitee