return NULL;
}
- if ( cmapcnt == 0) {
- if (( ColorMap = (GifFile->Image.ColorMap ? GifFile->Image.ColorMap : GifFile->SColorMap) )) {
- mm_log((1, "Adding local colormap\n"));
- ColorMapSize = ColorMap->ColorCount;
+ if (( ColorMap = (GifFile->Image.ColorMap ? GifFile->Image.ColorMap : GifFile->SColorMap) )) {
+ mm_log((1, "Adding local colormap\n"));
+ ColorMapSize = ColorMap->ColorCount;
+ if ( cmapcnt == 0) {
i_colortable_copy(colour_table, colours, ColorMap);
cmapcnt++;
- } else {
- /* No colormap and we are about to read in the image - abandon for now */
- mm_log((1, "Going in with no colormap\n"));
- i_push_error(0, "Image does not have a local or a global color map");
- /* we can't have allocated a colour table here */
- i_img_destroy(im);
- DGifCloseFile(GifFile);
- return NULL;
}
+ } else {
+ /* No colormap and we are about to read in the image - abandon for now */
+ mm_log((1, "Going in with no colormap\n"));
+ i_push_error(0, "Image does not have a local or a global color map");
+ /* we can't have allocated a colour table here */
+ i_img_destroy(im);
+ DGifCloseFile(GifFile);
+ return NULL;
}
+
Row = GifFile->Image.Top; /* Image Position relative to Screen. */
Col = GifFile->Image.Left;
Width = GifFile->Image.Width;
for (Count = i = 0; i < 4; i++) for (j = Row + InterlacedOffset[i]; j < Row + Height; j += InterlacedJumps[i]) {
Count++;
- if (DGifGetLine(GifFile, &GifRow[Col], Width) == GIF_ERROR) {
+ if (DGifGetLine(GifFile, GifRow, Width) == GIF_ERROR) {
gif_push_error();
i_push_error(0, "Reading GIF line");
if (colour_table && *colour_table) {
return NULL;
}
- for (x = 0; x < GifFile->SWidth; x++) {
+ for (x = 0; x < Width; x++) {
ColorMapEntry = &ColorMap->Colors[GifRow[x]];
col.rgb.r = ColorMapEntry->Red;
col.rgb.g = ColorMapEntry->Green;
col.rgb.b = ColorMapEntry->Blue;
- i_ppix(im,x,j,&col);
+ i_ppix(im,Col+x,j,&col);
}
}
}
else {
for (i = 0; i < Height; i++) {
- if (DGifGetLine(GifFile, &GifRow[Col], Width) == GIF_ERROR) {
+ if (DGifGetLine(GifFile, GifRow, Width) == GIF_ERROR) {
gif_push_error();
i_push_error(0, "Reading GIF line");
if (colour_table && *colour_table) {
return NULL;
}
- for (x = 0; x < GifFile->SWidth; x++) {
+ for (x = 0; x < Width; x++) {
ColorMapEntry = &ColorMap->Colors[GifRow[x]];
col.rgb.r = ColorMapEntry->Red;
col.rgb.g = ColorMapEntry->Green;
col.rgb.b = ColorMapEntry->Blue;
- i_ppix(im, x, Row, &col);
+ i_ppix(im, Col+x, Row, &col);
}
Row++;
}
$|=1;
-print "1..23\n";
+print "1..26\n";
use Imager qw(:all);
init_log("testout/t105gif.log",1);
print "not ok 23 # failed to read image with only a local colour map";
}
close FH;
+
+ # image has global and local colour maps
+ open FH, "< testimg/screen2.gif"
+ or die "Cannot open testimg/screen2.gif: $!";
+ binmode FH;
+ my $ims = i_readgif(fileno(FH));
+ if ($ims) {
+ print "ok 24\n";
+ }
+ else {
+ print "not ok 24 # ",Imager::_error_as_msg(),"\n";
+ }
+ close FH;
+ open FH, "< testimg/expected.gif"
+ or die "Cannot open testimg/expected.gif: $!";
+ binmode FH;
+ my $ime = i_readgif(fileno(FH));
+ close FH;
+ if ($ime) {
+ print "ok 25\n";
+ }
+ else {
+ print "not ok 25 # ",Imager::_error_as_msg(),"\n";
+ }
+ if ($ims && $ime) {
+ if (i_img_diff($ime, $ims)) {
+ print "not ok 26 # mismatch ",i_img_diff($ime, $ims),"\n";
+ # save the bad one
+ open FH, "> testout/t105_screen2.gif"
+ or die "Cannot create testout/t105_screen.gif: $!";
+ binmode FH;
+ i_writegifmc($ims, fileno(FH), 7)
+ or print "# could not save t105_screen.gif\n";
+ close FH;
+ }
+ else {
+ print "ok 26\n";
+ }
+ }
+ else {
+ print "ok 26 # skipped\n";
+ }
}
sub test_readgif_cb {