diff --git a/frameworks/innerkitsimpl/common/src/native_image.cpp b/frameworks/innerkitsimpl/common/src/native_image.cpp index 201420ced3ae066ce72731b81d6bf6ccbdf873b6..83095cff4ede38d9982f6b3a72d9e175e1be929b 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 805ada8bde3e9dfede4af4b844e9c4a443532640..bd048c8ecdb61d8d9eb718e09389b6b11449b107 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; diff --git a/frameworks/kits/native/common/ndk/image_receiver_native.cpp b/frameworks/kits/native/common/ndk/image_receiver_native.cpp index fc9a52e0d1e4af55203c36e2413dbd042f86a5a3..654ef2ac7c70e9b6371b9fcacf030867ab0e48f9 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; diff --git a/plugins/common/libs/image/libextplugin/include/hardware/jpeg_hw_decoder.h b/plugins/common/libs/image/libextplugin/include/hardware/jpeg_hw_decoder.h index 9e184857e6ca3cde4c6ce6ad0d9eae413fd179cd..acecbac3daeedbe22b97821fabaa3c148afb5bc3 100644 --- a/plugins/common/libs/image/libextplugin/include/hardware/jpeg_hw_decoder.h +++ b/plugins/common/libs/image/libextplugin/include/hardware/jpeg_hw_decoder.h @@ -126,11 +126,11 @@ private: OHOS::HDI::Display::Buffer::V1_0::IDisplayBuffer* bufferMgr_; OHOS::HDI::Codec::Image::V2_1::CodecImageBuffer inputBuffer_; OHOS::HDI::Codec::Image::V2_1::CodecJpegDecInfo decodeInfo_; - uint32_t compressDataPos_; - uint32_t compressDataSize_; - bool useDmaPool_; - uint32_t usedSizeInPool_; - uint32_t usedOffsetInPool_; + uint32_t compressDataPos_ {0}; + uint32_t compressDataSize_ {0}; + bool useDmaPool_ {false}; + uint32_t usedSizeInPool_ {0}; + uint32_t usedOffsetInPool_ {0}; }; } // namespace ImagePlugin } // namespace OHOS diff --git a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp index 919f6677b1db7fdf10b449849200820d282f9679..c52458ae76308d39d338d909bbd11b3a69e489e8 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; } @@ -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()); } } @@ -1554,7 +1554,8 @@ void ExtDecoder::ReportImageType(SkEncodedImageFormat skEncodeFormat) "PVERSIONID", DEFAULT_VERSION_ID, "IMAGE_TYPE", GetFormatStr(skEncodeFormat) ); - CHECK_DEBUG_RETURN_LOG(SUCCESS != ret, "ExtDecoder::ReportImageType failed, ret = %{public}d", ret); + uint32_t tmpRet = static_cast(ret); + CHECK_DEBUG_RETURN_LOG(SUCCESS != tmpRet, "ExtDecoder::ReportImageType failed, ret = %{public}d", ret); #endif IMAGE_LOGD("ExtDecoder::ReportImageType format %{public}d success", skEncodeFormat); } @@ -1582,11 +1583,11 @@ uint32_t ExtDecoder::AllocOutputBuffer(DecodeContext &context, "Alloc OutputBuffer failed, context is null"); BufferHandle *handle = (static_cast(context.pixelsBuffer.context))->GetBufferHandle(); if (outputColorFmt_ == V1_2::PIXEL_FMT_RGBA_8888) { - outputBufferSize_.width = static_cast(handle->stride) / NUM_4; + outputBufferSize_.width = handle->stride / NUM_4; } else { - outputBufferSize_.width = static_cast(handle->stride); + outputBufferSize_.width = handle->stride; } - outputBufferSize_.height = static_cast(handle->height); + outputBufferSize_.height = handle->height; outputBuffer.buffer = new NativeBuffer(handle); outputBuffer.fenceFd = -1; return SUCCESS; diff --git a/plugins/common/libs/image/libextplugin/src/ext_encoder.cpp b/plugins/common/libs/image/libextplugin/src/ext_encoder.cpp index a64b200fd5238508f30fada01d3560478f5a32f8..167ce5642b0704a4a3c6939c9a6c3863995fc6e1 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/libextplugin/src/hardware/jpeg_hw_decoder.cpp b/plugins/common/libs/image/libextplugin/src/hardware/jpeg_hw_decoder.cpp index 45629d4a3716a70412500647475e129643d5bac8..8be3101ca8befb0a61dbf38f526f0bce34fd9ada 100644 --- a/plugins/common/libs/image/libextplugin/src/hardware/jpeg_hw_decoder.cpp +++ b/plugins/common/libs/image/libextplugin/src/hardware/jpeg_hw_decoder.cpp @@ -236,7 +236,7 @@ bool JpegHardwareDecoder::AssembleComponentInfo(jpeg_decompress_struct* jpegComp JPEG_HW_LOGE("unsupported component number: %{public}d!", jpegCompressInfo->num_components); return false; } - decodeInfo_.numComponents = jpegCompressInfo->num_components; + decodeInfo_.numComponents = static_cast(jpegCompressInfo->num_components); for (int i = 0; i < jpegCompressInfo->num_components; ++i) { decodeInfo_.compInfo.emplace_back(CodecJpegCompInfo { .componentId = jpegCompressInfo->comp_info[i].component_id, @@ -316,7 +316,7 @@ bool JpegHardwareDecoder::AssembleJpegImgHeader(jpeg_decompress_struct* jpegComp { decodeInfo_.imageWidth = jpegCompressInfo->image_width; decodeInfo_.imageHeight = jpegCompressInfo->image_height; - decodeInfo_.dataPrecision = jpegCompressInfo->data_precision; + decodeInfo_.dataPrecision = static_cast(jpegCompressInfo->data_precision); decodeInfo_.restartInterval = jpegCompressInfo->restart_interval; decodeInfo_.arithCode = jpegCompressInfo->arith_code; decodeInfo_.progressiveMode = jpegCompressInfo->progressive_mode; @@ -522,9 +522,9 @@ bool JpegHardwareDecoder::PackingInputBufferHandle(BufferHandle* inputBufferHand return false; } curHandle->fd = inputBufferHandle->fd; - curHandle->size = usedSizeInPool_; - curHandle->width = usedSizeInPool_; - curHandle->stride = usedSizeInPool_; + curHandle->size = static_cast(usedSizeInPool_); + curHandle->width = static_cast(usedSizeInPool_); + curHandle->stride = static_cast(usedSizeInPool_); curHandle->height = 1; curHandle->reserveFds = 0; curHandle->reserveInts = 0; diff --git a/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h b/plugins/common/libs/image/libjpegplugin/include/jpeg_utils.h index 49f2efe4c513fc2dae852d1912daae548dffe0f4..e610d9276edd40dd9e7eb3e78f2bc608da9387f2 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 = {}; // 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 8eb0b9e15b916a0f4d6f3a791ede795137e8ecd8..9bb9c148b1f050cfab35baf870500e3e0f842e59 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; } @@ -255,18 +255,18 @@ J_COLOR_SPACE JpegDecoder::GetDecodeFormat(PixelFormat format, PixelFormat &outp static int CalculateInSampleSize(const jpeg_decompress_struct &dInfo, const PixelDecodeOptions &opts) { - int inSampleSize = 1; + unsigned int inSampleSize = 1; // Input height and width of image - int width = dInfo.image_width; - int height = dInfo.image_height; + unsigned int width = dInfo.image_width; + unsigned int height = dInfo.image_height; if (opts.desiredSize.height > 0 && opts.desiredSize.width > 0) { - int reqHeight = opts.desiredSize.height; - int reqWidth = opts.desiredSize.width; + unsigned int reqHeight = static_cast(opts.desiredSize.height); + unsigned int reqWidth = static_cast(opts.desiredSize.width); if (height > reqHeight || width > reqWidth) { - const int halfHeight = height >> 1; - const int halfWidth = width >> 1; + const unsigned int halfHeight = height >> 1; + const unsigned int halfWidth = width >> 1; // Calculate the largest inSampleSize value that is a power of 2 and keeps both // height and width larger than the requested height and width. @@ -275,7 +275,7 @@ static int CalculateInSampleSize(const jpeg_decompress_struct &dInfo, const Pixe } } } - return inSampleSize; + return static_cast(inSampleSize); } /* @@ -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; @@ -473,7 +473,7 @@ uint32_t JpegDecoder::DoSwDecode(DecodeContext &context) __attribute__((no_sanit #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) if (context.allocatorType == Media::AllocatorType::DMA_ALLOC) { SurfaceBuffer* sbBuffer = reinterpret_cast (context.pixelsBuffer.context); - rowStride = sbBuffer->GetStride(); + rowStride = static_cast(sbBuffer->GetStride()); } #endif while (decodeInfo_.output_scanline < decodeInfo_.output_height) { diff --git a/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp b/plugins/common/libs/image/libjpegplugin/src/jpeg_encoder.cpp index 15cb5c69a57db53026758fd7e8a4a15940b45fd5..d74f9de2f6c930f93ffcaeaa8945eded419ea51b 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) { @@ -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 * 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) {