#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/image-attributes.h>
+
+// We need to check if giflib has the new open and close API (including error parameter).
+#ifdef GIFLIB_MAJOR
+#define LIBGIF_VERSION_5_1_OR_ABOVE
+#endif
namespace Dali
{
if(NULL != gifInfo)
{
// clean up GIF resources
- DGifCloseFile(gifInfo);
+#ifdef LIBGIF_VERSION_5_1_OR_ABOVE
+ int errorCode = 0; //D_GIF_SUCCEEDED is 0
+ DGifCloseFile( gifInfo, &errorCode );
+
+ if( errorCode )
+ {
+ DALI_LOG_ERROR( "GIF Loader: DGifCloseFile Error. Code: %d\n", errorCode );
+ }
+#else
+ DGifCloseFile( gifInfo );
+#endif
}
}
/// Loads the GIF Header.
bool LoadGifHeader(FILE *fp, unsigned int &width, unsigned int &height, GifFileType** gifInfo)
{
- *gifInfo = DGifOpen(reinterpret_cast<void*>(fp), ReadDataFromGif);
+ int errorCode = 0; //D_GIF_SUCCEEDED is 0
- if ( !(*gifInfo) )
+#ifdef LIBGIF_VERSION_5_1_OR_ABOVE
+ *gifInfo = DGifOpen( reinterpret_cast<void*>(fp), ReadDataFromGif, &errorCode );
+#else
+ *gifInfo = DGifOpen( reinterpret_cast<void*>(fp), ReadDataFromGif );
+#endif
+
+ if ( !(*gifInfo) || errorCode )
{
+ DALI_LOG_ERROR( "GIF Loader: DGifOpen Error. Code: %d\n", errorCode );
return false;
}
}
/// Called when we want to handle IMAGE_DESC_RECORD_TYPE
-bool HandleImageDescriptionRecordType( Bitmap& bitmap, ImageAttributes& attributes, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished )
+bool HandleImageDescriptionRecordType( Bitmap& bitmap, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished )
{
if ( DGifGetImageDesc( gifInfo ) == GIF_ERROR )
{
return false;
}
- // TODO: Add scaling support
-
// Get the colormap for the GIF
GifColorType* color( GetImageColors( image, gifInfo ) );
}
}
- attributes.SetSize( actualWidth, actualHeight );
-
finished = true;
return true;
image.ExtensionBlockCount = 0;
GifByteType *extensionByte( NULL );
+#ifdef LIBGIF_VERSION_5_1_OR_ABOVE
+ int *extensionBlockTypePointer = &image.ExtensionBlocks->Function;
+#else
+ int *extensionBlockTypePointer = &image.Function;
+#endif
+
// Not really interested in the extensions so just skip them unless there is an error.
- for ( int extRetCode = DGifGetExtension( gifInfo, &image.Function, &extensionByte );
+ for ( int extRetCode = DGifGetExtension( gifInfo, extensionBlockTypePointer, &extensionByte );
extensionByte != NULL;
extRetCode = DGifGetExtensionNext( gifInfo, &extensionByte ) )
{
} // unnamed namespace
-bool LoadGifHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height )
+bool LoadGifHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
{
GifFileType* gifInfo = NULL;
AutoCleanupGif autoCleanupGif(gifInfo);
+ FILE* const fp = input.file;
return LoadGifHeader(fp, width, height, &gifInfo);
}
-bool LoadBitmapFromGif(FILE *fp, Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client )
+bool LoadBitmapFromGif( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
+ FILE* const fp = input.file;
// Load the GIF Header file.
GifFileType* gifInfo( NULL );
if( IMAGE_DESC_RECORD_TYPE == recordType )
{
- if ( !HandleImageDescriptionRecordType( bitmap, attributes, gifInfo, width, height, finished ) )
+ if ( !HandleImageDescriptionRecordType( bitmap, gifInfo, width, height, finished ) )
{
return false;
}