From 8fb20e4f78c5cfca7579c1b294a53805b843cb7f Mon Sep 17 00:00:00 2001 From: yangfan Date: Thu, 11 Apr 2024 22:11:55 +0800 Subject: [PATCH] =?UTF-8?q?yuv=E6=A0=BC=E5=BC=8F=E8=A7=A3=E7=A0=81cppcheck?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan Change-Id: Idc7cfc776b92b0ce65ca8dde02e54d4817568839 --- .../jpeg_yuv_decoder/jpeg_decoder_yuv.h | 4 +-- .../jpeg_yuv_decoder/jpeg_yuvdata_converter.h | 22 ++++++------ .../src/jpeg_yuv_decoder/jpeg_decoder_yuv.cpp | 13 +++---- .../jpeg_yuvdata_converter.cpp | 36 ++++++++++--------- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder/jpeg_decoder_yuv.h b/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder/jpeg_decoder_yuv.h index 7fd8f950b..53d9cb986 100644 --- a/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder/jpeg_decoder_yuv.h +++ b/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder/jpeg_decoder_yuv.h @@ -26,8 +26,8 @@ namespace OHOS { namespace ImagePlugin { -typedef int (*FUNC_I4xxToI420)(YuvPlaneInfo& src, YuvPlaneInfo& dest); -typedef int (*FUNC_I4xxToNV21)(YuvPlaneInfo& src, YuvPlaneInfo& dest); +typedef int (*FUNC_I4xxToI420)(const YuvPlaneInfo& src, const YuvPlaneInfo& dest); +typedef int (*FUNC_I4xxToNV21)(const YuvPlaneInfo& src, const YuvPlaneInfo& dest); struct ConverterPair { FUNC_I4xxToI420 to420Func = nullptr; diff --git a/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder/jpeg_yuvdata_converter.h b/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder/jpeg_yuvdata_converter.h index 86e5060a3..0c21da32a 100644 --- a/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder/jpeg_yuvdata_converter.h +++ b/plugins/common/libs/image/libextplugin/include/jpeg_yuv_decoder/jpeg_yuvdata_converter.h @@ -38,18 +38,18 @@ struct YuvPlaneInfo { unsigned char *planes[YUVCOMPONENT_MAX] = { 0 }; }; -int I444ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I444ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I422ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I422ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I420ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I420ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I440ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I440ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I411ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); -int I411ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); +int I444ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I444ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I422ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I422ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I420ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I420ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I440ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I440ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I411ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); +int I411ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); -int I400ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest); +int I400ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest); } } #endif \ No newline at end of file diff --git a/plugins/common/libs/image/libextplugin/src/jpeg_yuv_decoder/jpeg_decoder_yuv.cpp b/plugins/common/libs/image/libextplugin/src/jpeg_yuv_decoder/jpeg_decoder_yuv.cpp index ca5d38453..7bd4cab8a 100644 --- a/plugins/common/libs/image/libextplugin/src/jpeg_yuv_decoder/jpeg_decoder_yuv.cpp +++ b/plugins/common/libs/image/libextplugin/src/jpeg_yuv_decoder/jpeg_decoder_yuv.cpp @@ -72,11 +72,9 @@ tjscalingfactor JpegDecoderYuv::GetScaledFactor(uint32_t jpgwidth, uint32_t jpgh if (sf == nullptr || NUMSF == 0) { return factor; } - uint32_t scaledw = 0; - uint32_t scaledh = 0; for (int i = 0; i < NUMSF; i++) { - scaledw = TJSCALED(jpgwidth, sf[i]); - scaledh = TJSCALED(jpgheight, sf[i]); + uint32_t scaledw = TJSCALED(jpgwidth, sf[i]); + uint32_t scaledh = TJSCALED(jpgheight, sf[i]); if ((scaledw <= width && scaledh <= height) || i == NUMSF - 1) { factor.num = sf[i].num; factor.denom = sf[i].denom; @@ -392,11 +390,8 @@ int JpegDecoderYuv::DoDecodeToYuvPlane(DecodeContext &context, tjhandle dehandle return DecodeFrom420To420(context, dehandle, width, height); } std::unique_ptr yuvBuffer = std::make_unique(totalSizeForDecodeData); - unsigned char* data = (unsigned char*)yuvBuffer.get(); - if (data == nullptr) { - IMAGE_LOGE("JpegDecoderYuv DoDecodeToYuvPlane, error to malloc"); - return JpegYuvDecodeError_MemoryMallocFailed; - } + unsigned char* data = reinterpret_cast(yuvBuffer.get()); + YuvPlaneInfo jpegOutYuvInfo = { 0 }; FillJpgOutYuvInfo(jpegOutYuvInfo, width, height, data, jpegSubsamp); ret = tjDecompressToYUVPlanes(dehandle, decodeParameter_.jpegBuffer_, decodeParameter_.jpegBufferSize_, diff --git a/plugins/common/libs/image/libextplugin/src/jpeg_yuv_decoder/jpeg_yuvdata_converter.cpp b/plugins/common/libs/image/libextplugin/src/jpeg_yuv_decoder/jpeg_yuvdata_converter.cpp index 98a596ea3..f8c3f04dd 100644 --- a/plugins/common/libs/image/libextplugin/src/jpeg_yuv_decoder/jpeg_yuvdata_converter.cpp +++ b/plugins/common/libs/image/libextplugin/src/jpeg_yuv_decoder/jpeg_yuvdata_converter.cpp @@ -43,7 +43,7 @@ namespace ImagePlugin { #define SCALE_411_X 4 #define SCALE_411_Y 1 -static bool IsValidYuvData(YuvPlaneInfo &data) +static bool IsValidYuvData(const YuvPlaneInfo &data) { if (data.planes[YCOM] == nullptr || data.planes[UCOM] == nullptr || data.planes[VCOM] == nullptr || data.strides[YCOM] == 0 || data.strides[UCOM] == 0 || data.strides[VCOM] == 0) { @@ -53,7 +53,7 @@ static bool IsValidYuvData(YuvPlaneInfo &data) } } -static bool IsValidYuvNVData(YuvPlaneInfo &data) +static bool IsValidYuvNVData(const YuvPlaneInfo &data) { if (data.planes[YCOM] == nullptr || data.planes[UVCOM] == nullptr || data.strides[YCOM] == 0 || data.strides[UVCOM] == 0) { @@ -63,7 +63,7 @@ static bool IsValidYuvNVData(YuvPlaneInfo &data) } } -static bool IsValidYuvGrayData(YuvPlaneInfo &data) +static bool IsValidYuvGrayData(const YuvPlaneInfo &data) { if (data.planes[YCOM] == nullptr || data.strides[YCOM] == 0) { return false; @@ -125,7 +125,8 @@ static uint8_t SampleUV(const uint8_t* srcUV, int stride, bool canUseNextRow, bo return *srcUV; } -static bool VerifyParameter(YuvPlaneInfo &src, YuvPlaneInfo &dest, uint8_t srcXScale, uint8_t srcYScale, bool outYU12) +static bool VerifyParameter(const YuvPlaneInfo &src, const YuvPlaneInfo &dest, + uint8_t srcXScale, uint8_t srcYScale, bool outYU12) { uint32_t width = src.imageWidth; uint32_t height = src.imageHeight; @@ -141,7 +142,7 @@ static bool VerifyParameter(YuvPlaneInfo &src, YuvPlaneInfo &dest, uint8_t srcXS return true; } -static bool CopyYData(YuvPlaneInfo &src, YuvPlaneInfo &dest) +static bool CopyYData(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { uint32_t height = src.imageHeight; const uint8_t* srcY = nullptr; @@ -163,7 +164,8 @@ static bool CopyYData(YuvPlaneInfo &src, YuvPlaneInfo &dest) return true; } -int I4xxToI420_c(YuvPlaneInfo &src, YuvPlaneInfo &dest, uint8_t srcXScale, uint8_t srcYScale, bool outfmtIsYU12) +int I4xxToI420_c(const YuvPlaneInfo &src, const YuvPlaneInfo &dest, + uint8_t srcXScale, uint8_t srcYScale, bool outfmtIsYU12) { if (!VerifyParameter(src, dest, srcXScale, srcYScale, outfmtIsYU12)) { return -1; @@ -214,7 +216,7 @@ int I4xxToI420_c(YuvPlaneInfo &src, YuvPlaneInfo &dest, uint8_t srcXScale, uint8 return 0; } -int I444ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I444ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { #ifdef LIBYUV_ENABLE uint32_t width = src.imageWidth; @@ -230,7 +232,7 @@ int I444ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) #endif } -int I444ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I444ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { #ifdef LIBYUV_ENABLE uint32_t width = src.imageWidth; @@ -246,7 +248,7 @@ int I444ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) #endif } -int I422ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I422ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { #ifdef LIBYUV_ENABLE uint32_t width = src.imageWidth; @@ -262,7 +264,7 @@ int I422ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) #endif } -int I422ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I422ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { #ifdef LIBYUV_ENABLE uint32_t width = src.imageWidth; @@ -278,12 +280,12 @@ int I422ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) #endif } -int I420ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I420ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { return I4xxToI420_c(src, dest, SCALE_420_X, SCALE_420_Y, true); } -int I420ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I420ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { #ifdef LIBYUV_ENABLE uint32_t width = src.imageWidth; @@ -299,27 +301,27 @@ int I420ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) #endif } -int I440ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I440ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { return I4xxToI420_c(src, dest, SCALE_440_X, SCALE_440_Y, true); } -int I440ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I440ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { return I4xxToI420_c(src, dest, SCALE_440_X, SCALE_440_Y, false); } -int I411ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I411ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { return I4xxToI420_c(src, dest, SCALE_411_X, SCALE_411_Y, true); } -int I411ToNV21_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I411ToNV21_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { return I4xxToI420_c(src, dest, SCALE_411_X, SCALE_411_Y, false); } -int I400ToI420_wrapper(YuvPlaneInfo &src, YuvPlaneInfo &dest) +int I400ToI420_wrapper(const YuvPlaneInfo &src, const YuvPlaneInfo &dest) { uint32_t width = src.imageWidth; uint32_t height = src.imageHeight; -- Gitee