From be9554be5f0272cbadacb2d2cdabc0e471c8326d Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Tue, 6 Aug 2024 18:27:51 +0900 Subject: [PATCH] Print more detail logs if image load failed - Do not assert if download buffer size is zero - Print log if FileDescription is NULL - Print log if fseek / ftell failed - Print log if download failed, or download data size is 0 Change-Id: I0f69e12baa44d04a9a26b03cf2c7f1bd9e087bf1 Signed-off-by: Eunki, Hong --- .../adaptor-framework/image-loading.cpp | 43 +++++++++++++--- dali/internal/imaging/common/gif-loading.cpp | 12 +++++ dali/internal/imaging/common/image-loader.cpp | 50 +++++++++++++++---- dali/internal/imaging/common/loader-ico.cpp | 9 +++- dali/internal/imaging/common/webp-loading.cpp | 19 ++++++- 5 files changed, 114 insertions(+), 19 deletions(-) diff --git a/dali/devel-api/adaptor-framework/image-loading.cpp b/dali/devel-api/adaptor-framework/image-loading.cpp index a552b618e..2c345346a 100644 --- a/dali/devel-api/adaptor-framework/image-loading.cpp +++ b/dali/devel-api/adaptor-framework/image-loading.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ Devel::PixelBuffer LoadImageFromFile(const std::string& url, ImageDimensions siz Internal::Platform::FileReader fileReader(url); FILE* const fp = fileReader.GetFile(); - if(fp != NULL) + if(DALI_LIKELY(fp != NULL)) { Dali::Devel::PixelBuffer bitmap; bool success = TizenPlatform::ImageLoader::ConvertStreamToBitmap(resourceType, url, fp, bitmap); @@ -48,6 +48,10 @@ Devel::PixelBuffer LoadImageFromFile(const std::string& url, ImageDimensions siz return bitmap; } } + else + { + DALI_LOG_ERROR("Error reading file\n"); + } return Dali::Devel::PixelBuffer(); } @@ -57,10 +61,14 @@ void LoadImagePlanesFromFile(const std::string& url, std::vector& buffer, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection) @@ -74,7 +82,7 @@ Devel::PixelBuffer LoadImageFromBuffer(const Dali::Vector& buffer, Imag Internal::Platform::FileReader fileReader(buffer); FILE* const fp = fileReader.GetFile(); - if(fp != NULL) + if(DALI_LIKELY(fp != NULL)) { Dali::Devel::PixelBuffer bitmap; // Make path as empty string. Path information just for file format hint. @@ -84,6 +92,10 @@ Devel::PixelBuffer LoadImageFromBuffer(const Dali::Vector& buffer, Imag return bitmap; } } + else + { + DALI_LOG_ERROR("Error reading file\n"); + } return Dali::Devel::PixelBuffer(); } @@ -98,7 +110,7 @@ Devel::PixelBuffer LoadImageFromBuffer(uint8_t* buffer, size_t bufferSize, Image Internal::Platform::FileReader fileReader(buffer, bufferSize); FILE* const fp = fileReader.GetFile(); - if(fp != NULL) + if(DALI_LIKELY(fp != NULL)) { Dali::Devel::PixelBuffer bitmap; // Make path as empty string. Path information just for file format hint. @@ -108,6 +120,10 @@ Devel::PixelBuffer LoadImageFromBuffer(uint8_t* buffer, size_t bufferSize, Image return bitmap; } } + else + { + DALI_LOG_ERROR("Error reading file\n"); + } return Dali::Devel::PixelBuffer(); } @@ -142,14 +158,13 @@ Devel::PixelBuffer DownloadImageSynchronously(const std::string& url, ImageDimen if(succeeded) { size_t blobSize = dataBuffer.Size(); - DALI_ASSERT_DEBUG(blobSize > 0U); - if(blobSize > 0U) + if(DALI_LIKELY(blobSize > 0U)) { // Open a file handle on the memory buffer: Dali::Internal::Platform::FileReader fileReader(dataBuffer, blobSize); FILE* const fp = fileReader.GetFile(); - if(NULL != fp) + if(DALI_LIKELY(NULL != fp)) { Dali::Devel::PixelBuffer bitmap; bool result = TizenPlatform::ImageLoader::ConvertStreamToBitmap( @@ -167,7 +182,19 @@ Devel::PixelBuffer DownloadImageSynchronously(const std::string& url, ImageDimen DALI_LOG_WARNING("Unable to decode bitmap supplied as in-memory blob.\n"); } } + else + { + DALI_LOG_ERROR("Error reading file\n"); + } } + else + { + DALI_LOG_ERROR("Error download empty buffer!\n"); + } + } + else + { + DALI_LOG_ERROR("Error download failed!\n"); } return Dali::Devel::PixelBuffer(); } diff --git a/dali/internal/imaging/common/gif-loading.cpp b/dali/internal/imaging/common/gif-loading.cpp index c35899aec..06723bb69 100644 --- a/dali/internal/imaging/common/gif-loading.cpp +++ b/dali/internal/imaging/common/gif-loading.cpp @@ -299,17 +299,20 @@ bool LoaderInfo::FileData::LoadLocalFile() FILE* fp = fileReader.GetFile(); if(DALI_UNLIKELY(fp == NULL)) { + DALI_LOG_ERROR("Error reading file\n"); return false; } if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END) <= -1)) { + DALI_LOG_ERROR("Error seeking within file\n"); return false; } length = ftell(fp); if(DALI_UNLIKELY(length <= -1)) { + DALI_LOG_ERROR("Could not determine GIF file size.\n"); return false; } @@ -325,6 +328,7 @@ bool LoaderInfo::FileData::LoadLocalFile() } else { + DALI_LOG_ERROR("Error seeking within file\n"); return false; } return true; @@ -371,6 +375,14 @@ bool LoaderInfo::FileData::LoadRemoteFile() DALI_LOG_ERROR("Error reading file\n"); } } + else + { + DALI_LOG_ERROR("Error download empty buffer!\n"); + } + } + else + { + DALI_LOG_ERROR("Error download failed!\n"); } return succeeded; diff --git a/dali/internal/imaging/common/image-loader.cpp b/dali/internal/imaging/common/image-loader.cpp index b19b3a75b..081b3f714 100644 --- a/dali/internal/imaging/common/image-loader.cpp +++ b/dali/internal/imaging/common/image-loader.cpp @@ -176,7 +176,7 @@ bool GetBitmapLoaderFunctions(FILE* fp, size_t read = fread(magic, sizeof(unsigned char), MAGIC_LENGTH, fp); // Reset to the start of the file. - if(fseek(fp, 0, SEEK_SET)) + if(DALI_UNLIKELY(fseek(fp, 0, SEEK_SET))) { DALI_LOG_ERROR("Error seeking to start of file\n"); } @@ -262,7 +262,7 @@ bool GetBitmapLoaderFunctions(FILE* fp, } // Reset to the start of the file. - if(fseek(fp, 0, SEEK_SET)) + if(DALI_UNLIKELY(fseek(fp, 0, SEEK_SET))) { DALI_LOG_ERROR("Error seeking to start of file\n"); } @@ -280,7 +280,7 @@ bool ConvertStreamToBitmap(const BitmapResourceType& resource, const std::string bool result = false; - if(fp != NULL) + if(DALI_LIKELY(fp != NULL)) { Dali::ImageLoader::LoadBitmapFunction function; Dali::ImageLoader::LoadPlanesFunction planeLoader; @@ -315,6 +315,10 @@ bool ConvertStreamToBitmap(const BitmapResourceType& resource, const std::string DALI_LOG_ERROR("Image Decoder for %s unavailable\n", path.c_str()); } } + else + { + DALI_LOG_ERROR("Error reading file\n"); + } return result; } @@ -325,7 +329,7 @@ bool ConvertStreamToPlanes(const Integration::BitmapResourceType& resource, cons bool result = false; - if(fp != NULL) + if(DALI_LIKELY(fp != NULL)) { Dali::ImageLoader::LoadBitmapFunction loader; Dali::ImageLoader::LoadPlanesFunction planeLoader; @@ -399,6 +403,10 @@ bool ConvertStreamToPlanes(const Integration::BitmapResourceType& resource, cons DALI_LOG_ERROR("Image Decoder for %s unavailable\n", path.c_str()); } } + else + { + DALI_LOG_ERROR("Error reading file\n"); + } return result; } @@ -410,7 +418,7 @@ ResourcePointer LoadImageSynchronously(const Integration::BitmapResourceType& re Internal::Platform::FileReader fileReader(path); FILE* const fp = fileReader.GetFile(); - if(fp != NULL) + if(DALI_LIKELY(fp != NULL)) { bool success = ConvertStreamToBitmap(resource, path, fp, bitmap); if(success && bitmap) @@ -435,6 +443,10 @@ ResourcePointer LoadImageSynchronously(const Integration::BitmapResourceType& re result.Reset(retval); } } + else + { + DALI_LOG_ERROR("Error reading file\n"); + } return result; } @@ -458,7 +470,7 @@ ImageDimensions GetClosestImageSize(const std::string& filename, Internal::Platform::FileReader fileReader(filename); FILE* fp = fileReader.GetFile(); - if(fp != NULL) + if(DALI_LIKELY(fp != NULL)) { Dali::ImageLoader::LoadBitmapFunction loaderFunction; Dali::ImageLoader::LoadPlanesFunction planeLoader; @@ -486,6 +498,10 @@ ImageDimensions GetClosestImageSize(const std::string& filename, DALI_LOG_ERROR("Image Decoder for %s unavailable\n", filename.c_str()); } } + else + { + DALI_LOG_ERROR("Error reading file for %s\n", filename.c_str()); + } return ImageDimensions(width, height); } @@ -502,14 +518,14 @@ ImageDimensions GetClosestImageSize(Integration::ResourcePointer resourceBuffer, DALI_ASSERT_DEBUG(resourceBuffer); Dali::RefCountedVector* const encodedBlob = reinterpret_cast*>(resourceBuffer.Get()); - if(encodedBlob != 0) + if(DALI_LIKELY(encodedBlob != 0)) { - if(encodedBlob->GetVector().Size()) + if(DALI_LIKELY(encodedBlob->GetVector().Size())) { // Open a file handle on the memory buffer: Internal::Platform::FileReader fileReader(encodedBlob->GetVector()); FILE* fp = fileReader.GetFile(); - if(fp != NULL) + if(DALI_LIKELY(fp != NULL)) { Dali::ImageLoader::LoadBitmapFunction loaderFunction; Dali::ImageLoader::LoadPlanesFunction planeLoader; @@ -531,8 +547,24 @@ ImageDimensions GetClosestImageSize(Integration::ResourcePointer resourceBuffer, DALI_LOG_ERROR("Image Decoder failed to read header for resourceBuffer\n"); } } + else + { + DALI_LOG_ERROR("Image Decoder unavailable\n"); + } + } + else + { + DALI_LOG_ERROR("Error reading file\n"); } } + else + { + DALI_LOG_ERROR("Image Buffer is empty size\n"); + } + } + else + { + DALI_LOG_ERROR("Image Buffer is nullptr\n"); } return ImageDimensions(width, height); } diff --git a/dali/internal/imaging/common/loader-ico.cpp b/dali/internal/imaging/common/loader-ico.cpp index b23eaeed9..b7d79b3e9 100644 --- a/dali/internal/imaging/common/loader-ico.cpp +++ b/dali/internal/imaging/common/loader-ico.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -188,6 +188,7 @@ bool LoadIcoHeaderHelper(FILE* fp, if(DALI_UNLIKELY(0u == fsize)) { + DALI_LOG_ERROR("Error ICO data size is zero!\n"); return false; } @@ -199,6 +200,7 @@ bool LoadIcoHeaderHelper(FILE* fp, if(DALI_UNLIKELY(fsize < (ICO_FILE_HEADER + ICO_IMAGE_INFO_HEADER))) //6 + 16 + 40 { + DALI_LOG_ERROR("Error ICO data size is too small! (%ld < %u)!\n", fsize, static_cast(ICO_FILE_HEADER + ICO_IMAGE_INFO_HEADER)); return false; } map.ResizeUninitialized(fsize); @@ -214,19 +216,23 @@ bool LoadIcoHeaderHelper(FILE* fp, unsigned short reserved, type, count; if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &reserved))) { + DALI_LOG_ERROR("Error ICO header.reserved decode failed!\n"); return false; } if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &type))) { + DALI_LOG_ERROR("Error ICO header.type decode failed!\n"); return false; } if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &count))) { + DALI_LOG_ERROR("Error ICO header.count decode failed!\n"); return false; } if(DALI_UNLIKELY(!((reserved == 0) && ((type == ICON) || (type == CURSOR)) && (count != 0)))) { + DALI_LOG_ERROR("Error ICO header is invalid! (reserved : %hu, type : %hu, count : %hu)\n", reserved, type, count); return false; } search = BIGGEST; @@ -327,6 +333,7 @@ bool LoadIcoHeaderHelper(FILE* fp, if(DALI_UNLIKELY(chosen.bmoffset == 0)) { + DALI_LOG_ERROR("Error ICO data is invalid!\n"); return false; } diff --git a/dali/internal/imaging/common/webp-loading.cpp b/dali/internal/imaging/common/webp-loading.cpp index 24f150650..1a550bfd2 100644 --- a/dali/internal/imaging/common/webp-loading.cpp +++ b/dali/internal/imaging/common/webp-loading.cpp @@ -184,10 +184,18 @@ public: // Open a file handle on the memory buffer: fileReader = std::make_unique(dataBuffer, mBufferSize); } + else + { + DALI_LOG_ERROR("Error download empty buffer!\n"); + } + } + else + { + DALI_LOG_ERROR("Error download failed!\n"); } } - if(fileReader) + if(DALI_LIKELY(fileReader)) { fp = fileReader->GetFile(); } @@ -199,6 +207,7 @@ public: { if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END) <= -1)) { + DALI_LOG_ERROR("Error seeking within file\n"); return false; } mBufferSize = ftell(fp); @@ -215,6 +224,14 @@ public: mBufferSize = fread(mBuffer, sizeof(WebPByteType), mBufferSize, fp); return true; } + else + { + DALI_LOG_ERROR("Error seeking within file\n"); + } + } + else + { + DALI_LOG_ERROR("Error reading file\n"); } return false; } -- 2.34.1