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:
int InterlacedOffset[] = { 0, 4, 2, 1 }; // The way Interlaced image should.
int InterlacedJumps[] = { 8, 8, 4, 2 }; // be read - offsets and jumps...
int row, col, width, height, count, ext_code;
int error = DGifGetRecordType(in_file.get(), &record_type);
if(error == GIF_ERROR)
GifErrorHandler("DGifGetRecordType", error);
switch(record_type) {
case IMAGE_DESC_RECORD_TYPE:
error = DGifGetImageDesc(in_file.get());
if (error == GIF_ERROR) GifErrorHandler("DGifGetImageDesc", error);
row = in_file->Image.Top; // Image Position relative to Screen.
col = in_file->Image.Left;
width = in_file->Image.Width;
height = in_file->Image.Height;
if(in_file->Image.Left + in_file->Image.Width > in_file->SWidth ||
in_file->Image.Top + in_file->Image.Height > in_file->SHeight)
{
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);
bool terminated = false;
bool image_found = false;
do{
int error = DGifGetRecordType(in_file.get(), &record_type);
if(error == GIF_ERROR)
GifErrorHandler("DGifGetRecordType", error);
switch(record_type) {
case IMAGE_DESC_RECORD_TYPE:
if (image_found){
// we already have found an image...
break;
}
error = DGifGetImageDesc(in_file.get());
if (error == GIF_ERROR) GifErrorHandler("DGifGetImageDesc", error);
row = in_file->Image.Top; // Image Position relative to Screen.
col = in_file->Image.Left;
width = in_file->Image.Width;
height = in_file->Image.Height;
if(in_file->Image.Left + in_file->Image.Width > in_file->SWidth ||
in_file->Image.Top + in_file->Image.Height > in_file->SHeight)
{
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);
}
}
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);
}
}
break;
case EXTENSION_RECORD_TYPE:
// Skip any extension blocks in file:
error = DGifGetExtension(in_file.get(), &ext_code, &extension);
if (error == GIF_ERROR) GifErrorHandler("DGifGetExtension", error);
while(extension != NULL) {
error = DGifGetExtensionNext(in_file.get(), &extension);
if(error == GIF_ERROR) GifErrorHandler("DGifGetExtensionNext", error);
}
break;
case TERMINATE_RECORD_TYPE:
break;
default: // Should be trapped by DGifGetRecordType.
break;
image_found = true;
break;
case EXTENSION_RECORD_TYPE:
// Skip any extension blocks in file:
error = DGifGetExtension(in_file.get(), &ext_code, &extension);
if (error == GIF_ERROR) GifErrorHandler("DGifGetExtension", error);
while(extension != NULL) {
error = DGifGetExtensionNext(in_file.get(), &extension);
if(error == GIF_ERROR) GifErrorHandler("DGifGetExtensionNext", error);
}
break;
case TERMINATE_RECORD_TYPE:
terminated = true;
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:
......
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