- }
- }
-
- if( !fileInfo.map )
- {
- LOADERR("LOAD_ERROR_CORRUPT_FILE");
- }
- fileInfo.length = fileData.length;
- fileInfo.position = 0;
-
-// actually ask libgif to open the file
-#if GIFLIB_MAJOR >= 5
- gif = DGifOpen( &fileInfo, FileRead, NULL );
-#else
- gif = DGifOpen( &fileInfo, FileRead );
-#endif
-
- if (!gif)
- {
- LOADERR("LOAD_ERROR_UNKNOWN_FORMAT");
- }
-
- // get the gif "screen size" (the actual image size)
- prop.w = gif->SWidth;
- prop.h = 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( IMG_TOO_BIG(prop.w, prop.h) )
- {
- LOADERR("LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
- }
- LOADERR("LOAD_ERROR_GENERIC");
- }
- // walk through gif records in file to figure out info
- do
- {
- if( DGifGetRecordType(gif, &rec) == GIF_ERROR )
- {
- // if we have a gif that ends part way through a sequence
- // (or animation) consider it valid and just break - no error
- if( imageNumber > 1 )
- {
- break;
- }
- LOADERR("LOAD_ERROR_UNKNOWN_FORMAT");
- }
-
- // get image description section
- if( rec == IMAGE_DESC_RECORD_TYPE )
- {
- int img_code;
- GifByteType *img;
-
- // get image desc
- if( DGifGetImageDesc(gif) == GIF_ERROR )
- {
- LOADERR("LOAD_ERROR_UNKNOWN_FORMAT");
- }
- // skip decoding and just walk image to next
- if( DGifGetCode(gif, &img_code, &img) == GIF_ERROR )
- {
- LOADERR("LOAD_ERROR_UNKNOWN_FORMAT");
- }
- // skip till next...
- while( img )
- {
- img = NULL;
- DGifGetCodeNext( gif, &img );
- }
- // store geometry in the last frame info data
- if( frameInfo )
- {
- StoreFrameInfo( gif, frameInfo );
- CheckTransparency( full, frameInfo, prop.w, prop.h );
- }
- // or if we dont have a frameInfo entry - create one even for stills