home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / graphics / sprtools_1 / c / clr_info < prev    next >
Text File  |  1998-04-06  |  2KB  |  72 lines

  1. /************************************************************************
  2.  *                                    *
  3.  * clear bitmap information                        *
  4.  *                                    *
  5.  * Version 2.01 (25-Aug-1993)                        *
  6.  *         2.02 (06-Apr-1998)     File opened as binary             *
  7.  *                                    *
  8.  * (C) 1993-8 DEEJ Technology PLC                    *
  9.  *                                    *
  10.  ************************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "io.h"
  15. #include "clear.h"
  16.  
  17. int main(int argc, char** argv)
  18. {
  19.         int  i,r,g,b;
  20.         FILE *file;
  21.         clear_hdr hdr;
  22.         char creator[256];
  23.  
  24.         if(argc>1 && strcmp(argv[argc-1],"-c")!=0)
  25.                 file = fopen(argv[argc-1],"rb");
  26.         else
  27.                 file = stdin;
  28.  
  29.         if(file == 0)
  30.         {
  31.                 fprintf(stderr,"Could not open file\n");
  32.                 return(1);
  33.         }
  34.         
  35.         i = 0;
  36.         while((creator[i++] = fgetc(file)) > 0);
  37.  
  38.         read_struct(LE, (BYTE*)&hdr, clear_hdr_descr, file);
  39.  
  40.         printf("Creator        : %s\n",creator);
  41.         printf("Version        : %d.%d\n",hdr.version/100,hdr.version%100);
  42.         printf("Width, Height  : %d,%d\n",hdr.width,hdr.height);
  43.         printf("Bits Per Pixel : %d\n",hdr.bpp);
  44.  
  45.         if(argc>1 && strcmp(argv[1],"-c")==0)
  46.         {
  47.                 printf("\n");
  48.  
  49.                 if(hdr.bpp>8)
  50.                 {
  51.                         fprintf(stderr,"No colour map with BPP > 8\n");
  52.                 }
  53.                 else
  54.                 {
  55.                         printf("%-10s : %5s %5s %5s\n",
  56.                                "Colour Map","Red","Green","Blue");
  57.  
  58.                         for(i=0; i<(1<<hdr.bpp); i++)
  59.                         {
  60.                                 r = fgetc(file);
  61.                                 g = fgetc(file);
  62.                                 b = fgetc(file);
  63.                                 printf("%10d : %5d %5d %5d\n",i,r,g,b);
  64.                         }
  65.                 }
  66.         }
  67.  
  68.         fclose(file);
  69.  
  70.         return(0);
  71. }
  72.