/*
- * 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;