From: Tony Cook Date: Thu, 19 Oct 2006 10:26:12 +0000 (+0000) Subject: The gif_disposal and gif_user_input tags weren't being set to the X-Git-Tag: Imager-0.55~21 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/336f5078205737fd922506cc6378f901cd93e4b3 The gif_disposal and gif_user_input tags weren't being set to the correct values when a GIF with a GCE block was read. http://rt.cpan.org/Ticket/Display.html?id=22192 --- diff --git a/gif.c b/gif.c index 792b8407..a31cc9a0 100644 --- a/gif.c +++ b/gif.c @@ -519,12 +519,12 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) { GifRowType GifRow; int got_gce = 0; - int trans_index; /* transparent index if we see a GCE */ - int gif_delay; /* delay from a GCE */ - int user_input; /* user input flag from a GCE */ - int disposal; /* disposal method from a GCE */ + int trans_index = 0; /* transparent index if we see a GCE */ + int gif_delay = 0; /* delay from a GCE */ + int user_input = 0; /* user input flag from a GCE */ + int disposal = 0; /* disposal method from a GCE */ int got_ns_loop = 0; - int ns_loop; + int ns_loop = 0; char *comment = NULL; /* a comment */ i_img **results = NULL; int result_alloc = 0; @@ -748,8 +748,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) { else trans_index = -1; gif_delay = Extension[2] + 256 * Extension[3]; - user_input = (Extension[0] & 2) != 0; - disposal = (Extension[0] >> 2) & 3; + user_input = (Extension[1] & 2) != 0; + disposal = (Extension[1] >> 2) & 7; } if (ExtCode == 0xFF && *Extension == 11) { if (memcmp(Extension+1, "NETSCAPE2.0", 11) == 0) { @@ -1660,13 +1660,13 @@ Returns non-zero on success. static undef_int i_writegif_low(i_quantize *quant, GifFileType *gf, i_img **imgs, int count) { - unsigned char *result; + unsigned char *result = NULL; int color_bits; ColorMapObject *map; int scrw = 0, scrh = 0; int imgn, orig_count, orig_size; int posx, posy; - int trans_index; + int trans_index = -1; i_mempool mp; int *localmaps; int anylocal; @@ -1674,11 +1674,11 @@ i_writegif_low(i_quantize *quant, GifFileType *gf, i_img **imgs, int count) { int glob_img_count; i_color *orig_colors = quant->mc_colors; i_color *glob_colors = NULL; - int glob_color_count; + int glob_color_count = 0; int glob_want_trans; - int glob_paletted; /* the global map was made from the image palettes */ - int colors_paletted; - int want_trans; + int glob_paletted = 0; /* the global map was made from the image palettes */ + int colors_paletted = 0; + int want_trans = 0; int interlace; int gif_background; diff --git a/t/t105gif.t b/t/t105gif.t index a8a7842b..423645c8 100644 --- a/t/t105gif.t +++ b/t/t105gif.t @@ -1,4 +1,5 @@ #!perl -w + =pod IF THIS TEST CRASHES @@ -12,7 +13,7 @@ UPGRADE. use strict; $|=1; use lib 't'; -use Test::More tests => 113; +use Test::More tests => 125; use Imager qw(:all); BEGIN { require "t/testtools.pl"; } use Carp 'confess'; @@ -48,7 +49,7 @@ SKIP: $im = Imager->new(xsize=>2, ysize=>2); ok(!$im->write(file=>"testout/nogif.gif"), "should fail to write gif"); is($im->errstr, 'format not supported', "check no gif message"); - skip("no gif support", 109); + skip("no gif support", 121); } open(FH,">testout/t105.gif") || die "Cannot open testout/t105.gif\n"; binmode(FH); @@ -669,6 +670,25 @@ SKIP: is($im[0]->tags(name => 'gif_delay'), 50, "first delay read back"); is($im[1]->tags(name => 'gif_delay'), 50, "second delay read back"); } + SKIP: + { # check graphic control extension and ns loop tags are read correctly + print "# check GCE and netscape loop extension tag values\n"; + my @im = Imager->read_multi(file => 'testimg/screen3.gif'); + is(@im, 2, "read 2 images from screen3.gif") + or skip("Could not load testimg/screen3.gif:".Imager->errstr, 11); + is($im[0]->tags(name => 'gif_delay'), 50, "0 - gif_delay"); + is($im[0]->tags(name => 'gif_disposal'), 2, "0 - gif_disposal"); + is($im[0]->tags(name => 'gif_trans_index'), undef, "0 - gif_trans_index"); + is($im[0]->tags(name => 'gif_user_input'), 0, "0 - gif_user_input"); + is($im[0]->tags(name => 'gif_loop'), 0, "0 - gif_loop"); + is($im[1]->tags(name => 'gif_delay'), 50, "1 - gif_delay"); + is($im[1]->tags(name => 'gif_disposal'), 2, "1 - gif_disposal"); + is($im[1]->tags(name => 'gif_trans_index'), 7, "1 - gif_trans_index"); + is($im[1]->tags(name => 'gif_trans_color'), 'color(255,255,255,0)', + "1 - gif_trans_index"); + is($im[1]->tags(name => 'gif_user_input'), 0, "1 - gif_user_input"); + is($im[1]->tags(name => 'gif_loop'), 0, "1 - gif_loop"); + } } sub test_readgif_cb {