]> git.imager.perl.org - imager.git/commitdiff
- set i_format to tga when reading tga files and test for it
authorTony Cook <tony@develop=help.com>
Mon, 29 Nov 2004 13:52:03 +0000 (13:52 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 29 Nov 2004 13:52:03 +0000 (13:52 +0000)
- handle image creation failures when reading tga files

Changes
TODO
t/t108tga.t
tga.c

diff --git a/Changes b/Changes
index 438ac955a8ffb0b9d120637ce0030480298f8feb..1b6a5213ab9ed5b6d25b477b0845681723f299b1 100644 (file)
--- a/Changes
+++ b/Changes
@@ -916,6 +916,8 @@ Revision history for Perl extension Imager.
   fails.
 - set i_format to gif when reading gif files and test for it
 - set i_format to pnm when reading pnm files and test for it
+- set i_format to tga when reading tga files and test for it
+- handle image creation failures when reading tga files
 
 =================================================================
 
diff --git a/TODO b/TODO
index 565222ecef6a389dbeee8ea7e3ebcf6f9f400426..a821003d9b686775aaa5b7adec23045903c979ac 100644 (file)
--- a/TODO
+++ b/TODO
@@ -5,7 +5,7 @@ PRE-0.44:
   - bmp - done
   - jpeg - done
   - tiff
-  - tga
+  - tga - done
   - rgb
   - png - done
   - gif - done
index d3aab11738e67a29126ec076def7e92bcfba4a02..2a06786f7ca707b734d3f8eb0da685b8147e6f0c 100644 (file)
@@ -1,7 +1,8 @@
 #!perl -w
-print "1..16\n";
+print "1..17\n";
 use Imager qw(:all);
 use strict;
+BEGIN { require "t/testtools.pl"; }
 init_log("testout/t108tga.log",1);
 
 
@@ -66,7 +67,8 @@ if ($imoo->write(file=>'testout/t108_oo.tga')) {
   print "not ok 16 # ",$imoo->errstr,"\n";
 }
 
-
+my ($type) = $imoo->tags(name=>'i_format');
+isn(17, $type, 'tga', "check i_format tag");
 
 
 sub write_test {
diff --git a/tga.c b/tga.c
index 04f684c8065f1e39f18ae3b673b45a8c40b4bbee..edcef272fd7b085fbe030124aa257f7ab5e4e77f 100644 (file)
--- a/tga.c
+++ b/tga.c
@@ -719,6 +719,12 @@ i_readtga_wiol(io_glue *ig, int length) {
   img = mapped ? 
     i_img_pal_new(width, height, channels, 256) :
     i_img_empty_ch(NULL, width, height, channels);
+
+  if (!img) {
+    if (idstring) 
+      myfree(idstring);
+    return NULL;
+  }
   
   if (idstring) {
     i_tags_add(&img->tags, "tga_idstring", 0, idstring, header.idlength, 0);
@@ -758,6 +764,7 @@ i_readtga_wiol(io_glue *ig, int length) {
   myfree(databuf);
   if (linebuf) myfree(linebuf);
   
+  i_tags_add(&img->tags, "i_format", 0, "tga", -1, 0);
   i_tags_addn(&img->tags, "tga_bitspp", 0, mapped?header.colourmapdepth:header.bitsperpixel);
   if (src.compressed) i_tags_addn(&img->tags, "compressed", 0, 1);
   return img;