Commit e51d59da authored by Manuel Günther's avatar Manuel Günther Committed by André Anjos

Reading all records from the image; use only the first image inside the GIF

parent 1ec669e8
...@@ -416,51 +416,65 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base: ...@@ -416,51 +416,65 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base:
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, count, ext_code;
int error = DGifGetRecordType(in_file.get(), &record_type); bool terminated = false;
if(error == GIF_ERROR) bool image_found = false;
GifErrorHandler("DGifGetRecordType", error); do{
switch(record_type) { int error = DGifGetRecordType(in_file.get(), &record_type);
case IMAGE_DESC_RECORD_TYPE: if(error == GIF_ERROR)
error = DGifGetImageDesc(in_file.get()); GifErrorHandler("DGifGetRecordType", error);
if (error == GIF_ERROR) GifErrorHandler("DGifGetImageDesc", error); switch(record_type) {
row = in_file->Image.Top; // Image Position relative to Screen. case IMAGE_DESC_RECORD_TYPE:
col = in_file->Image.Left; if (image_found){
width = in_file->Image.Width; // we already have found an image...
height = in_file->Image.Height; break;
if(in_file->Image.Left + in_file->Image.Width > in_file->SWidth || }
in_file->Image.Top + in_file->Image.Height > in_file->SHeight) error = DGifGetImageDesc(in_file.get());
{ if (error == GIF_ERROR) GifErrorHandler("DGifGetImageDesc", error);
throw std::runtime_error("GIF: the dimensions of image larger than the dimensions of the canvas."); row = in_file->Image.Top; // Image Position relative to Screen.
} col = in_file->Image.Left;
if(in_file->Image.Interlace) { width = in_file->Image.Width;
// Need to perform 4 passes on the images: height = in_file->Image.Height;
for(int i=count=0; i<4; ++i) if(in_file->Image.Left + in_file->Image.Width > in_file->SWidth ||
for(int j=row+InterlacedOffset[i]; j<row+height; j+=InterlacedJumps[i]) { in_file->Image.Top + in_file->Image.Height > in_file->SHeight)
++count; {
error = DGifGetLine(in_file.get(), &screen_buffer[j][col], width); throw std::runtime_error("GIF: the dimensions of image larger than the dimensions of the canvas.");
}
if(in_file->Image.Interlace) {
// Need to perform 4 passes on the images:
for(int i=count=0; i<4; ++i)
for(int j=row+InterlacedOffset[i]; j<row+height; j+=InterlacedJumps[i]) {
++count;
error = DGifGetLine(in_file.get(), &screen_buffer[j][col], width);
if(error == GIF_ERROR) GifErrorHandler("DGifGetLine", error);
}
}
else {
for(int i=0; i<height; ++i) {
error = DGifGetLine(in_file.get(), &screen_buffer[row++][col], width);
if(error == GIF_ERROR) GifErrorHandler("DGifGetLine", error); if(error == GIF_ERROR) GifErrorHandler("DGifGetLine", error);
} }
}
else {
for(int i=0; i<height; ++i) {
error = DGifGetLine(in_file.get(), &screen_buffer[row++][col], width);
if(error == GIF_ERROR) GifErrorHandler("DGifGetLine", error);
} }
} image_found = true;
break; break;
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", 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", error);
} }
break; break;
case TERMINATE_RECORD_TYPE: case TERMINATE_RECORD_TYPE:
break; terminated = true;
default: // Should be trapped by DGifGetRecordType. break;
break; default: // Should be trapped by DGifGetRecordType.
break;
}
} while (!terminated);
if (!image_found){
std::runtime_error("GIF: image does not contain an image section");
} }
// Lets dump it - set the global variables required and do it: // Lets dump it - set the global variables required and do it:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment