1. Wrap DALI_UNLIKELY if there was some system / file error.
e.g. fread, fseek faild. malloc faild. image size or format not valid.
2. Reduce Dali::Vector operation more times.
When we use fixed size of Dali::Vector, use void * or std::uint8_t*
instead of &vector[0]. It's for reducing function call of operator[]
so we don't check index range, so we don't call Dali::Vector::Count().
3. Don't setup initial value of buffer for some cases.
Note. gausian-blur.cpp defect will be fixed in Heeyong's stride patch.
4. Reduce useless operations on loader-ico.cpp
Previous code use 4 times memory + buffer overflow error exist
when bitcount is 1 + read mask buffer only for each line. not whole buffer.
Change-Id: I28cdd7468ec4d573e53f4f6f7ad2345bca60b273
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
}
dataBuffer.ResizeUninitialized(dataSize);
- size_t offset = 0;
- for(size_t i = 0; i < chunks.size(); ++i)
+ if(DALI_LIKELY(dataSize > 0))
{
- memcpy(&dataBuffer[offset], &chunks[i].data[0], chunks[i].data.capacity());
- offset += chunks[i].data.capacity();
+ std::uint8_t* dataBufferPtr = dataBuffer.Begin();
+ for(size_t i = 0; i < chunks.size(); ++i)
+ {
+ memcpy(dataBufferPtr, &chunks[i].data[0], chunks[i].data.capacity());
+ dataBufferPtr += chunks[i].data.capacity();
+ }
}
return result;
{
LoaderInfo::FileInfo* fi = reinterpret_cast<LoaderInfo::FileInfo*>(gifFileType->UserData);
- if(fi->position >= fi->length)
+ if(DALI_UNLIKELY(fi->position >= fi->length))
{
return 0; // if at or past end - no
}
{
Internal::Platform::FileReader fileReader(fileName);
FILE* fp = fileReader.GetFile();
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
return false;
}
- if(fseek(fp, 0, SEEK_END) <= -1)
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END) <= -1))
{
return false;
}
length = ftell(fp);
- if(length <= -1)
+ if(DALI_UNLIKELY(length <= -1))
{
return false;
}
- if((!fseek(fp, 0, SEEK_SET)))
+ if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET)))
{
globalMap = reinterpret_cast<GifByteType*>(malloc(sizeof(GifByteType) * length));
length = fread(globalMap, sizeof(GifByteType), length, fp);
size_t dataSize;
succeeded = TizenPlatform::Network::DownloadRemoteFileIntoMemory(fileName, dataBuffer, dataSize, MAXIMUM_DOWNLOAD_IMAGE_SIZE);
- if(succeeded)
+ if(DALI_LIKELY(succeeded))
{
size_t blobSize = dataBuffer.Size();
- 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))
{
- if((!fseek(fp, 0, SEEK_SET)))
+ if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET)))
{
globalMap = reinterpret_cast<GifByteType*>(malloc(sizeof(GifByteType) * blobSize));
length = fread(globalMap, sizeof(GifByteType), blobSize, fp);
* @param[in] index Frame index to be searched in GIF
* @return A pointer to the ImageFrame.
*/
-inline int CombinePixelABGR(int a, int r, int g, int b)
+inline std::uint32_t CombinePixelABGR(const std::uint32_t& a, const std::uint32_t& r, const std::uint32_t& g, const std::uint32_t& b)
{
return (((a) << 24) + ((b) << 16) + ((g) << 8) + (r));
}
-inline int PixelLookup(ColorMapObject* colorMap, int index)
+inline std::uint32_t PixelLookup(const ColorMapObject* const& colorMap, int index)
{
return CombinePixelABGR(0xFF, colorMap->Colors[index].Red, colorMap->Colors[index].Green, colorMap->Colors[index].Blue);
}
* @brief Fill in an image with a specific rgba color value.
*
* @param[in] data A pointer pointing to an image data
- * @param[in] row A int containing the number of rows in an image
+ * @param[in] stride A int containing the number of stride in an image
* @param[in] val A uint32_t containing rgba color value
* @param[in] x X-coordinate used an offset to calculate pixel position
* @param[in] y Y-coordinate used an offset to calculate pixel position
* @param[in] width Width of the image
* @param[in] height Height of the image
*/
-void FillImage(uint32_t* data, int row, uint32_t val, int x, int y, int width, int height)
+void FillImage(uint32_t* data, int stride, uint32_t val, int x, int y, int width, int height)
{
- int xAxis, yAxis;
uint32_t* pixelPosition;
- for(yAxis = 0; yAxis < height; yAxis++)
+ // Boost time if stride == width and x == 0. We can assume that all pointer is continuous.
+ if(x == 0 && stride == width)
{
- pixelPosition = data + ((y + yAxis) * row) + x;
- for(xAxis = 0; xAxis < width; xAxis++)
+ pixelPosition = data + (y * stride);
+ // Clear as white or transparent
+ // Special case. we can use memset.
+ if(val == 0x00 || val == 0xffffffffu)
{
- *pixelPosition = val;
- pixelPosition++;
+ const std::int8_t setupVal = val & 0xff;
+ memset(pixelPosition, setupVal, width * height * sizeof(std::uint32_t));
+ }
+ else
+ {
+ for(int byteCount = 0; byteCount < width * height; ++byteCount)
+ {
+ *pixelPosition = val;
+ ++pixelPosition;
+ }
+ }
+ }
+ else
+ {
+ for(int yAxis = 0; yAxis < height; ++yAxis)
+ {
+ pixelPosition = data + ((y + yAxis) * stride) + x;
+ for(int xAxis = 0; xAxis < width; ++xAxis)
+ {
+ *pixelPosition = val;
+ ++pixelPosition;
+ }
}
}
}
* @brief Fill a rgba data pixle blob with a frame color (bg or trans)
*
* @param[in] data A pointer pointing to an image data
- * @param[in] row A int containing the number of rows in an image
+ * @param[in] stride A int containing the number of stride in an image
* @param[in] gif A pointer pointing to GIF File Type
* @param[in] frameInfo A pointer pointing to Frame Information data
* @param[in] x X-coordinate used an offset to calculate pixel position
* @param[in] width Width of the image
* @param[in] height Height of the image
*/
-void FillFrame(uint32_t* data, int row, GifFileType* gif, FrameInfo* frameInfo, int x, int y, int w, int h)
+void FillFrame(uint32_t* data, int stride, GifFileType* gif, FrameInfo* frameInfo, int x, int y, int w, int h)
{
// solid color fill for pre frame region
if(frameInfo->transparent < 0)
}
backGroundColor = gif->SBackGroundColor;
// and do the fill
- FillImage(data, row, CombinePixelABGR(0xff, colorMap->Colors[backGroundColor].Red, colorMap->Colors[backGroundColor].Green, colorMap->Colors[backGroundColor].Blue), x, y, w, h);
+ FillImage(data, stride, CombinePixelABGR(0xff, colorMap->Colors[backGroundColor].Red, colorMap->Colors[backGroundColor].Green, colorMap->Colors[backGroundColor].Blue), x, y, w, h);
}
// fill in region with 0 (transparent)
else
{
- FillImage(data, row, 0, x, y, w, h);
+ FillImage(data, stride, 0, x, y, w, h);
}
}
gifW = sp->ImageDesc.Width;
gifH = sp->ImageDesc.Height;
- if((gifW < w) || (gifH < h))
+ if(DALI_UNLIKELY((gifW < w) || (gifH < h)))
{
DALI_LOG_ERROR("gifW : %d, w : %d, gifH : %d, h : %d\n", gifW, w, gifH, h);
DALI_ASSERT_DEBUG(false && "Dimensions are bigger than the Gif image size");
// build a blob of memory to have pointers to rows of pixels
// AND store the decoded gif pixels (1 byte per pixel) as welll
rows = static_cast<GifRowType*>(malloc((gifH * sizeof(GifRowType)) + (gifW * gifH * sizeof(GifPixelType))));
- if(!rows)
+ if(DALI_UNLIKELY(!rows))
{
goto on_error;
}
{
for(yy = intoffset[i]; yy < gifH; yy += intjump[i])
{
- if(DGifGetLine(gif, rows[yy], gifW) != GIF_OK)
+ if(DALI_UNLIKELY(DGifGetLine(gif, rows[yy], gifW) != GIF_OK))
{
goto on_error;
}
{
for(yy = 0; yy < gifH; yy++)
{
- if(DGifGetLine(gif, rows[yy], gifW) != GIF_OK)
+ if(DALI_UNLIKELY(DGifGetLine(gif, rows[yy], gifW) != GIF_OK))
{
goto on_error;
}
bool full = true;
success = fileData.LoadFile();
- if(!success || !fileData.globalMap)
+ if(DALI_UNLIKELY(!success || !fileData.globalMap))
{
success = false;
DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
prop.h = gifAccessor.gif->SHeight;
// if size is invalid - abort here
- if((prop.w < 1) || (prop.h < 1) || (prop.w > IMG_MAX_SIZE) || (prop.h > IMG_MAX_SIZE) || IMG_TOO_BIG(prop.w, prop.h))
+ if(DALI_UNLIKELY((prop.w < 1) || (prop.h < 1) || (prop.w > IMG_MAX_SIZE) || (prop.h > IMG_MAX_SIZE) || IMG_TOO_BIG(prop.w, prop.h)))
{
if(IMG_TOO_BIG(prop.w, prop.h))
{
GifByteType* img;
// get image desc
- if(DGifGetImageDesc(gifAccessor.gif) == GIF_ERROR)
+ if(DALI_UNLIKELY(DGifGetImageDesc(gifAccessor.gif) == GIF_ERROR))
{
success = false;
DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
break;
}
// skip decoding and just walk image to next
- if(DGifGetCode(gifAccessor.gif, &img_code, &img) == GIF_ERROR)
+ if(DALI_UNLIKELY(DGifGetCode(gifAccessor.gif, &img_code, &img) == GIF_ERROR))
{
success = false;
DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
{
// allocate and save frame with field data
frameInfo = NewFrame(animated, -1, 0, 0, imageNumber + 1);
- if(!frameInfo)
+ if(DALI_UNLIKELY(!frameInfo))
{
success = false;
DALI_LOG_ERROR("LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
int disposeMode = (ext[1] >> 2) & 0x7;
int delay = (int(ext[3]) << 8) | int(ext[2]);
frameInfo = NewFrame(animated, transparencyIndex, disposeMode, delay, imageNumber + 1);
- if(!frameInfo)
+ if(DALI_UNLIKELY(!frameInfo))
{
success = false;
DALI_LOG_ERROR("LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
index = animated.currentFrame;
// if index is invalid for animated image - error out
- if((animated.animated) && ((index <= 0) || (index > animated.frameCount)))
+ if(DALI_UNLIKELY((animated.animated) && ((index <= 0) || (index > animated.frameCount))))
{
DALI_LOG_ERROR("LOAD_ERROR_GENERIC");
return false;
// find the given frame index
frame = FindFrame(animated, index);
- if(!frame)
+ if(DALI_UNLIKELY(!frame))
{
DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
return false;
loaderInfo.fileInfo.map = fileData.globalMap;
loaderInfo.fileInfo.length = fileData.length;
loaderInfo.fileInfo.position = 0;
- if(!loaderInfo.fileInfo.map)
+ if(DALI_UNLIKELY(!loaderInfo.fileInfo.map))
{
DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
return false;
}
std::unique_ptr<GifAccessor> gifAccessor = std::make_unique<GifAccessor>(loaderInfo.fileInfo);
- if(!gifAccessor->gif)
+ if(DALI_UNLIKELY(!gifAccessor->gif))
{
DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
return false;
// walk through gif records in file to figure out info
do
{
- if(DGifGetRecordType(loaderInfo.gifAccessor->gif, &rec) == GIF_ERROR)
+ if(DALI_UNLIKELY(DGifGetRecordType(loaderInfo.gifAccessor->gif, &rec) == GIF_ERROR))
{
DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
return false;
ImageFrame* thisFrame = NULL;
// get image desc
- if(DGifGetImageDesc(loaderInfo.gifAccessor->gif) == GIF_ERROR)
+ if(DALI_UNLIKELY(DGifGetImageDesc(loaderInfo.gifAccessor->gif) == GIF_ERROR))
{
DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
return false;
// allocate it
thisFrame->data = new uint32_t[prop.w * prop.h];
- if(!thisFrame->data)
+ if(DALI_UNLIKELY(!thisFrame->data))
{
DALI_LOG_ERROR("LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
return false;
{
// Find last preserved frame.
lastPreservedFrame = FindFrame(animated, imageNumber - prevIndex);
- if(!lastPreservedFrame)
+ if(DALI_UNLIKELY(!lastPreservedFrame))
{
DALI_LOG_ERROR("LOAD_ERROR_LAST_PRESERVED_FRAME_NOT_FOUND");
return false;
// now draw this frame on top
frameInfo = &(thisFrame->info);
ClipCoordinates(prop.w, prop.h, &xin, &yin, frameInfo->x, frameInfo->y, frameInfo->w, frameInfo->h, &x, &y, &w, &h);
- if(!DecodeImage(loaderInfo.gifAccessor->gif, loaderInfo.cachedColor, thisFrame->data, prop.w, xin, yin, frameInfo->transparent, x, y, w, h, first))
+ if(DALI_UNLIKELY(!DecodeImage(loaderInfo.gifAccessor->gif, loaderInfo.cachedColor, thisFrame->data, prop.w, xin, yin, frameInfo->transparent, x, y, w, h, first)))
{
DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
return false;
FillFrame(reinterpret_cast<uint32_t*>(pixels), prop.w, loaderInfo.gifAccessor->gif, frameInfo, 0, 0, prop.w, prop.h);
// and decode the gif with overwriting
- if(!DecodeImage(loaderInfo.gifAccessor->gif, loaderInfo.cachedColor, reinterpret_cast<uint32_t*>(pixels), prop.w, xin, yin, frameInfo->transparent, x, y, w, h, true))
+ if(DALI_UNLIKELY(!DecodeImage(loaderInfo.gifAccessor->gif, loaderInfo.cachedColor, reinterpret_cast<uint32_t*>(pixels), prop.w, xin, yin, frameInfo->transparent, x, y, w, h, true)))
{
DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
return false;
else
{
// skip decoding and just walk image to next
- if(DGifGetCode(loaderInfo.gifAccessor->gif, &img_code, &img) == GIF_ERROR)
+ if(DALI_UNLIKELY(DGifGetCode(loaderInfo.gifAccessor->gif, &img_code, &img) == GIF_ERROR))
{
DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
return false;
bool ret = false;
Mutex::ScopedLock lock(mImpl->mMutex);
- if(!mImpl->mLoadSucceeded)
+ if(DALI_UNLIKELY(!mImpl->mLoadSucceeded))
{
return false;
}
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
{
// Pull the bytes of the file header in as a block:
const unsigned int readLength = sizeof(AstcFileHeader);
- if(fread(&fileHeader, 1, readLength, filePointer) != readLength)
+ if(DALI_UNLIKELY(fread(&fileHeader, 1, readLength, filePointer) != readLength))
{
return false;
}
// Check the header contains the ASTC native file identifier.
bool headerIsValid = memcmp(fileHeader.magic, FileIdentifier, sizeof(fileHeader.magic)) == 0;
- if(!headerIsValid)
+ if(DALI_UNLIKELY(!headerIsValid))
{
DALI_LOG_ERROR("File is not a valid ASTC native file\n");
// Return here as otherwise, if not a valid ASTC file, we are likely to pick up other header errors spuriously.
const unsigned int zDepth = static_cast<unsigned int>(fileHeader.zsize[0]) + (static_cast<unsigned int>(fileHeader.zsize[1]) << 8) + (static_cast<unsigned int>(fileHeader.zsize[2]) << 16);
// Check image dimensions are within limits.
- if((width > MAX_TEXTURE_DIMENSION) || (height > MAX_TEXTURE_DIMENSION))
+ if(DALI_UNLIKELY((width > MAX_TEXTURE_DIMENSION) || (height > MAX_TEXTURE_DIMENSION)))
{
DALI_LOG_ERROR("ASTC file has larger than supported dimensions: %d,%d\n", width, height);
headerIsValid = false;
}
// Confirm the ASTC block does not have any Z depth.
- if(zDepth != 1)
+ if(DALI_UNLIKELY(zDepth != 1))
{
DALI_LOG_ERROR("ASTC files with z size other than 1 are not supported. Z size is: %d\n", zDepth);
headerIsValid = false;
bool LoadBitmapFromAstc(const Dali::ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap)
{
FILE* const filePointer = input.file;
- if(!filePointer)
+ if(DALI_UNLIKELY(!filePointer))
{
DALI_LOG_ERROR("Null file handle passed to ASTC compressed bitmap file loader.\n");
return false;
AstcFileHeader fileHeader;
unsigned int width, height;
- if(!LoadAstcHeader(filePointer, width, height, fileHeader))
+ if(DALI_UNLIKELY(!LoadAstcHeader(filePointer, width, height, fileHeader)))
{
DALI_LOG_ERROR("Could not load ASTC Header from file.\n");
return false;
// Retrieve the pixel format from the ASTC block size.
Pixel::Format pixelFormat = GetAstcPixelFormat(fileHeader);
- if(pixelFormat == Pixel::INVALID)
+ if(DALI_UNLIKELY(pixelFormat == Pixel::INVALID))
{
DALI_LOG_ERROR("No internal pixel format supported for ASTC file pixel format.\n");
return false;
}
// Retrieve the file size.
- if(fseek(filePointer, 0L, SEEK_END))
+ if(DALI_UNLIKELY(fseek(filePointer, 0L, SEEK_END)))
{
DALI_LOG_ERROR("Could not seek through file.\n");
return false;
}
off_t fileSize = ftell(filePointer);
- if(fileSize == -1L)
+ if(DALI_UNLIKELY(fileSize == -1L))
{
DALI_LOG_ERROR("Could not determine ASTC file size.\n");
return false;
}
- if(fseek(filePointer, sizeof(AstcFileHeader), SEEK_SET))
+ if(DALI_UNLIKELY(fseek(filePointer, sizeof(AstcFileHeader), SEEK_SET)))
{
DALI_LOG_ERROR("Could not seek through file.\n");
return false;
size_t imageByteCount = fileSize - sizeof(AstcFileHeader);
// Sanity-check the image data is not too large and that it is at less than 2 bytes per texel:
- if((imageByteCount > MAX_IMAGE_DATA_SIZE) || (imageByteCount > ((static_cast<size_t>(width) * height) << 1)))
+ if(DALI_UNLIKELY((imageByteCount > MAX_IMAGE_DATA_SIZE) || (imageByteCount > ((static_cast<size_t>(width) * height) << 1))))
{
DALI_LOG_ERROR("ASTC file has too large image-data field.\n");
return false;
const size_t bytesRead = fread(pixels, 1, imageByteCount, filePointer);
// Check the size of loaded data is what we expected.
- if(bytesRead != imageByteCount)
+ if(DALI_UNLIKELY(bytesRead != imageByteCount))
{
DALI_LOG_ERROR("Read of image pixel data failed.\n");
return false;
const unsigned int readLength = sizeof(T);
// Load the information directly into our structure
- if(fread(&header, 1, readLength, fp) != readLength)
+ if(DALI_UNLIKELY(fread(&header, 1, readLength, fp) != readLength))
{
return false;
}
bool LoadBmpHeader(FILE* fp, unsigned int& width, unsigned int& height, BmpFileHeader& fileHeader, BmpInfoHeader& infoHeader)
{
- if(!ReadHeader(fp, fileHeader))
+ if(DALI_UNLIKELY(!ReadHeader(fp, fileHeader)))
{
DALI_LOG_ERROR("File header read failed\n");
return false;
}
- if(!ReadHeader(fp, infoHeader))
+ if(DALI_UNLIKELY(!ReadHeader(fp, infoHeader)))
{
DALI_LOG_ERROR("Info header read failed\n");
return false;
width = infoHeader.width;
height = abs(infoHeader.height);
- if(infoHeader.width == 0)
+ if(DALI_UNLIKELY(infoHeader.width == 0))
{
DALI_LOG_ERROR("Invalid header size\n");
return false;
unsigned int rowStride,
unsigned int padding)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_RGB24V5 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_RGB24V5 data\n");
return false;
{
pixelsPtr = pixels + (((height - 1) - yPos) * rowStride);
}
- if(fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+ if(DALI_UNLIKELY(fread(pixelsPtr, 1, rowStride, fp) != rowStride))
{
DALI_LOG_ERROR("Error reading the BMP image\n");
return false;
if(padding)
{
// move past the padding.
- if(fseek(fp, padding, SEEK_CUR))
+ if(DALI_UNLIKELY(fseek(fp, padding, SEEK_CUR)))
{
DALI_LOG_ERROR("Error moving past BMP_RGB24V5 padding\n");
}
unsigned int rowStride,
unsigned int padding)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_BITFIELDS32V4 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_BITFIELDS32V4 data\n");
return false;
{
pixelsPtr = pixels + (((height - 1) - yPos) * rowStride);
}
- if(fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+ if(DALI_UNLIKELY(fread(pixelsPtr, 1, rowStride, fp) != rowStride))
{
DALI_LOG_ERROR("Error reading the BMP image\n");
return false;
if(padding)
{
// move past the padding.
- if(fseek(fp, padding, SEEK_CUR))
+ if(DALI_UNLIKELY(fseek(fp, padding, SEEK_CUR)))
{
DALI_LOG_ERROR("Error moving past BMP_BITFIELDS32V4 padding\n");
}
unsigned int rowStride,
unsigned int padding)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_BITFIELDS32 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_BITFIELDS32 data\n");
return false;
pixelsPtr = pixels + (((height - 1) - yPos) * rowStride);
}
- if(fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+ if(DALI_UNLIKELY(fread(pixelsPtr, 1, rowStride, fp) != rowStride))
{
DALI_LOG_ERROR("Error reading the BMP image\n");
return false;
if(padding)
{
// move past the padding.
- if(fseek(fp, padding, SEEK_CUR))
+ if(DALI_UNLIKELY(fseek(fp, padding, SEEK_CUR)))
{
DALI_LOG_ERROR("Error moving past BMP_BITFIELDS32 padding\n");
}
unsigned int offset,
bool topDown)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding RGB565 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking RGB565 data\n");
return false;
// the data in the file is bottom up, and we store the data top down
pixelsPtr = pixels + (((height - 1) - i) * rowStride);
}
- if(fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+ if(DALI_UNLIKELY(fread(pixelsPtr, 1, rowStride, fp) != rowStride))
{
return false;
}
unsigned int offset,
bool topDown)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_BITFIELDS555 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_BITFIELDS555 data\n");
return false;
for(std::uint32_t j = 0; j < height; ++j)
{
rawPtr = &raw[0] + (j * rawStride);
- if(fread(rawPtr, 1, rawStride, fp) != rawStride)
+ if(DALI_UNLIKELY(fread(rawPtr, 1, rawStride, fp) != rawStride))
{
return false;
}
unsigned int offset,
bool topDown)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_RGB555 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_RGB555 data\n");
return false;
for(std::uint32_t j = 0; j < height; ++j)
{
rawPtr = &raw[0] + (j * rawStride);
- if(fread(rawPtr, 1, rawStride, fp) != rawStride)
+ if(DALI_UNLIKELY(fread(rawPtr, 1, rawStride, fp) != rawStride))
{
return false;
}
unsigned int offset,
bool topDown)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_RGB1 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_RGB1 data\n");
return false;
std::vector<std::uint8_t> colorIndex(fillw * height);
std::uint32_t rowStride = fillw * 3; // RGB
- if(fread(colorTable, 1, 8, fp) != 8)
+ if(DALI_UNLIKELY(fread(colorTable, 1, 8, fp) != 8))
{
return false;
}
for(std::uint32_t i = 0; i < fillw * height; i += 8)
{
- if(fread(&cmd, 1, 1, fp) != 1)
+ if(DALI_UNLIKELY(fread(&cmd, 1, 1, fp) != 1))
{
return false;
}
unsigned int offset,
bool topDown)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_RGB4 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_RGB4 data\n");
return false;
std::vector<std::uint8_t> colorIndex(fillw * height);
std::uint32_t rowStride = fillw * 3;
- if(fread(colorTable, 1, 64, fp) != 64)
+ if(DALI_UNLIKELY(fread(colorTable, 1, 64, fp) != 64))
{
return false;
}
for(std::uint32_t i = 0; i < fillw * height; i += 2)
{
- if(fread(&cmd, 1, 1, fp) != 1)
+ if(DALI_UNLIKELY(fread(&cmd, 1, 1, fp) != 1))
{
return false;
}
unsigned int offset,
bool topDown)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_RGB8 format\n");
return false;
}
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_RGB8 data\n");
return false;
std::vector<std::uint8_t> colorIndex(width * height);
std::uint32_t rowStride = width * 3; //RGB8->RGB24
- if(fread(&colorTable[0], 1, 1024, fp) != 1024)
+ if(DALI_UNLIKELY(fread(&colorTable[0], 1, 1024, fp) != 1024))
{
return false;
}
- if(fread(&colorIndex[0], 1, width * height, fp) != width * height)
+ if(DALI_UNLIKELY(fread(&colorIndex[0], 1, width * height, fp) != width * height))
{
return false;
}
unsigned int offset,
bool topDown)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_RLE4 format\n");
return false;
bool finish = false;
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_RLE4 data\n");
return false;
}
- if(fread(colorTable, 1, 64, fp) != 64)
+ if(DALI_UNLIKELY(fread(colorTable, 1, 64, fp) != 64))
{
return false;
}
{
break;
}
- if(fread(cmd, 1, cmdStride, fp) != cmdStride)
+ if(DALI_UNLIKELY(fread(cmd, 1, cmdStride, fp) != cmdStride))
{
return false;
}
y++;
break;
case 2: // delta
- if(fread(cmd, 1, cmdStride, fp) != cmdStride)
+ if(DALI_UNLIKELY(fread(cmd, 1, cmdStride, fp) != cmdStride))
{
DALI_LOG_ERROR("Error reading the BMP image\n");
return false;
bytesize >>= 1;
bytesize += (bytesize & 1);
run.resize(bytesize);
- if(fread(&run[0], 1, bytesize, fp) != bytesize)
+ if(DALI_UNLIKELY(fread(&run[0], 1, bytesize, fp) != bytesize))
{
DALI_LOG_ERROR("Error reading the BMP image\n");
return false;
unsigned int offset,
bool topDown)
{
- if(fp == NULL || pixels == NULL)
+ if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
{
DALI_LOG_ERROR("Error decoding BMP_RLE8 format\n");
return false;
std::uint8_t cmd[2];
std::vector<std::uint8_t> colorIndex(width * height);
- if(fseek(fp, offset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking BMP_RLE8 data\n");
return false;
}
- if(fread(&colorTable[0], 1, 1024, fp) != 1024)
+ if(DALI_UNLIKELY(fread(&colorTable[0], 1, 1024, fp) != 1024))
{
return false;
}
std::vector<std::uint8_t> run;
while((x + y * width) < width * height)
{
- if(finish)
+ if(DALI_UNLIKELY(finish))
{
break;
}
- if(fread(cmd, 1, cmdStride, fp) != cmdStride)
+ if(DALI_UNLIKELY(fread(cmd, 1, cmdStride, fp) != cmdStride))
{
return false;
}
y++;
break;
case 2: // delta
- if(fread(cmd, 1, cmdStride, fp) != cmdStride)
+ if(DALI_UNLIKELY(fread(cmd, 1, cmdStride, fp) != cmdStride))
{
DALI_LOG_ERROR("Error reading the BMP image\n");
return false;
//absolute mode must be word-aligned
length += (length & 1);
run.resize(length);
- if(fread(&run[0], 1, length, fp) != length)
+ if(DALI_UNLIKELY(fread(&run[0], 1, length, fp) != length))
{
DALI_LOG_ERROR("Error reading the BMP image\n");
return false;
{
//DALI_ASSERT_DEBUG( bitmap.GetPackedPixelsProfile() != 0 && "Need a packed pixel bitmap to load into." );
FILE* const fp = input.file;
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
DALI_LOG_ERROR("Error loading bitmap\n");
return false;
// Load the header info
unsigned int width, height;
- if(!LoadBmpHeader(fp, width, height, fileHeader, infoHeader))
+ if(DALI_UNLIKELY(!LoadBmpHeader(fp, width, height, fileHeader, infoHeader)))
{
return false;
}
{
if(infoHeader.bitsPerPixel == 16)
{
- if(fseek(fp, 14 + infoHeader.infoHeaderSize + 1, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, 14 + infoHeader.infoHeaderSize + 1, SEEK_SET)))
{
return false;
}
char mask;
- if(fread(&mask, 1, 1, fp) != 1)
+ if(DALI_UNLIKELY(fread(&mask, 1, 1, fp) != 1))
{
return false;
}
pixelsIterator = pixels + (((height - 1) - yPos) * rowStride);
}
- if(fread(pixelsIterator, 1, rowStride, fp) != rowStride)
+ if(DALI_UNLIKELY(fread(pixelsIterator, 1, rowStride, fp) != rowStride))
{
DALI_LOG_ERROR("Error reading the BMP image\n");
break;
if(padding)
{
- if(fseek(fp, padding, SEEK_CUR)) // move past the padding.
+ if(DALI_UNLIKELY(fseek(fp, padding, SEEK_CUR))) // move past the padding.
{
DALI_LOG_ERROR("Error moving past BMP padding\n");
}
}
} // switch
- if(!decodeResult)
+ if(DALI_UNLIKELY(!decodeResult))
{
DALI_LOG_ERROR("Decoding failed\n");
return false;
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
*gifInfo = DGifOpen(reinterpret_cast<void*>(fp), ReadDataFromGif);
#endif
- if(!(*gifInfo) || errorCode)
+ if(DALI_UNLIKELY(!(*gifInfo) || errorCode))
{
DALI_LOG_ERROR("GIF Loader: DGifOpen Error. Code: %d\n", errorCode);
return false;
height = (*gifInfo)->SHeight;
// No proper size in GIF.
- if(width <= 0 || height <= 0)
+ if(DALI_UNLIKELY(width <= 0 || height <= 0))
{
return false;
}
for(unsigned int currentByte = interlacePairPtr->startingByte; currentByte < height; currentByte += interlacePairPtr->incrementalByte)
{
unsigned char* row = decodedData + currentByte * bytesPerRow;
- if(DGifGetLine(gifInfo, row, width) == GIF_ERROR)
+ if(DALI_UNLIKELY(DGifGetLine(gifInfo, row, width) == GIF_ERROR))
{
DALI_LOG_ERROR("GIF Loader: Error reading Interlaced GIF\n");
return false;
for(unsigned int row = 0; row < height; ++row)
{
- if(DGifGetLine(gifInfo, decodedDataPtr, width) == GIF_ERROR)
+ if(DALI_UNLIKELY(DGifGetLine(gifInfo, decodedDataPtr, width) == GIF_ERROR))
{
DALI_LOG_ERROR("GIF Loader: Error reading non-interlaced GIF\n");
return false;
/// Called when we want to handle IMAGE_DESC_RECORD_TYPE
bool HandleImageDescriptionRecordType(Dali::Devel::PixelBuffer& bitmap, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished)
{
- if(DGifGetImageDesc(gifInfo) == GIF_ERROR)
+ if(DALI_UNLIKELY(DGifGetImageDesc(gifInfo) == GIF_ERROR))
{
DALI_LOG_ERROR("GIF Loader: Error getting Image Description\n");
return false;
}
// Ensure there is at least 1 image in the GIF.
- if(gifInfo->ImageCount < 1)
+ if(DALI_UNLIKELY(gifInfo->ImageCount < 1))
{
DALI_LOG_ERROR("GIF Loader: No Images\n");
return false;
bitmap = Dali::Devel::PixelBuffer::New(actualWidth, actualHeight, pixelFormat);
// Decode the GIF Image
- if(!DecodeImage(gifInfo, decodedData, actualWidth, actualHeight, bytesPerRow))
+ if(DALI_UNLIKELY(!DecodeImage(gifInfo, decodedData, actualWidth, actualHeight, bytesPerRow)))
{
return false;
}
extensionByte != NULL;
extRetCode = DGifGetExtensionNext(gifInfo, &extensionByte))
{
- if(extRetCode == GIF_ERROR)
+ if(DALI_UNLIKELY(extRetCode == GIF_ERROR))
{
DALI_LOG_ERROR("GIF Loader: Error reading GIF Extension record.\n");
return false;
GifFileType* gifInfo(NULL);
unsigned int width(0);
unsigned int height(0);
- if(!LoadGifHeader(fp, width, height, &gifInfo))
+ if(DALI_UNLIKELY(!LoadGifHeader(fp, width, height, &gifInfo)))
{
return false;
}
!finished && recordType != TERMINATE_RECORD_TYPE;
returnCode = DGifGetRecordType(gifInfo, &recordType))
{
- if(returnCode == GIF_ERROR)
+ if(DALI_UNLIKELY(returnCode == GIF_ERROR))
{
DALI_LOG_ERROR("GIF Loader: Error getting Record Type\n");
return false;
if(IMAGE_DESC_RECORD_TYPE == recordType)
{
- if(!HandleImageDescriptionRecordType(bitmap, gifInfo, width, height, finished))
+ if(DALI_UNLIKELY(!HandleImageDescriptionRecordType(bitmap, gifInfo, width, height, finished)))
{
return false;
}
}
else if(EXTENSION_RECORD_TYPE == recordType)
{
- if(!HandleExtensionRecordType(gifInfo))
+ if(DALI_UNLIKELY(!HandleExtensionRecordType(gifInfo)))
{
return false;
}
#define ARGB_JOIN(a, r, g, b) \
(((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
-bool read_ushort(unsigned char* map, size_t length, size_t* position, unsigned short* ret)
+bool read_ushort(const unsigned char* const& map, size_t length, size_t* position, unsigned short* ret)
{
unsigned char b[2];
- if(*position + 2 > length)
+ if(DALI_UNLIKELY(*position + 2 > length))
{
return false;
}
return true;
}
-bool read_uint(unsigned char* map, size_t length, size_t* position, unsigned int* ret)
+bool read_uint(const unsigned char* const& map, size_t length, size_t* position, unsigned int* ret)
{
unsigned char b[4];
unsigned int i;
- if(*position + 4 > length)
+ if(DALI_UNLIKELY(*position + 4 > length))
{
return false;
}
return true;
}
-bool read_uchar(unsigned char* map, size_t length, size_t* position, unsigned char* ret)
+bool read_uchar(const unsigned char* const& map, size_t length, size_t* position, unsigned char* ret)
{
- if(*position + 1 > length)
+ if(DALI_UNLIKELY(*position + 1 > length))
{
return false;
}
return true;
}
-bool read_mem(unsigned char* map, size_t length, size_t* position, void* buffer, int size)
+bool read_mem(const unsigned char* const& map, size_t length, size_t* position, void* buffer, int size)
{
- if(*position + size > length)
+ if(DALI_UNLIKELY(*position + size > length))
{
return false;
}
{
memset(&chosen, 0, sizeof(chosen));
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
DALI_LOG_ERROR("Error loading bitmap\n");
return false;
unsigned short word;
unsigned char byte;
- if(fseek(fp, 0, SEEK_END))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END)))
{
DALI_LOG_ERROR("Error seeking ICO data\n");
return false;
fsize = static_cast<unsigned int>(positionIndicator);
}
- if(0u == fsize)
+ if(DALI_UNLIKELY(0u == fsize))
{
return false;
}
- if(fseek(fp, 0, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking ICO data\n");
return false;
}
- if(fsize < (ICO_FILE_HEADER + ICO_IMAGE_INFO_HEADER)) //6 + 16 + 40
+ if(DALI_UNLIKELY(fsize < (ICO_FILE_HEADER + ICO_IMAGE_INFO_HEADER))) //6 + 16 + 40
{
return false;
}
map.ResizeUninitialized(fsize);
-
- if(fread(&map[0], 1, fsize, fp) != fsize)
+ if(DALI_UNLIKELY(fread(&map[0], 1, fsize, fp) != fsize))
{
DALI_LOG_WARNING("image file read opeation error!\n");
return false;
}
+ const std::uint8_t* const inputBufferPtr = &map[0];
+
int search = BIGGEST;
unsigned short reserved, type, count;
- if(!read_ushort(&map[0], fsize, &position, &reserved))
+ if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &reserved)))
{
return false;
}
- if(!read_ushort(&map[0], fsize, &position, &type))
+ if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &type)))
{
return false;
}
- if(!read_ushort(&map[0], fsize, &position, &count))
+ if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &count)))
{
return false;
}
- if(!((reserved == 0) &&
- ((type == ICON) || (type == CURSOR)) && (count != 0)))
+ if(DALI_UNLIKELY(!((reserved == 0) &&
+ ((type == ICON) || (type == CURSOR)) && (count != 0))))
{
return false;
}
for(unsigned short i = 0; i < count; i++)
{
unsigned char tw = 0, th = 0, tcols = 0;
- if(!read_uchar(&map[0], fsize, &position, &tw))
+ if(DALI_UNLIKELY(!read_uchar(inputBufferPtr, fsize, &position, &tw)))
{
return false;
}
{
w = 256;
}
- if(!read_uchar(&map[0], fsize, &position, &th))
+ if(DALI_UNLIKELY(!read_uchar(inputBufferPtr, fsize, &position, &th)))
{
return false;
}
{
h = 256;
}
- if(!read_uchar(&map[0], fsize, &position, &tcols))
+ if(DALI_UNLIKELY(!read_uchar(inputBufferPtr, fsize, &position, &tcols)))
{
return false;
}
int cols = tcols;
- if(!read_uchar(&map[0], fsize, &position, &byte))
+ if(DALI_UNLIKELY(!read_uchar(inputBufferPtr, fsize, &position, &byte)))
{
return false;
}
- if(!read_ushort(&map[0], fsize, &position, &word))
+ if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &word)))
{
return false;
}
planes = word;
}
//else hot_x = word;
- if(!read_ushort(&map[0], fsize, &position, &word))
+ if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &word)))
{
return false;
}
//else hot_y = word;
unsigned int bmoffset, bmsize;
- if(!read_uint(&map[0], fsize, &position, &bmsize))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &bmsize)))
{
return false;
}
- if(!read_uint(&map[0], fsize, &position, &bmoffset))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &bmoffset)))
{
return false;
}
- if((bmsize <= 0) || (bmoffset <= 0) || (bmoffset >= fsize))
+ if(DALI_UNLIKELY((bmsize <= 0) || (bmoffset <= 0) || (bmoffset >= fsize)))
{
return false;
}
}
}
- if(chosen.bmoffset == 0)
+ if(DALI_UNLIKELY(chosen.bmoffset == 0))
{
return false;
}
/**
* @brief Handle the different bits per pixel
* @param[in] bitcount The bit count
- * @param[in/out] map The map to use/set
+ * @param[in] inputBufferPtr The map to use
* @param[in/out] pix A reference to the pointer to the pix buffer
- * @param[in/out] surface A reference to the surface buffer
+ * @param[in/out] outputBufferPtr A reference to the surface buffer
* @param[in] width The width
* @param[in] height The height
* @param[in] fsize The file size
*/
bool HandleBitsPerPixel(
const unsigned int bitcount,
- Dali::Vector<unsigned char>& map,
+ const std::uint8_t* const& inputBufferPtr,
unsigned int*& pix,
- Dali::Vector<unsigned int>& surface,
+ std::uint32_t* const& outputBufferPtr,
const unsigned int width,
const unsigned int height,
const unsigned int fsize,
size_t& position,
- Dali::Vector<unsigned char>& pixbuf,
const unsigned int stride,
const Dali::Vector<unsigned int>& palette)
{
+ // Pixbuf only ever contains one scanline worth of data.
+ Dali::Vector<std::uint8_t> pixbuf;
+ pixbuf.ResizeUninitialized(stride);
+ std::uint8_t* lineBufferPtr = &pixbuf[0];
+
// Note: Switch is in order of most common format first.
switch(bitcount)
{
case 32:
{
- unsigned char* p = &map[position];
- pix = &surface[0] + ((height - 1) * width);
+ const std::uint8_t* p = inputBufferPtr + position;
+ pix = outputBufferPtr + ((height - 1) * width);
for(unsigned int i = 0; i < height; i++)
{
{
for(unsigned int i = 0; i < height; i++)
{
- pix = &surface[0] + ((height - 1 - i) * width);
- if(!read_mem(&map[0], fsize, &position, &pixbuf[0], stride))
+ pix = outputBufferPtr + ((height - 1 - i) * width);
+ if(DALI_UNLIKELY(!read_mem(inputBufferPtr, fsize, &position, lineBufferPtr, stride)))
{
return false;
}
- unsigned char* p = &pixbuf[0];
+ const std::uint8_t* p = lineBufferPtr;
for(unsigned int j = 0; j < width; j++)
{
*pix++ = ARGB_JOIN(0xff, p[0], p[1], p[2]);
{
for(unsigned int i = 0; i < height; i++)
{
- pix = &surface[0] + ((height - 1 - i) * width);
- if(!read_mem(&map[0], fsize, &position, &pixbuf[0], stride))
+ pix = outputBufferPtr + ((height - 1 - i) * width);
+ if(DALI_UNLIKELY(!read_mem(inputBufferPtr, fsize, &position, lineBufferPtr, stride)))
{
return false;
}
- unsigned char* p = &pixbuf[0];
+ const std::uint8_t* p = lineBufferPtr;
for(unsigned int j = 0; j < width; j++)
{
*pix++ = palette[*p++];
{
for(unsigned int i = 0; i < height; i++)
{
- pix = &surface[0] + ((height - 1 - i) * width);
- if(!read_mem(&map[0], fsize, &position, &pixbuf[0], stride))
+ pix = outputBufferPtr + ((height - 1 - i) * width);
+ if(DALI_UNLIKELY(!read_mem(inputBufferPtr, fsize, &position, lineBufferPtr, stride)))
{
return false;
}
- unsigned char* p = &pixbuf[0];
+ const std::uint8_t* p = lineBufferPtr;
for(unsigned int j = 0; j < width; j++)
{
if(j & 0x1)
case 1:
{
+ const std::uint32_t bytesPerWidth = width / 8;
+ const std::uint32_t bytesRemainingPerWidth = width & 7;
for(unsigned int i = 0; i < height; i++)
{
- pix = &surface[0] + ((height - 1 - i) * width);
- if(!read_mem(&map[0], fsize, &position, &pixbuf[0], stride))
+ pix = outputBufferPtr + ((height - 1 - i) * width);
+ if(DALI_UNLIKELY(!read_mem(inputBufferPtr, fsize, &position, lineBufferPtr, stride)))
{
return false;
}
- unsigned char* p = &pixbuf[0];
- for(unsigned int j = 0; j < width; j += 8)
+ const std::uint8_t* p = lineBufferPtr;
+ for(unsigned int j = 0; j < bytesPerWidth; ++j)
{
*pix++ = palette[*p >> 7];
*pix++ = palette[*p >> 6 & 0x01];
*pix++ = palette[*p >> 1 & 0x01];
*pix++ = palette[*p >> 0 & 0x01];
- p++;
+ ++p;
+ }
+ if(bytesRemainingPerWidth > 0)
+ {
+ for(std::uint32_t j = 0; j < bytesRemainingPerWidth; ++j)
+ {
+ *pix++ = palette[(*p >> (7 - j)) & 0x01];
+ }
+ ++p;
}
}
break;
/**
* @brief Apply the mask if required
- * @param[in/out] map The map to use/set
+ * @param[in] inputBufferPtr The map to use
* @param[in] fsize The file size
* @param[in/out] position The position in the file
- * @param[in//out] maskbuf The mask buffer
* @param[in] bitStride The stride
* @param[in] width The width
* @param[in] height The height
* @param[in/out] pix A reference to the pointer to the pix buffer
- * @param[in/out] surface A reference to the surface buffer
+ * @param[in/out] outputBufferPtr A reference to the surface buffer
*/
bool ApplyMask(
- Dali::Vector<unsigned char>& map,
- const unsigned int fsize,
- size_t& position,
- Dali::Vector<unsigned char>& maskbuf,
- const unsigned int bitStride,
- const unsigned int width,
- const unsigned int height,
- unsigned int*& pix,
- Dali::Vector<unsigned int>& surface)
+ const std::uint8_t* const& inputBufferPtr,
+ const unsigned int fsize,
+ size_t& position,
+ const unsigned int bitStride,
+ const unsigned int width,
+ const unsigned int height,
+ unsigned int*& pix,
+ std::uint32_t* const& outputBufferPtr)
{
- if(!read_mem(&map[0], fsize, &position, &maskbuf[0], bitStride * height))
- {
- return false;
- }
+ Dali::Vector<std::uint8_t> maskbuf;
+ maskbuf.ResizeUninitialized(bitStride);
+ std::uint8_t* lineBufferPtr = &maskbuf[0];
// Apply mask.
// Precalc to save time in the loops.
// Loop for each line of the image.
for(unsigned int i = 0; i < height; ++i)
{
- unsigned char* m = &maskbuf[0] + (bitStride * i);
- pix = &surface[0] + ((height - 1 - i) * width);
+ pix = outputBufferPtr + ((height - 1 - i) * width);
+ if(DALI_UNLIKELY(!read_mem(inputBufferPtr, fsize, &position, lineBufferPtr, bitStride)))
+ {
+ return false;
+ }
+ const std::uint8_t* m = lineBufferPtr;
// Do chunks of 8 pixels first so mask operations can be unrolled.
for(unsigned int j = 0; j < bytesPerWidth; ++j)
unsigned int fsize;
FILE* const fp = input.file;
- if(false == LoadIcoHeaderHelper(fp, chosen, map, fsize))
+ if(DALI_UNLIKELY(false == LoadIcoHeaderHelper(fp, chosen, map, fsize)))
{
return false;
}
unsigned int fsize;
FILE* const fp = input.file;
- if(false == LoadIcoHeaderHelper(fp, chosen, map, fsize))
+ if(DALI_UNLIKELY(false == LoadIcoHeaderHelper(fp, chosen, map, fsize)))
{
return false;
}
- Dali::Vector<unsigned int> pal;
- Dali::Vector<unsigned int> surface;
- Dali::Vector<unsigned char> maskbuf;
- Dali::Vector<unsigned char> pixbuf;
- pal.Resize(256 * 4);
-
unsigned int dword;
unsigned short word;
unsigned int h = chosen.h;
unsigned int cols = chosen.cols;
+ const std::uint8_t* const inputBufferPtr = &map[0];
+
// read bmp header time... let's do some checking
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // headersize - dont care
}
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // width
}
diff_size = 1;
}
}
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // height
}
DALI_LOG_WARNING("Broken ICO file!\n");
}
- // Set up the surface as soon as we have the width and height, so we have a black image if there are any further errors.
- surface.ResizeUninitialized(w * h * 4);
- memset(&surface[0], 0, w * h * 4);
-
- if(!read_ushort(&map[0], fsize, &position, &word))
+ if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &word)))
{
return false; // planes
}
//planes2 = word;
- if(!read_ushort(&map[0], fsize, &position, &word))
+ if(DALI_UNLIKELY(!read_ushort(inputBufferPtr, fsize, &position, &word)))
{
return false; // bitcount
}
unsigned int bitcount = word;
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // compression
}
//compression = dword;
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // imagesize
}
//imagesize = dword;
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // z pixels per m
}
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // y pizels per m
}
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // colors used
}
//colorsused = dword;
- if(!read_uint(&map[0], fsize, &position, &dword))
+ if(DALI_UNLIKELY(!read_uint(inputBufferPtr, fsize, &position, &dword)))
{
return false; // colors important
}
+ Dali::Vector<unsigned int> pal;
+ pal.Resize(256 * 4);
for(unsigned int i = 0; i < cols; i++)
{
unsigned char a, r, g, b;
- if(!read_uchar(&map[0], fsize, &position, &b))
+ if(DALI_UNLIKELY(!read_uchar(inputBufferPtr, fsize, &position, &b)))
{
return false;
}
- if(!read_uchar(&map[0], fsize, &position, &g))
+ if(DALI_UNLIKELY(!read_uchar(inputBufferPtr, fsize, &position, &g)))
{
return false;
}
- if(!read_uchar(&map[0], fsize, &position, &r))
+ if(DALI_UNLIKELY(!read_uchar(inputBufferPtr, fsize, &position, &r)))
{
return false;
}
- if(!read_uchar(&map[0], fsize, &position, &a))
+ if(DALI_UNLIKELY(!read_uchar(inputBufferPtr, fsize, &position, &a)))
{
return false;
}
pal[i] = ARGB_JOIN(0xff, b, g, r);
}
+ Dali::Vector<std::uint32_t> surface;
+
// This is the reference way of calculating the total number of bytes necessary to store one row of pixels.
unsigned int stride = (((bitcount * w) + 31) / 32) * 4;
unsigned int bitStride = ((w + 31) / 32) * 4;
+ // Set up the surface as soon as we have the width and height.
+ surface.ResizeUninitialized(w * h);
- // Pixbuf only ever contains one scanline worth of data.
- pixbuf.ResizeUninitialized(stride);
- maskbuf.ResizeUninitialized(bitStride * h);
+ std::uint32_t* const outputBufferPtr = &surface[0];
// Handle different bits-per-pixel.
- if(!HandleBitsPerPixel(bitcount, map, pix, surface, w, h, fsize, position, pixbuf, stride, pal))
+ if(DALI_UNLIKELY(!HandleBitsPerPixel(bitcount, inputBufferPtr, pix, outputBufferPtr, w, h, fsize, position, stride, pal)))
{
return false;
}
// From the spec: If bpp is less than 32, there will be a 1bpp mask bitmap also.
- if((bitcount < 32) && !ApplyMask(map, fsize, position, maskbuf, bitStride, w, h, pix, surface))
+ if(bitcount < 32)
{
- // Return false if not able to apply mask when the bpp is less than 32
- return false;
+ if(DALI_UNLIKELY(!ApplyMask(inputBufferPtr, fsize, position, bitStride, w, h, pix, outputBufferPtr)))
+ {
+ // Return false if not able to apply mask when the bpp is less than 32
+ return false;
+ }
}
bitmap = Dali::Devel::PixelBuffer::New(w, h, Pixel::Format::RGBA8888);
auto pixels = bitmap.GetBuffer();
- memcpy(pixels, &surface[0], w * h * 4);
+ memcpy(pixels, outputBufferPtr, w * h * 4);
return true;
}
// On error exit from the JPEG lib, control will pass via JpegErrorHandler
// into this branch body for cleanup and error return:
- if(setjmp(jerr.jumpBuffer))
+ if(DALI_UNLIKELY(setjmp(jerr.jumpBuffer)))
{
DALI_LOG_ERROR("setjmp failed\n");
jpeg_destroy_decompress(&cinfo);
jpeg_stdio_src(&cinfo, fp);
// Check header to see if it is JPEG file
- if(jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK)
+ if(DALI_UNLIKELY(jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK))
{
DALI_LOG_ERROR("jpeg_read_header failed\n");
width = height = 0;
const int flags = 0;
FILE* const fp = input.file;
- if(fseek(fp, 0, SEEK_END))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END)))
{
DALI_LOG_ERROR("Error seeking to end of file\n");
return false;
jpegBufferSize = static_cast<unsigned int>(positionIndicator);
}
- if(0u == jpegBufferSize)
+ if(DALI_UNLIKELY(0u == jpegBufferSize))
{
DALI_LOG_ERROR("Jpeg buffer size error\n");
return false;
}
- if(fseek(fp, 0, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking to start of file\n");
return false;
unsigned char* const jpegBufferPtr = jpegBuffer.Begin();
// Pull the compressed JPEG image bytes out of a file and into memory:
- if(fread(jpegBufferPtr, 1, jpegBufferSize, fp) != jpegBufferSize)
+ if(DALI_UNLIKELY(fread(jpegBufferPtr, 1, jpegBufferSize, fp) != jpegBufferSize))
{
DALI_LOG_ERROR("Error on image file read.\n");
return false;
}
- if(fseek(fp, 0, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking to start of file\n");
+ return false;
}
auto jpeg = MakeJpegDecompressor();
- if(!jpeg)
+ if(DALI_UNLIKELY(!jpeg))
{
DALI_LOG_ERROR("%s\n", tjGetErrorStr());
return false;
}
#endif
- if(preXformImageWidth == 0 || preXformImageHeight == 0)
+ if(DALI_UNLIKELY(preXformImageWidth == 0 || preXformImageHeight == 0))
{
DALI_LOG_ERROR("Invalid Image!\n");
return false;
{
std::string errorString = tjGetErrorStr();
- if(IsJpegErrorFatal(errorString))
+ if(DALI_UNLIKELY(IsJpegErrorFatal(errorString)))
{
DALI_LOG_ERROR("%s\n", errorString.c_str());
return false;
// Initialise a JPEG codec:
{
auto jpeg = MakeJpegCompressor();
- if(!jpeg)
+ if(DALI_UNLIKELY(!jpeg))
{
DALI_LOG_ERROR("JPEG Compressor init failed: %s\n", tjGetErrorStr());
return false;
unsigned long dstBufferSize = 0;
const int flags = 0;
- if(tjCompress2(jpeg.get(),
- const_cast<unsigned char*>(pixelBuffer),
- width,
- 0,
- height,
- jpegPixelFormat,
- SetPointer(dstBuffer),
- &dstBufferSize,
- TJSAMP_444,
- quality,
- flags))
+ if(DALI_UNLIKELY(tjCompress2(jpeg.get(),
+ const_cast<unsigned char*>(pixelBuffer),
+ width,
+ 0,
+ height,
+ jpegPixelFormat,
+ SetPointer(dstBuffer),
+ &dstBufferSize,
+ TJSAMP_444,
+ quality,
+ flags)))
{
DALI_LOG_ERROR("JPEG Compression failed: %s\n", tjGetErrorStr());
return false;
int numFactors = 0;
tjscalingfactor* factors = tjGetScalingFactors(&numFactors);
- if(factors == NULL)
+ if(DALI_UNLIKELY(factors == NULL))
{
DALI_LOG_WARNING("TurboJpeg tjGetScalingFactors error!\n");
success = false;
auto exifData = MakeNullExifData();
unsigned char dataBuffer[1024];
- if(fseek(fp, 0, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking to start of file\n");
}
unsigned int headerHeight;
success = LoadJpegHeader(fp, headerWidth, headerHeight);
- if(success)
+ if(DALI_LIKELY(success))
{
auto transform = JpegTransform::NONE;
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
const unsigned int readLength = sizeof(KtxFileHeader);
// Load the information directly into our structure
- if(fread(&header, 1, readLength, filePointer) != readLength)
+ if(DALI_UNLIKELY(fread(&header, 1, readLength, filePointer) != readLength))
{
return false;
}
bool LoadKtxHeader(FILE* const fp, unsigned int& width, unsigned int& height, KtxFileHeader& fileHeader)
{
// Pull the bytes of the file header in as a block:
- if(!ReadHeader(fp, fileHeader))
+ if(DALI_UNLIKELY(!ReadHeader(fp, fileHeader)))
{
return false;
}
width = fileHeader.pixelWidth;
height = fileHeader.pixelHeight;
- if(width > MAX_TEXTURE_DIMENSION || height > MAX_TEXTURE_DIMENSION)
+ if(DALI_UNLIKELY(width > MAX_TEXTURE_DIMENSION || height > MAX_TEXTURE_DIMENSION))
{
return false;
}
static_assert(sizeof(uint32_t) == 4);
FILE* const fp = input.file;
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
DALI_LOG_ERROR("Null file handle passed to KTX compressed bitmap file loader.\n");
return false;
// Load the header info
unsigned int width, height;
- if(!LoadKtxHeader(fp, width, height, fileHeader))
+ if(DALI_UNLIKELY(!LoadKtxHeader(fp, width, height, fileHeader)))
{
return false;
}
// Skip the key-values:
const long int imageSizeOffset = sizeof(KtxFileHeader) + fileHeader.bytesOfKeyValueData;
- if(fseek(fp, imageSizeOffset, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, imageSizeOffset, SEEK_SET)))
{
DALI_LOG_ERROR("Seek past key/vals in KTX compressed bitmap file failed.\n");
return false;
// Load the size of the image data:
uint32_t imageByteCount = 0;
- if(fread(&imageByteCount, 1, 4, fp) != 4)
+ if(DALI_UNLIKELY(fread(&imageByteCount, 1, 4, fp) != 4))
{
DALI_LOG_ERROR("Read of image size failed.\n");
return false;
}
// Sanity-check the image size:
- if(imageByteCount > MAX_IMAGE_DATA_SIZE ||
- // A compressed texture should certainly be less than 2 bytes per texel:
- imageByteCount > width * height * 2)
+ if(DALI_UNLIKELY(imageByteCount > MAX_IMAGE_DATA_SIZE ||
+ // A compressed texture should certainly be less than 2 bytes per texel:
+ imageByteCount > width * height * 2))
{
DALI_LOG_ERROR("KTX file with too-large image-data field.\n");
return false;
Pixel::Format pixelFormat;
const bool pixelFormatKnown = ConvertPixelFormat(fileHeader.glInternalFormat, pixelFormat);
- if(!pixelFormatKnown)
+ if(DALI_UNLIKELY(!pixelFormatKnown))
{
DALI_LOG_ERROR("No internal pixel format supported for KTX file pixel format.\n");
return false;
pixels = bitmap.GetBuffer();
}
- if(!pixels)
+ if(DALI_UNLIKELY(!pixels))
{
DALI_LOG_ERROR("Unable to reserve a pixel buffer to load the requested bitmap into.\n");
return false;
}
const size_t bytesRead = fread(pixels, 1, imageByteCount, fp);
- if(bytesRead != imageByteCount)
+ if(DALI_UNLIKELY(bytesRead != imageByteCount))
{
DALI_LOG_ERROR("Read of image pixel data failed.\n");
return false;
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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;
break;
}
}
-
- // decode the whole image into bitmap buffer
- auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer();
-
- DALI_ASSERT_DEBUG(pixels);
rows = reinterpret_cast<png_bytep*>(malloc(sizeof(png_bytep) * height));
- if(!rows)
+ if(DALI_UNLIKELY(!rows))
{
DALI_LOG_ERROR("malloc is failed\n");
return false;
}
+ // decode the whole image into bitmap buffer
+ auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer();
+
+ DALI_ASSERT_DEBUG(pixels);
+
for(y = 0; y < height; y++)
{
rows[y] = pixels + y * stride;
((1ULL << (29)) - 2048))
//extract multiple bytes integer , and saved in *data
-int extractMultiByteInteger(unsigned int* data, void* map, size_t length, size_t* position)
+int extractMultiByteInteger(unsigned int* data, const std::uint8_t* const& map, size_t length, size_t* position)
{
// the header field contains an image type indentifier of multi-byte length(TypeField), an octet of general header info(FixHeaderField)
//, a multi-byte width field(Width) and a multi-byte height field(Height) and so on.
// for general width and height, if(buf & 0x80) == 0, then the next byte does not need to fetch again
// first step, readBufCount = 1 , read int(4 bytes) to buf, if buf & 0x80 !=0, the buf need to continue to fetch
// second step, readBufCount = 2, read next( 4 bytes) to buf, if buf & 0x80 == 0, then assigned the buf to target
- if((readBufCount++) == 4)
+ if(DALI_UNLIKELY((readBufCount++) == 4))
{
return -1;
}
- if(*position > length)
+ if(DALI_UNLIKELY(*position > length))
{
return -1;
}
- buf = reinterpret_cast<unsigned char*>(map)[(*position)++];
+ buf = map[(*position)++];
targetMultiByteInteger = (targetMultiByteInteger << 7) | (buf & 0x7f);
if((buf & 0x80) == 0)
bool LoadBitmapFromWbmp(const Dali::ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap)
{
FILE* const fp = input.file;
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
DALI_LOG_ERROR("Error loading bitmap\n");
return false;
std::uint32_t type;
std::uint32_t lineByteLength;
- if(fseek(fp, 0, SEEK_END))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END)))
{
DALI_LOG_ERROR("Error seeking WBMP data\n");
return false;
fsize = static_cast<unsigned int>(positionIndicator);
}
- if(0u == fsize)
+ if(DALI_UNLIKELY(0u == fsize))
{
DALI_LOG_ERROR("Error: filesize is 0!\n");
return false;
}
- if(fseek(fp, 0, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking WBMP data\n");
return false;
}
- if(fsize <= 4)
+ if(DALI_UNLIKELY(fsize <= 4))
{
DALI_LOG_ERROR("Error: WBMP Raw Data Not Found!\n");
return false;
}
- if(fsize > 4096 * 4096 * 4)
+ if(DALI_UNLIKELY(fsize > 4096 * 4096 * 4))
{
DALI_LOG_ERROR("Error: WBMP size is too large!\n");
return false;
}
map.ResizeUninitialized(fsize);
- if(fread(&map[0], 1, fsize, fp) != fsize)
+ if(DALI_UNLIKELY(fread(&map[0], 1, fsize, fp) != fsize))
{
DALI_LOG_WARNING("image file read opeation error!\n");
return false;
}
- if(extractMultiByteInteger(&type, &map[0], fsize, &position) < 0)
+ const std::uint8_t* const inputBufferPtr = &map[0];
+
+ if(DALI_UNLIKELY(extractMultiByteInteger(&type, inputBufferPtr, fsize, &position) < 0))
{
return false;
}
position++; /* skipping one byte */
- if(extractMultiByteInteger(&w, &map[0], fsize, &position) < 0)
+ if(DALI_UNLIKELY(extractMultiByteInteger(&w, inputBufferPtr, fsize, &position) < 0))
{
return false;
}
- if(extractMultiByteInteger(&h, &map[0], fsize, &position) < 0)
+ if(DALI_UNLIKELY(extractMultiByteInteger(&h, inputBufferPtr, fsize, &position) < 0))
{
return false;
}
- if(type != 0)
+ if(DALI_UNLIKELY(type != 0))
{
DALI_LOG_ERROR("Unknown Format!\n");
return false;
}
- if((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
+ if(DALI_UNLIKELY((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE)))
{
return false;
}
// w >= 1 and h >= 1. So we can assume that outputPixels is not null.
auto outputPixels = (bitmap = Dali::Devel::PixelBuffer::New(w, h, Pixel::L8)).GetBuffer();
+
/**
* @code
* std::uint8_t* line = NULL;
* @endcode
*/
- const std::uint8_t* inputPixels = &map[0] + position;
+ const std::uint8_t* inputPixels = inputBufferPtr + position;
const std::uint32_t lineByteLengthWithoutPadding = w >> 3;
const std::uint8_t linePadding = w & 0x07;
- for(std::uint32_t y = 0; y < h; y++)
+ for(std::uint32_t y = 0; y < h; ++y)
{
- for(std::uint32_t x = 0; x < lineByteLengthWithoutPadding; x++)
+ for(std::uint32_t x = 0; x < lineByteLengthWithoutPadding; ++x)
{
// memset whole 8 bits
// outputPixels filled 4 bytes in one operation.
bool LoadWbmpHeader(const Dali::ImageLoader::Input& input, unsigned int& width, unsigned int& height)
{
FILE* const fp = input.file;
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
DALI_LOG_ERROR("Error loading bitmap\n");
return false;
unsigned int w, h;
unsigned int type;
- if(fseek(fp, 0, SEEK_END))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END)))
{
DALI_LOG_ERROR("Error seeking WBMP data\n");
return false;
fsize = static_cast<unsigned int>(positionIndicator);
}
- if(0u == fsize)
+ if(DALI_UNLIKELY(0u == fsize))
{
return false;
}
- if(fseek(fp, 0, SEEK_SET))
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_SET)))
{
DALI_LOG_ERROR("Error seeking WBMP data\n");
return false;
}
- if(fsize <= 4)
+ if(DALI_UNLIKELY(fsize <= 4))
{
DALI_LOG_ERROR("Error: WBMP Raw Data Not Found!\n");
return false;
headerSize = std::min(headerSize, fsize);
map.ResizeUninitialized(headerSize);
- if(fread(&map[0], 1, headerSize, fp) != headerSize)
+ if(DALI_UNLIKELY(fread(&map[0], 1, headerSize, fp) != headerSize))
{
DALI_LOG_WARNING("image file read opeation error!\n");
return false;
}
- if(extractMultiByteInteger(&type, &map[0], headerSize, &position) < 0)
+ const std::uint8_t* const inputBufferPtr = &map[0];
+
+ if(DALI_UNLIKELY(extractMultiByteInteger(&type, inputBufferPtr, headerSize, &position) < 0))
{
DALI_LOG_ERROR("Error: unable to read type!\n");
return false;
}
position++; /* skipping one byte */
- if(type != 0)
+ if(DALI_UNLIKELY(type != 0))
{
DALI_LOG_ERROR("Error: unknown format!\n");
return false;
}
- if(extractMultiByteInteger(&w, &map[0], headerSize, &position) < 0)
+ if(DALI_UNLIKELY(extractMultiByteInteger(&w, inputBufferPtr, headerSize, &position) < 0))
{
DALI_LOG_ERROR("Error: can not read width!\n");
return false;
}
- if(extractMultiByteInteger(&h, &map[0], headerSize, &position) < 0)
+ if(DALI_UNLIKELY(extractMultiByteInteger(&h, inputBufferPtr, headerSize, &position) < 0))
{
DALI_LOG_ERROR("Error: can not read height!\n");
return false;
}
- if((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
+ if(DALI_UNLIKELY((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE)))
{
DALI_LOG_ERROR("Error: file size is not supported!\n");
return false;
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
#ifdef DALI_ANIMATED_WEBP_ENABLED
bool ReadWebPInformation(FILE* const fp, WebPData& webPData)
{
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
return false;
}
- if(fseek(fp, 0, SEEK_END) <= -1)
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END) <= -1))
{
return false;
}
WebPDataInit(&webPData);
webPData.size = ftell(fp);
- if((!fseek(fp, 0, SEEK_SET)))
+ if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET)))
{
unsigned char* WebPDataBuffer;
WebPDataBuffer = reinterpret_cast<WebPByteType*>(malloc(sizeof(WebPByteType) * webPData.size));
bool LoadWebpHeader(const Dali::ImageLoader::Input& input, unsigned int& width, unsigned int& height)
{
FILE* const fp = input.file;
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
return false;
}
- if(fseek(fp, 0, SEEK_END) <= -1)
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END) <= -1))
{
return false;
}
// If the image is non-animated webp
#ifdef DALI_WEBP_AVAILABLE
size_t webPSize = ftell(fp);
- if((!fseek(fp, 0, SEEK_SET)))
+ if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET)))
{
std::vector<uint8_t> encodedImage;
- encodedImage.resize(webPSize, 0);
+ encodedImage.resize(webPSize);
size_t readCount = fread(&encodedImage[0], sizeof(uint8_t), encodedImage.size(), fp);
- if(readCount != encodedImage.size())
+ if(DALI_UNLIKELY(readCount != encodedImage.size()))
{
return false;
}
bool LoadBitmapFromWebp(const Dali::ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap)
{
FILE* const fp = input.file;
- if(fp == NULL)
+ if(DALI_UNLIKELY(fp == NULL))
{
return false;
}
- if(fseek(fp, 0, SEEK_END) <= -1)
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END) <= -1))
{
return false;
}
// If the image is non-animated webp
#ifdef DALI_WEBP_AVAILABLE
size_t webPSize = ftell(fp);
- if((!fseek(fp, 0, SEEK_SET)))
+ if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET)))
{
std::vector<uint8_t> encodedImage;
- encodedImage.resize(webPSize, 0);
+ encodedImage.resize(webPSize);
size_t readCount = fread(&encodedImage[0], sizeof(uint8_t), encodedImage.size(), fp);
- if(readCount != encodedImage.size())
+ if(DALI_UNLIKELY(readCount != encodedImage.size()))
{
DALI_LOG_ERROR("WebP image loading failed.\n");
return false;
}
int32_t width, height;
- if(!WebPGetInfo(&encodedImage[0], encodedImage.size(), &width, &height))
+ if(DALI_UNLIKELY(!WebPGetInfo(&encodedImage[0], encodedImage.size(), &width, &height)))
{
DALI_LOG_ERROR("Cannot retrieve WebP image size information.\n");
return false;
}
WebPBitstreamFeatures features;
- if(VP8_STATUS_NOT_ENOUGH_DATA == WebPGetFeatures(&encodedImage[0], encodedImage.size(), &features))
+ if(DALI_UNLIKELY(VP8_STATUS_NOT_ENOUGH_DATA == WebPGetFeatures(&encodedImage[0], encodedImage.size(), &features)))
{
DALI_LOG_ERROR("Cannot retrieve WebP image features.\n");
return false;
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
mLoadSucceeded(true)
{
// mFrameCount will be 1 if the input image is non-animated image or animated image with single frame.
- if(ReadWebPInformation(isLocalResource))
+ if(DALI_LIKELY(ReadWebPInformation(isLocalResource)))
{
#ifdef DALI_ANIMATED_WEBP_ENABLED
WebPDataInit(&mWebPData);
{
Internal::Platform::FileReader fileReader(mUrl);
fp = fileReader.GetFile();
- if(fp == nullptr)
+ if(DALI_UNLIKELY(fp == nullptr))
{
return false;
}
- if(fseek(fp, 0, SEEK_END) <= -1)
+ if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END) <= -1))
{
return false;
}
mBufferSize = ftell(fp);
- if(!fseek(fp, 0, SEEK_SET))
+ if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET)))
{
mBuffer = reinterpret_cast<WebPByteType*>(malloc(sizeof(WebPByteType) * mBufferSize));
mBufferSize = fread(mBuffer, sizeof(WebPByteType), mBufferSize, fp);
size_t dataSize;
succeeded = TizenPlatform::Network::DownloadRemoteFileIntoMemory(mUrl, dataBuffer, dataSize, MAXIMUM_DOWNLOAD_IMAGE_SIZE);
- if(succeeded)
+ if(DALI_LIKELY(succeeded))
{
mBufferSize = dataBuffer.Size();
- if(mBufferSize > 0U)
+ if(DALI_LIKELY(mBufferSize > 0U))
{
// Open a file handle on the memory buffer:
Internal::Platform::FileReader fileReader(dataBuffer, mBufferSize);
fp = fileReader.GetFile();
- if(fp != nullptr)
+ if(DALI_LIKELY(fp != nullptr))
{
- if(!fseek(fp, 0, SEEK_SET))
+ if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET)))
{
mBuffer = reinterpret_cast<WebPByteType*>(malloc(sizeof(WebPByteType) * mBufferSize));
mBufferSize = fread(mBuffer, sizeof(WebPByteType), mBufferSize, fp);
Dali::PixelData imageData = Devel::PixelBuffer::Convert(pixelBuffer);
pixelData.push_back(imageData);
}
- if(pixelData.size() != static_cast<uint32_t>(count))
+ if(DALI_UNLIKELY(pixelData.size() != static_cast<uint32_t>(count)))
{
return false;
}
if(mImpl->mFrameCount == 1)
{
int32_t width, height;
- if(!WebPGetInfo(mImpl->mBuffer, mImpl->mBufferSize, &width, &height))
+ if(DALI_UNLIKELY(!WebPGetInfo(mImpl->mBuffer, mImpl->mBufferSize, &width, &height)))
{
return pixelBuffer;
}
WebPBitstreamFeatures features;
- if(VP8_STATUS_NOT_ENOUGH_DATA == WebPGetFeatures(mImpl->mBuffer, mImpl->mBufferSize, &features))
+ if(DALI_UNLIKELY(VP8_STATUS_NOT_ENOUGH_DATA == WebPGetFeatures(mImpl->mBuffer, mImpl->mBufferSize, &features)))
{
return pixelBuffer;
}
#ifdef DALI_ANIMATED_WEBP_ENABLED
Mutex::ScopedLock lock(mImpl->mMutex);
- if(frameIndex >= mImpl->mWebPAnimInfo.frame_count || !mImpl->mLoadSucceeded)
+ if(DALI_UNLIKELY(frameIndex >= mImpl->mWebPAnimInfo.frame_count || !mImpl->mLoadSucceeded))
{
return pixelBuffer;
}