/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
* @param[out] fileHeader This will be populated with the header data
* @return True if the file is valid, false otherwise
*/
-bool LoadAstcHeader( FILE * const filePointer, unsigned int &width, unsigned int &height, AstcFileHeader &fileHeader )
+bool LoadAstcHeader( FILE * const filePointer, unsigned int& width, unsigned int& height, AstcFileHeader& fileHeader )
{
// Pull the bytes of the file header in as a block:
- unsigned int readLength = sizeof( AstcFileHeader );
- if( fread( (void*)&fileHeader, 1, readLength, filePointer ) != readLength )
+ const unsigned int readLength = sizeof( AstcFileHeader );
+ if( fread( &fileHeader, 1, readLength, filePointer ) != readLength )
{
return false;
}
}
// File loading API entry-point:
-bool LoadBitmapFromAstc( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromAstc( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
FILE* const filePointer = input.file;
if( !filePointer )
}
// Retrieve the file size.
- fseek( filePointer, 0L, SEEK_END );
+ if( fseek( filePointer, 0L, SEEK_END ) )
+ {
+ DALI_LOG_ERROR( "Could not seek through file.\n" );
+ return false;
+ }
+
off_t fileSize = ftell( filePointer );
if( fileSize == -1L )
{
DALI_LOG_ERROR( "Could not determine ASTC file size.\n" );
return false;
}
- fseek( filePointer, sizeof( AstcFileHeader ), SEEK_SET );
+
+ if( fseek( filePointer, sizeof( AstcFileHeader ), SEEK_SET ) )
+ {
+ DALI_LOG_ERROR( "Could not seek through file.\n" );
+ return false;
+ }
// Data size is file size - header size.
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 > ( ( width * height ) << 1 ) ) )
+ if( ( 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;