]> git.imager.perl.org - imager.git/blobdiff - tga.c
- more information on gif library versions in README and Makefile.PL
[imager.git] / tga.c
diff --git a/tga.c b/tga.c
index 361f732e6a765f0bf5580e252f39172c4ee5e169..04f684c8065f1e39f18ae3b673b45a8c40b4bbee 100644 (file)
--- a/tga.c
+++ b/tga.c
@@ -1,5 +1,4 @@
 #include "image.h"
-#include "io.h"
 #include "log.h"
 #include "iolayer.h"
 
@@ -321,6 +320,38 @@ tga_header_unpack(tga_header *header, unsigned char headbuf[18]) {
 }
 
 
+
+int
+tga_header_verify(unsigned char headbuf[18]) {
+  tga_header header;
+  tga_header_unpack(&header, headbuf);
+  switch (header.datatypecode) { 
+  default:
+               printf("bad typecode!\n");
+    return 0;
+  case 0:
+  case 1:  /* Uncompressed, color-mapped images */ 
+  case 2:  /* Uncompressed, rgb images          */ 
+  case 3:  /* Uncompressed, grayscale images    */ 
+  case 9:  /* Compressed,   color-mapped images */ 
+  case 10: /* Compressed,   rgb images          */ 
+  case 11: /* Compressed,   grayscale images    */ 
+         break;
+       }
+
+  switch (header.colourmaptype) { 
+  default:
+               printf("bad colourmaptype!\n");
+    return 0;
+  case 0:
+  case 1:
+       break;
+       }
+  
+  return 1;
+}
+
+
 /*
 =item tga_header_pack(header, headbuf)
 
@@ -388,21 +419,23 @@ tga_source_read(tga_source *s, unsigned char *buf, size_t pixels) {
       s->len = (s->hdr &~(1<<7))+1;
       s->state = (s->hdr & (1<<7)) ? Rle : Raw;
       {
+/*
        static cnt = 0;
        printf("%04d %s: %d\n", cnt++, s->state==Rle?"RLE":"RAW", s->len);
-      }
+ */
+     }
       if (s->state == Rle && s->ig->readcb(s->ig, s->cval, s->bytepp) != s->bytepp) return 0;
 
       break;
     case Rle:
-      ml = min(s->len, pixels-cp);
+      ml = i_min(s->len, pixels-cp);
       for(k=0; k<ml; k++) for(j=0; j<s->bytepp; j++) 
        buf[(cp+k)*s->bytepp+j] = s->cval[j];
       cp     += ml;
       s->len -= ml;
       break;
     case Raw:
-      ml = min(s->len, pixels-cp);
+      ml = i_min(s->len, pixels-cp);
       if (s->ig->readcb(s->ig, buf+cp*s->bytepp, ml*s->bytepp) != ml*s->bytepp) return 0;
       cp     += ml;
       s->len -= ml;