diff --git a/frameworks/innerkitsimpl/utils/src/image_utils.cpp b/frameworks/innerkitsimpl/utils/src/image_utils.cpp index a62df6530dabbb49b6fc803fb53b70f9faf88da3..bc5bd98c39cd40a23ae5d5d9be69f2fca7db29f2 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -1257,5 +1257,62 @@ void ImageUtils::SetReuseContextBuffer(ImagePlugin::DecodeContext& context, context.pixelsBuffer.bufferSize = count; context.pixelsBuffer.context = fd; } + +bool ImageUtils::CheckRowDataSizeIsVaild(int32_t &rowDataSize, ImageInfo &imgInfo) +{ + int32_t bytesPerPixel = ImageUtils::GetPixelBytes(imgInfo.pixelFormat); + if (bytesPerPixel == 0 || rowDataSize <=0 || + rowDataSize != ImageUtils::GetRowDataSizeByPixelFormat(imgInfo.size.width, imgInfo.pixelFormat)) { + IMAGE_LOGE("[ImageUtils] RowDataSizeIsVaild: bytesPerPixel or rowDataSize:%{public}d", rowDataSize); + return false; + } + return true; +} + +bool ImageUtils::CheckBufferSizeIsVaild(int32_t &bufferSize, uint64_t &expectedBufferSize, AllocatorType &allocatorType) +{ + if (bufferSize <= 0 || + expectedBufferSize > (allocatorType == AllocatorType::HEAP_ALLOC ? PIXEL_MAP_MAX_RAM_SIZE : INT_MAX) || + expectedBufferSize != static_cast(bufferSize)) { + IMAGE_LOGE("[ImageUtils] BufferSizeIsVaild: bufferSize invalid, expect:%{public}llu, actual:%{public}d", + static_cast(expectedBufferSize), bufferSize); + return false; + } + return true; +} + +bool ImageUtils::GetAlignedNumber(int32_t& number, int32_t align) +{ + if (number < 0 || align <= 0) { + return false; + } + int64_t res = number; + res = (res + align - 1) / align * align; + if (res > INT32_MAX) { + return false; + } + number = static_cast(res); + return true; +} + +uint16_t ImageUtils::GetRGBA1010102ColorR(uint32_t color) +{ + return (color >> RGBA1010102_R_SHIFT) & RGBA1010102_RGB_MASK; +} + +uint16_t ImageUtils::GetRGBA1010102ColorG(uint32_t color) +{ + return (color >> RGBA1010102_G_SHIFT) & RGBA1010102_RGB_MASK; +} + +uint16_t ImageUtils::GetRGBA1010102ColorB(uint32_t color) +{ + return (color >> RGBA1010102_B_SHIFT) & RGBA1010102_RGB_MASK; +} + +uint16_t ImageUtils::GetRGBA1010102ColorA(uint32_t color) +{ + return (color >> RGBA1010102_A_SHIFT) & RGBA1010102_ALPHA_MASK; +} } // namespace Media } // namespace OHOS