Skip to content
Snippets Groups Projects
Commit 048296be authored by Manuel Günther's avatar Manuel Günther Committed by André Anjos
Browse files

Fixed handling of multi-frame gif (now, the last frame is used); improved Error reporting

parent 3804f496
Branches
Tags v2.2.7
1 merge request!24Resolve "GIF loading seems to be completely broken"
...@@ -417,21 +417,17 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base: ...@@ -417,21 +417,17 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base:
GifByteType *extension; GifByteType *extension;
int InterlacedOffset[] = { 0, 4, 2, 1 }; // The way Interlaced image should. int InterlacedOffset[] = { 0, 4, 2, 1 }; // The way Interlaced image should.
int InterlacedJumps[] = { 8, 8, 4, 2 }; // be read - offsets and jumps... int InterlacedJumps[] = { 8, 8, 4, 2 }; // be read - offsets and jumps...
int row, col, width, height, count, ext_code; int row, col, width, height, ext_code;
bool terminated = false; bool terminated = false;
bool image_found = false; bool image_found = false;
do{ do{
int error = DGifGetRecordType(in_file.get(), &record_type); int error = DGifGetRecordType(in_file.get(), &record_type);
if(error == GIF_ERROR) if(error == GIF_ERROR)
GifErrorHandler("DGifGetRecordType", error); GifErrorHandler("DGifGetRecordType", in_file->Error);
switch(record_type) { switch(record_type) {
case IMAGE_DESC_RECORD_TYPE: case IMAGE_DESC_RECORD_TYPE:
if (image_found){
// we already have found an image...
break;
}
error = DGifGetImageDesc(in_file.get()); error = DGifGetImageDesc(in_file.get());
if (error == GIF_ERROR) GifErrorHandler("DGifGetImageDesc", error); if (error == GIF_ERROR) GifErrorHandler("DGifGetImageDesc", in_file->Error);
row = in_file->Image.Top; // Image Position relative to Screen. row = in_file->Image.Top; // Image Position relative to Screen.
col = in_file->Image.Left; col = in_file->Image.Left;
width = in_file->Image.Width; width = in_file->Image.Width;
...@@ -443,17 +439,16 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base: ...@@ -443,17 +439,16 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base:
} }
if(in_file->Image.Interlace) { if(in_file->Image.Interlace) {
// Need to perform 4 passes on the images: // Need to perform 4 passes on the images:
for(int i=count=0; i<4; ++i) for(int i=0; i<4; ++i)
for(int j=row+InterlacedOffset[i]; j<row+height; j+=InterlacedJumps[i]) { for(int j=row+InterlacedOffset[i]; j<row+height; j+=InterlacedJumps[i]) {
++count;
error = DGifGetLine(in_file.get(), &screen_buffer[j][col], width); error = DGifGetLine(in_file.get(), &screen_buffer[j][col], width);
if(error == GIF_ERROR) GifErrorHandler("DGifGetLine", error); if(error == GIF_ERROR) GifErrorHandler("DGifGetLine", in_file->Error);
} }
} }
else { else {
for(int i=0; i<height; ++i) { for(int i=0; i<height; ++i) {
error = DGifGetLine(in_file.get(), &screen_buffer[row++][col], width); error = DGifGetLine(in_file.get(), &screen_buffer[row++][col], width);
if(error == GIF_ERROR) GifErrorHandler("DGifGetLine", error); if(error == GIF_ERROR) GifErrorHandler("DGifGetLine", in_file->Error);
} }
} }
image_found = true; image_found = true;
...@@ -461,10 +456,10 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base: ...@@ -461,10 +456,10 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base:
case EXTENSION_RECORD_TYPE: case EXTENSION_RECORD_TYPE:
// Skip any extension blocks in file: // Skip any extension blocks in file:
error = DGifGetExtension(in_file.get(), &ext_code, &extension); error = DGifGetExtension(in_file.get(), &ext_code, &extension);
if (error == GIF_ERROR) GifErrorHandler("DGifGetExtension", error); if (error == GIF_ERROR) GifErrorHandler("DGifGetExtension", in_file->Error);
while(extension != NULL) { while(extension != NULL) {
error = DGifGetExtensionNext(in_file.get(), &extension); error = DGifGetExtensionNext(in_file.get(), &extension);
if(error == GIF_ERROR) GifErrorHandler("DGifGetExtensionNext", error); if(error == GIF_ERROR) GifErrorHandler("DGifGetExtensionNext", in_file->Error);
} }
break; break;
case TERMINATE_RECORD_TYPE: case TERMINATE_RECORD_TYPE:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment