home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / sprtools / c / tga_info < prev    next >
Encoding:
Text File  |  1994-07-18  |  2.4 KB  |  78 lines

  1. /************************************************************************
  2.  *                                    *
  3.  * TGA bitmap information                        *
  4.  *                                    *
  5.  * Version 1.00 (17-Jun-1993)                        *
  6.  *         2.00 (05-Aug-1993)                        *
  7.  *         2.50 (22-Aug-1993)                        *
  8.  *                                    *
  9.  * (C) 1993 DEEJ Technology PLC                        *
  10.  *                                    *
  11.  ************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "io.h"
  16. #include "tga.h"
  17.  
  18. int main(int argc, char** argv)
  19. {
  20.         int  i;
  21.         int r,g,b;
  22.         FILE *file;
  23.         tga_hdr_str hdr;
  24.  
  25.         if(argc>1 && strcmp(argv[argc-1],"-c")!=0)
  26.                 file = fopen(argv[argc-1],"r");
  27.         else
  28.                 file = stdin;
  29.  
  30.         if(file == 0)
  31.         {
  32.                 fprintf(stderr,"Could not open file\n");
  33.                 return(1);
  34.         }
  35.  
  36.         read_struct(LE, (BYTE*)&hdr, tga_hdr_descr, file);
  37.  
  38.         printf("ID Length        : %d\n",hdr.IDLength);
  39.         printf("Map Type         : %d\n",hdr.MapType);
  40.         printf("Image Type       : %d\n",hdr.ImageType);
  41.         printf("Map Info Orgin   : %d\n",hdr.MapInfoOrgin);
  42.         printf("Map Info Length  : %d\n",hdr.MapInfoLength);
  43.         printf("Map Info Width   : %d\n",hdr.MapInfoWidth);
  44.         printf("Image x,y start  : %d,%d\n",hdr.ImageInfoX,hdr.ImageInfoY);
  45.         printf("Image x,y length : %d,%d\n",hdr.ImageInfoDX,hdr.ImageInfoDY);
  46.         printf("Image depth (BPP): %d\n",hdr.ImageInfoDepth);
  47.         printf("Image attributes : %d\n",hdr.ImageInfoAttrib);
  48.  
  49.         if(argc>1 && strcmp(argv[1],"-c")==0)
  50.         {
  51.                 printf("\n");
  52.                 if(hdr.MapInfoOrgin==0    &&
  53.                    hdr.MapInfoLength<=256 &&
  54.                    hdr.MapInfoWidth==24)
  55.                 {
  56.                         printf("Palette red,green,blue\n");
  57.  
  58.                         for(i=0; i<(int)hdr.MapInfoLength; i++)
  59.                         {
  60.                                 b = fgetc(file);
  61.                                 g = fgetc(file);
  62.                                 r = fgetc(file);
  63.  
  64.                                 printf("%5d : %3d %3d %3d\n",
  65.                                         i, r, g, b);
  66.                         }
  67.                 }
  68.                 else
  69.                 {
  70.                         printf("Cannot handle this type of colour map\n");
  71.                 }
  72.         }
  73.  
  74.         fclose(file);
  75.  
  76.         return(0);
  77. }
  78.