/*
- * Copyright (c) 2021 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.
// Check header to see if it is a PNG file
size_t size = fread(header, 1, 8, fp);
- if(size != 8)
+ if(DALI_UNLIKELY(size != 8))
{
DALI_LOG_ERROR("fread failed\n");
return false;
}
- if(png_sig_cmp(header, 0, 8))
+ if(DALI_UNLIKELY(png_sig_cmp(header, 0, 8)))
{
DALI_LOG_ERROR("png_sig_cmp failed\n");
return false;
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if(!png)
+ if(DALI_UNLIKELY(!png))
{
DALI_LOG_ERROR("Can't create PNG read structure\n");
return false;
}
info = png_create_info_struct(png);
- if(!info)
+ if(DALI_UNLIKELY(!info))
{
DALI_LOG_ERROR("png_create_info_struct failed\n");
return false;
png_set_expand(png);
- if(setjmp(png_jmpbuf(png)))
+ if(DALI_UNLIKELY(setjmp(png_jmpbuf(png))))
{
DALI_LOG_ERROR("error during png_init_io\n");
return false;
bool valid = false;
// Load info from the header
- if(!LoadPngHeader(input.file, width, height, png, info))
+ if(DALI_UNLIKELY(!LoadPngHeader(input.file, width, height, png, info)))
{
return false;
}
}
}
- if(!valid)
+ if(DALI_UNLIKELY(!valid))
{
DALI_LOG_ERROR("Unsupported png format\n");
return false;
png_read_update_info(png, info);
- if(setjmp(png_jmpbuf(png)))
+ if(DALI_UNLIKELY(setjmp(png_jmpbuf(png))))
{
DALI_LOG_ERROR("error during png_read_image\n");
return false;
auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer();
DALI_ASSERT_DEBUG(pixels);
+
+ if(!pixels)
+ {
+ DALI_LOG_ERROR("PixelBuffer couldn't be created\n");
+ return false;
+ }
+
rows = reinterpret_cast<png_bytep*>(malloc(sizeof(png_bytep) * height));
- if(!rows)
+ if(DALI_UNLIKELY(!rows))
{
- DALI_LOG_ERROR("malloc is failed\n");
+ DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", sizeof(png_bytep) * height);
return false;
}
if(encoded_img)
{
const Vector<unsigned char>::SizeType bufferSize = encoded_img->Count();
- encoded_img->Resize(bufferSize + length); //< Can throw OOM.
+ encoded_img->ResizeUninitialized(bufferSize + length); //< Can throw OOM.
unsigned char* const bufferBack = encoded_img->Begin() + bufferSize;
memcpy(bufferBack, data, length);
}
extern "C" void FlushData(png_structp png_ptr)
{
#ifdef DEBUG_ENABLED
- Debug::LogMessage(Debug::DebugInfo, "PNG Flush");
+ Debug::LogMessageWithFunctionLine(Debug::INFO, "PNG Flush");
#endif // DEBUG_ENABLED
}
} // namespace
// Account for RGB versus BGR and presence of alpha in input pixels:
switch(pixelFormat)
{
+ case Pixel::L8:
+ {
+ pngPixelFormat = PNG_COLOR_TYPE_GRAY;
+ pixelBytes = 1;
+ break;
+ }
+ case Pixel::LA88:
+ {
+ pngPixelFormat = PNG_COLOR_TYPE_GRAY_ALPHA;
+ pixelBytes = 2;
+ break;
+ }
case Pixel::RGB888:
{
pngPixelFormat = PNG_COLOR_TYPE_RGB;
}
default:
{
- DALI_LOG_ERROR("Unsupported pixel format for encoding to PNG.\n");
+ DALI_LOG_ERROR("Unsupported pixel format for encoding to PNG. Format enum : [%d]\n", pixelFormat);
return false;
}
}
const int interlace = PNG_INTERLACE_NONE;
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if(!png_ptr)
+ if(DALI_UNLIKELY(!png_ptr))
{
+ DALI_LOG_ERROR("Fail to create png_structp for png version" PNG_LIBPNG_VER_STRING "\n");
return false;
}
/* Allocate/initialize the image information data. REQUIRED */
png_infop info_ptr = png_create_info_struct(png_ptr);
- if(!info_ptr)
+ if(DALI_UNLIKELY(!info_ptr))
{
+ DALI_LOG_ERROR("Fail to create png_infop\n");
png_destroy_write_struct(&png_ptr, NULL);
return false;
}
/* Set error handling. REQUIRED if you aren't supplying your own
* error handling functions in the png_create_write_struct() call.
*/
- if(setjmp(png_jmpbuf(png_ptr)))
+ if(DALI_UNLIKELY(setjmp(png_jmpbuf(png_ptr))))
{
+ DALI_LOG_ERROR("Fail to png_jmpbuf\n");
png_destroy_write_struct(&png_ptr, &info_ptr);
return false;
}