]> git.imager.perl.org - imager.git/commitdiff
- set i_format to gif when reading gif files and test for it
authorTony Cook <tony@develop=help.com>
Mon, 29 Nov 2004 13:42:41 +0000 (13:42 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 29 Nov 2004 13:42:41 +0000 (13:42 +0000)
Changes
gif.c
t/t105gif.t

diff --git a/Changes b/Changes
index 157a24a8e568e0a2bfbc2fc6b1be07c9fdb89114..b7d5b4962ebdd3aa3a9f6dab4e43eaa7f77c8608 100644 (file)
--- a/Changes
+++ b/Changes
@@ -914,6 +914,7 @@ Revision history for Perl extension Imager.
 - added --palette action to tools/imager
 - i_img_pal_new() now releases the image object memory if creation
   fails.
+- set i_format to gif when reading gif files and test for it
 
 =================================================================
 
diff --git a/gif.c b/gif.c
index 0592828df9068f845baa0dd20647fbb93baf44bd..db79f6bdae81fedfa3649714ecd0d1057410bcce 100644 (file)
--- a/gif.c
+++ b/gif.c
@@ -179,6 +179,14 @@ i_readgif_low(GifFileType *GifFile, int **colour_table, int *colours) {
   
 
   im = i_img_empty_ch(NULL, GifFile->SWidth, GifFile->SHeight, 3);
+  if (!im) {
+    if (colour_table && *colour_table) {
+      myfree(*colour_table);
+      *colour_table = NULL;
+    }
+    DGifCloseFile(GifFile);
+    return NULL;
+  }
 
   Size = GifFile->SWidth * sizeof(GifPixelType); 
   
@@ -354,6 +362,9 @@ i_readgif_low(GifFileType *GifFile, int **colour_table, int *colours) {
     i_img_destroy(im);
     return NULL;
   }
+
+  i_tags_add(&im->tags, "i_format", 0, "gif", -1, 0);
+
   return im;
 }
 
@@ -554,6 +565,10 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count) {
       if (got_gce && trans_index >= 0)
         channels = 4;
       img = i_img_pal_new(Width, Height, channels, 256);
+      if (!img) {
+        free_images(results, *count);
+        return NULL;
+      }
       /* populate the palette of the new image */
       mm_log((1, "ColorMapSize %d\n", ColorMapSize));
       for (i = 0; i < ColorMapSize; ++i) {
@@ -581,6 +596,7 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count) {
         }
       }
       results[*count-1] = img;
+      i_tags_add(&img->tags, "i_format", 0, "gif", -1, 0);
       i_tags_addn(&img->tags, "gif_left", 0, GifFile->Image.Left);
       /**(char *)0 = 1;*/
       i_tags_addn(&img->tags, "gif_top",  0, GifFile->Image.Top);
index 34ed0d347732c5fb6145e86de8c2d3af8eaf8931..0f13a148c664ac233e8abc76b6e5751bda398e53 100644 (file)
@@ -1,9 +1,9 @@
 #!perl -w
 use strict;
 $|=1;
-print "1..61\n";
+print "1..69\n";
 use Imager qw(:all);
-require "t/testtools.pl";
+BEGIN { require "t/testtools.pl"; }
 
 my $buggy_giflib_file = "buggy_giflib.txt";
 
@@ -28,7 +28,7 @@ i_box_filled($timg, 0, 0, 20, 20, $green);
 i_box_filled($timg, 2, 2, 18, 18, $trans);
 
 if (!i_has_format("gif")) {
-  skipn(1, 61, "no gif support");
+  skipn(1, 69, "no gif support");
 } else {
     open(FH,">testout/t105.gif") || die "Cannot open testout/t105.gif\n";
     binmode(FH);
@@ -553,6 +553,22 @@ EOS
     # I don't see a way to test this, since we don't have a mechanism
     # to give the second image different quant options, we can't trigger
     # a failure just for the second image
+
+    # check that the i_format tag is set for both multiple and single
+    # image reads
+    {
+      my @anim = Imager->read_multi(file=>"testout/t105_anim.gif");
+      okn($num++, @anim == 5, "check we got all the images");
+      for my $frame (@anim) {
+        my ($type) = $frame->tags(name=>'i_format');
+        isn($num++, $type, 'gif', "check i_format for animation frame");
+      }
+
+      my $im = Imager->new;
+      okn($num++, $im->read(file=>"testout/t105.gif"), "read some gif");
+      my ($type) = $im->tags(name=>'i_format');
+      isn($num++, $type, 'gif', 'check i_format for single image read');
+    }
 }
 
 sub ok ($$$) {