From 1f8196f3b45dd418fa0d40827cbb563ee568c622 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Tue, 29 Jul 2025 18:48:15 +0800 Subject: [PATCH 1/5] fix for warnings Signed-off-by: fanzhihao8 --- .../libs/image/libextplugin/src/ext_decoder.cpp | 8 ++++---- .../libs/image/libextplugin/src/ext_encoder.cpp | 2 +- .../libs/image/libjpegplugin/include/jpeg_utils.h | 2 +- .../libs/image/libjpegplugin/src/jpeg_decoder.cpp | 12 ++++++------ .../libs/image/libjpegplugin/src/jpeg_encoder.cpp | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp index 919f6677b..dd2b07312 100644 --- a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp +++ b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp @@ -978,14 +978,14 @@ void ExtDecoder::FillYuvInfo(DecodeContext &context, SkImageInfo &dstInfo) { if (context.allocatorType == AllocatorType::SHARE_MEM_ALLOC) { context.yuvInfo.imageSize = {dstInfo.width(), dstInfo.height()}; - context.yuvInfo.yWidth = dstInfo.width(); - context.yuvInfo.yHeight = dstInfo.height(); + context.yuvInfo.yWidth = static_cast(dstInfo.width()); + context.yuvInfo.yHeight = static_cast(dstInfo.height()); context.yuvInfo.uvWidth = static_cast((dstInfo.width() + 1) / BYTES_PER_YUV_SAMPLE); context.yuvInfo.uvHeight = static_cast((dstInfo.height() + 1) / BYTES_PER_YUV_SAMPLE); - context.yuvInfo.yStride = dstInfo.width(); + context.yuvInfo.yStride = static_cast(dstInfo.width()); context.yuvInfo.uvStride = context.yuvInfo.uvWidth + context.yuvInfo.uvWidth; context.yuvInfo.yOffset = 0; - context.yuvInfo.uvOffset = dstInfo.width() * dstInfo.height(); + context.yuvInfo.uvOffset = static_cast(dstInfo.width() * dstInfo.height()); } } diff --git a/plugins/common/libs/image/libextplugin/src/ext_encoder.cpp b/plugins/common/libs/image/libextplugin/src/ext_encoder.cpp index a64b200fd..167ce5642 100644 --- a/plugins/common/libs/image/libextplugin/src/ext_encoder.cpp +++ b/plugins/common/libs/image/libextplugin/src/ext_encoder.cpp @@ -919,7 +919,7 @@ uint32_t ExtEncoder::EncodeImageBySurfaceBuffer(sptr& surfaceBuff pixels = dstData.get(); rowStride = info.minRowBytes64(); } else { - rowStride = surfaceBuffer->GetStride(); + rowStride = static_cast(surfaceBuffer->GetStride()); } cond = !bitmap.installPixels(info, pixels, rowStride); CHECK_ERROR_RETURN_RET_LOG(cond, ERR_IMAGE_ENCODE_FAILED, diff --git a/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h b/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h index 49f2efe4c..9d1f2f8e7 100644 --- a/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h +++ b/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h @@ -41,7 +41,7 @@ struct ErrorMgr : jpeg_error_mgr { #ifdef _WIN32 jmp_buf setjmp_buffer = {{0}}; // for return to caller #else - jmp_buf setjmp_buffer; // for return to caller + jmp_buf setjmp_buffer = {{0}}; // for return to caller #endif }; diff --git a/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp b/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp index 8eb0b9e15..f0c38bc5c 100644 --- a/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp @@ -193,8 +193,8 @@ uint32_t JpegDecoder::GetImageSize(uint32_t index, Size &size) return ERR_MEDIA_INVALID_OPERATION; } if (state_ >= JpegDecodingState::BASE_INFO_PARSED) { - size.width = decodeInfo_.image_width; - size.height = decodeInfo_.image_height; + size.width = static_cast(decodeInfo_.image_width); + size.height = static_cast(decodeInfo_.image_height); return Media::SUCCESS; } // only state JpegDecodingState::SOURCE_INITED and JpegDecodingState::BASE_INFO_PARSING can go here. @@ -204,8 +204,8 @@ uint32_t JpegDecoder::GetImageSize(uint32_t index, Size &size) state_ = JpegDecodingState::BASE_INFO_PARSING; return ret; } - size.width = decodeInfo_.image_width; - size.height = decodeInfo_.image_height; + size.width = static_cast(decodeInfo_.image_width); + size.height = static_cast(decodeInfo_.image_height); state_ = JpegDecodingState::BASE_INFO_PARSED; return Media::SUCCESS; } @@ -336,8 +336,8 @@ uint32_t JpegDecoder::SetDecodeOptions(uint32_t index, const PixelDecodeOptions return ret; } info.pixelFormat = outputFormat_; - info.size.width = decodeInfo_.output_width; - info.size.height = decodeInfo_.output_height; + info.size.width = static_cast(decodeInfo_.output_width); + info.size.height = static_cast(decodeInfo_.output_height); info.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; opts_ = opts; state_ = JpegDecodingState::IMAGE_DECODING; diff --git a/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp b/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp index 15cb5c69a..146b567d7 100644 --- a/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp @@ -195,8 +195,8 @@ uint32_t JpegEncoder::SetCommonConfig() "encode image failed, pixel map is null."); CHECK_ERROR_RETURN_RET_LOG(setjmp(jerr_.setjmp_buffer), ERR_IMAGE_ENCODE_FAILED, "encode image error, set config failed."); - encodeInfo_.image_width = pixelMaps_[0]->GetWidth(); - encodeInfo_.image_height = pixelMaps_[0]->GetHeight(); + encodeInfo_.image_width = static_cast(pixelMaps_[0]->GetWidth()); + encodeInfo_.image_height = static_cast(pixelMaps_[0]->GetHeight()); PixelFormat pixelFormat = pixelMaps_[0]->GetPixelFormat(); encodeInfo_.in_color_space = GetEncodeFormat(pixelFormat, encodeInfo_.input_components); if (encodeInfo_.in_color_space == JCS_UNKNOWN) { @@ -337,7 +337,7 @@ uint32_t JpegEncoder::RGBAF16Encoder(const uint8_t *data) CHECK_ERROR_RETURN_RET_LOG(setjmp(jerr_.setjmp_buffer), ERR_IMAGE_ENCODE_FAILED, "encode image error."); jpeg_start_compress(&encodeInfo_, TRUE); uint8_t *base = const_cast(data); - uint32_t rowStride = encodeInfo_.image_width * encodeInfo_.input_components; + uint32_t rowStride = encodeInfo_.image_width * (uint32_t)encodeInfo_.input_components; uint32_t orgRowStride = encodeInfo_.image_width * PIXEL_SIZE_RGBA_F16; uint8_t *buffer = nullptr; auto rowBuffer = std::make_unique(rowStride); -- Gitee From 3c103193736d322b3f36c4b0d815f98a1eca5b4e Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Tue, 29 Jul 2025 21:35:24 +0800 Subject: [PATCH 2/5] fix for warnings Signed-off-by: fanzhihao8 --- .../innerkitsimpl/common/src/native_image.cpp | 18 ++++++++++++++---- .../jpeg_yuv_decoder/jpeg_yuv_decoder_test.cpp | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/frameworks/innerkitsimpl/common/src/native_image.cpp b/frameworks/innerkitsimpl/common/src/native_image.cpp index 201420ced..83095cff4 100644 --- a/frameworks/innerkitsimpl/common/src/native_image.cpp +++ b/frameworks/innerkitsimpl/common/src/native_image.cpp @@ -180,6 +180,19 @@ int32_t NativeImage::CombineYUVComponents() return SUCCESS; } + uint8_t* buffer = GetSurfaceBufferAddr(); + if (buffer == nullptr) { + IMAGE_LOGE("SurfaceBuffer viraddr is nullptr"); + return ERR_MEDIA_NULL_POINTER; + } + + uint64_t bufferSize = NUM_0; + res = GetDataSize(bufferSize); + if (res != SUCCESS || bufferSize == NUM_0) { + IMAGE_LOGE("bufferSize is 0"); + return ERR_MEDIA_DATA_UNSUPPORT; + } + auto y = GetComponent(int32_t(ComponentType::YUV_Y)); auto u = GetComponent(int32_t(ComponentType::YUV_U)); auto v = GetComponent(int32_t(ComponentType::YUV_V)); @@ -192,10 +205,7 @@ int32_t NativeImage::CombineYUVComponents() data.u = u->raw; data.v = v->raw; - uint64_t bufferSize = NUM_0; - GetDataSize(bufferSize); - - YUV422SPDataCopy(GetSurfaceBufferAddr(), bufferSize, data, true); + YUV422SPDataCopy(buffer, bufferSize, data, true); return SUCCESS; } diff --git a/frameworks/innerkitsimpl/test/unittest/jpeg_yuv_decoder/jpeg_yuv_decoder_test.cpp b/frameworks/innerkitsimpl/test/unittest/jpeg_yuv_decoder/jpeg_yuv_decoder_test.cpp index 805ada8bd..bd048c8ec 100644 --- a/frameworks/innerkitsimpl/test/unittest/jpeg_yuv_decoder/jpeg_yuv_decoder_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/jpeg_yuv_decoder/jpeg_yuv_decoder_test.cpp @@ -56,27 +56,38 @@ bool JpgYuvDecoderTest::ReadImageData(std::string jpgpath, uint8_t*& jpegBuffer, } int ret = fseek(jpgFile, 0, SEEK_END); if (ret != 0) { + fclose(jpgFile); return false; } - jpegBufferSize = static_cast(ftell(jpgFile)); + jpegBufferSize = static_cast(ftell(jpgFile)); ret = fseek(jpgFile, 0, SEEK_SET); if (ret != 0) { + fclose(jpgFile); return false; } if (jpegBufferSize == 0 || jpegBufferSize > PIXEL_MAP_MAX_RAM_SIZE) { + fclose(jpgFile); return false; } else { jpegBuffer = new uint8_t[jpegBufferSize]; } if (jpegBuffer == nullptr) { + fclose(jpgFile); return false; } - jpegBufferSize = fread(jpegBuffer, 1, jpegBufferSize, jpgFile); - if (jpegBufferSize == 0) { + uint32_t readSize = fread(jpegBuffer, 1, jpegBufferSize, jpgFile); + if (readSize == 0) { + delete[] jpegBuffer; + jpegBuffer = nullptr; + fclose(jpgFile); return false; } + jpegBufferSize = readSize; + ret = fclose(jpgFile); if (ret != 0) { + delete[] jpegBuffer; + jpegBuffer = nullptr; return false; } return true; -- Gitee From ef3728838216475cbf9db4ac32d05e0a47e5e467 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Tue, 29 Jul 2025 22:02:11 +0800 Subject: [PATCH 3/5] fix for warnings Signed-off-by: fanzhihao8 --- plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h b/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h index 9d1f2f8e7..e610d9276 100644 --- a/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h +++ b/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h @@ -41,7 +41,7 @@ struct ErrorMgr : jpeg_error_mgr { #ifdef _WIN32 jmp_buf setjmp_buffer = {{0}}; // for return to caller #else - jmp_buf setjmp_buffer = {{0}}; // for return to caller + jmp_buf setjmp_buffer = {}; // for return to caller #endif }; -- Gitee From e6458a26def906e7abee831d601ecfbe42989ddf Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Wed, 30 Jul 2025 10:17:38 +0800 Subject: [PATCH 4/5] fix for warnings Signed-off-by: fanzhihao8 --- .../common/ndk/image_receiver_native.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frameworks/kits/native/common/ndk/image_receiver_native.cpp b/frameworks/kits/native/common/ndk/image_receiver_native.cpp index fc9a52e0d..654ef2ac7 100644 --- a/frameworks/kits/native/common/ndk/image_receiver_native.cpp +++ b/frameworks/kits/native/common/ndk/image_receiver_native.cpp @@ -86,6 +86,10 @@ Image_ErrorCode OH_ImageReceiverOptions_Create(OH_ImageReceiverOptions** options MIDK_EXPORT Image_ErrorCode OH_ImageReceiverOptions_GetSize(OH_ImageReceiverOptions* options, Image_Size* size) { + if (nullptr == size) { + IMAGE_LOGE("Invalid parameter: size=null."); + return IMAGE_BAD_PARAMETER; + } if (nullptr == options) { IMAGE_LOGE("Invalid parameter: options=null."); return IMAGE_BAD_PARAMETER; @@ -110,6 +114,10 @@ Image_ErrorCode OH_ImageReceiverOptions_SetSize(OH_ImageReceiverOptions* options MIDK_EXPORT Image_ErrorCode OH_ImageReceiverOptions_GetCapacity(OH_ImageReceiverOptions* options, int32_t* capacity) { + if (nullptr == capacity) { + IMAGE_LOGE("Invalid parameter: capacity=null."); + return IMAGE_BAD_PARAMETER; + } if (nullptr == options) { IMAGE_LOGE("Invalid parameter: options=null."); return IMAGE_BAD_PARAMETER; @@ -176,6 +184,10 @@ static bool ConvertToUint64(const std::string& str, uint64_t& value) MIDK_EXPORT Image_ErrorCode OH_ImageReceiverNative_GetReceivingSurfaceId(OH_ImageReceiverNative* receiver, uint64_t* surfaceId) { + if (nullptr == surfaceId) { + IMAGE_LOGE("Invalid parameter: surfaceId=null."); + return IMAGE_BAD_PARAMETER; + } if (nullptr == receiver) { IMAGE_LOGE("Invalid parameter: receiver=null."); return IMAGE_BAD_PARAMETER; @@ -202,6 +214,10 @@ Image_ErrorCode OH_ImageReceiverNative_GetReceivingSurfaceId(OH_ImageReceiverNat MIDK_EXPORT Image_ErrorCode OH_ImageReceiverNative_ReadLatestImage(OH_ImageReceiverNative* receiver, OH_ImageNative** image) { + if (nullptr == image) { + IMAGE_LOGE("Invalid parameter: image=null."); + return IMAGE_BAD_PARAMETER; + } if (nullptr == receiver) { IMAGE_LOGE("Invalid parameter: receiver=null."); return IMAGE_BAD_PARAMETER; @@ -245,6 +261,10 @@ Image_ErrorCode OH_ImageReceiverNative_ReadLatestImage(OH_ImageReceiverNative* r MIDK_EXPORT Image_ErrorCode OH_ImageReceiverNative_ReadNextImage(OH_ImageReceiverNative* receiver, OH_ImageNative** image) { + if (nullptr == image) { + IMAGE_LOGE("Invalid parameter: image=null."); + return IMAGE_BAD_PARAMETER; + } if (nullptr == receiver) { IMAGE_LOGE("Invalid parameter: receiver=null."); return IMAGE_BAD_PARAMETER; -- Gitee From 2b22a224081b3c9bb5ae27886c69afb92b6b8caa Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Wed, 30 Jul 2025 11:31:32 +0800 Subject: [PATCH 5/5] fix for warnings Signed-off-by: fanzhihao8 --- .../common/libs/image/libextplugin/src/ext_decoder.cpp | 8 ++++---- .../common/libs/image/libjpegplugin/src/jpeg_encoder.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp index dd2b07312..4cb6891b3 100644 --- a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp +++ b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp @@ -641,8 +641,8 @@ uint32_t ExtDecoder::GetImageSize(uint32_t index, Size &size) // Info has been get in check process, or empty on get failed. CHECK_ERROR_RETURN_RET_LOG(info_.isEmpty(), ERR_IMAGE_DECODE_HEAD_ABNORMAL, "GetImageSize failed, decode header failed."); - size.width = static_cast(info_.width()); - size.height = static_cast(info_.height()); + size.width = info_.width(); + size.height = info_.height(); return SUCCESS; } @@ -785,8 +785,8 @@ uint32_t ExtDecoder::SetDecodeOptions(uint32_t index, const PixelDecodeOptions & getDesiredColorSpace(info_, opts)); } - info.size.width = static_cast(dstInfo_.width()); - info.size.height = static_cast(dstInfo_.height()); + info.size.width = dstInfo_.width(); + info.size.height = dstInfo_.height(); reusePixelmap_ = opts.plReusePixelmap; return SUCCESS; } diff --git a/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp b/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp index 146b567d7..d74f9de2f 100644 --- a/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp @@ -239,7 +239,7 @@ uint32_t JpegEncoder::SequenceEncoder(const uint8_t *data) #endif uint8_t *base = const_cast(data); - uint32_t rowStride = encodeInfo_.image_width * (uint32_t)encodeInfo_.input_components; + uint32_t rowStride = encodeInfo_.image_width * static_cast(encodeInfo_.input_components); uint8_t *buffer = nullptr; while (encodeInfo_.next_scanline < encodeInfo_.image_height) { buffer = base + encodeInfo_.next_scanline * rowStride; @@ -337,7 +337,7 @@ uint32_t JpegEncoder::RGBAF16Encoder(const uint8_t *data) CHECK_ERROR_RETURN_RET_LOG(setjmp(jerr_.setjmp_buffer), ERR_IMAGE_ENCODE_FAILED, "encode image error."); jpeg_start_compress(&encodeInfo_, TRUE); uint8_t *base = const_cast(data); - uint32_t rowStride = encodeInfo_.image_width * (uint32_t)encodeInfo_.input_components; + uint32_t rowStride = encodeInfo_.image_width * static_cast(encodeInfo_.input_components); uint32_t orgRowStride = encodeInfo_.image_width * PIXEL_SIZE_RGBA_F16; uint8_t *buffer = nullptr; auto rowBuffer = std::make_unique(rowStride); @@ -366,7 +366,7 @@ uint32_t JpegEncoder::RGB565Encoder(const uint8_t *data) uint32_t orgRowStride = encodeInfo_.image_width * PIXEL_SIZE_RGB565; uint8_t *orgRowBuffer = nullptr; - uint32_t outRowStride = encodeInfo_.image_width * encodeInfo_.input_components; + uint32_t outRowStride = encodeInfo_.image_width * static_cast(encodeInfo_.input_components); auto outRowBuffer = std::make_unique(outRowStride); while (encodeInfo_.next_scanline < encodeInfo_.image_height) { -- Gitee