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

  1. /************************************************************************
  2.  *                                                                      *
  3.  * sun raster information                                               *
  4.  *                                                                      *
  5.  * Version 2.00 (16-Nov-1993)                                           *
  6.  *                                                                      *
  7.  * (C) 1989/1993 DEEJ Technology PLC                                    *
  8.  *                                                                      *
  9.  ************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include "io.h"
  14. #include "ras.h"
  15.  
  16. int main(int argc, char** argv)
  17. {
  18.         int  i,j;
  19.         rasterfile ras;
  20.         FILE *file;
  21.         uchar cmap[256][3];
  22.         char *ras_types[] =
  23.                 {
  24.                         "RT_OLD",
  25.                         "RT_STANDARD",
  26.                         "RT_BYTE_ENCODED",
  27.                         "RT_FORMAT_RGB",
  28.                         "RT_FORMAT_TIFF",
  29.                         "RT_FORMAT_IFF"
  30.                 };
  31.         char *ras_maptypes[] =
  32.                 {
  33.                         "RMT_NONE",
  34.                         "RMT_EQUAL_RGB",
  35.                         "RMT_RAW"
  36.                 };
  37.                 
  38.         if(argc>1 && strcmp(argv[argc-1],"-c")!=0)
  39.                 file = fopen(argv[argc-1],"r");
  40.         else
  41.                 file = stdin;
  42.  
  43.         if(file == 0)
  44.         {
  45.                 fprintf(stderr,"Could not open file\n");
  46.                 return(1);
  47.         }
  48.         
  49.         read_struct(BE, (BYTE*)&ras, rasterfile_descr, file);
  50.  
  51.         printf("Magic word : 0x%08X (0x%08X)\n", ras.ras_magic, RAS_MAGIC);
  52.         printf("Width      : %d \n", ras.ras_width);
  53.         printf("Height     : %d \n", ras.ras_height);
  54.         printf("Depth      : %d \n", ras.ras_depth);
  55.         printf("Length     : %d \n", ras.ras_length);
  56.         printf("Type       : %s (%d)\n", ras.ras_type > RT_FORMAT_IFF ?
  57.                                 "Unknown" : ras_types[ras.ras_type],
  58.                                 ras.ras_type);
  59.         printf("Map type   : %s (%d)\n", ras.ras_maptype > RMT_RAW ?
  60.                                 "Unknown" : ras_maptypes[ras.ras_maptype],
  61.                                 ras.ras_maptype);
  62.         printf("Map length : %d (%d)\n", ras.ras_maplength,ras.ras_maplength/3);
  63.  
  64.  
  65.         if(argc>1 && strcmp(argv[1],"-c")==0)
  66.         {
  67.                 printf("\n");
  68.  
  69.                 if(ras.ras_maptype != RMT_EQUAL_RGB)
  70.                 {
  71.                         printf("Only RMT_EQUAL_RGB maps can be displayed\n");
  72.                         return(0);
  73.                 }
  74.                 if((ras.ras_maplength/3) > 256)
  75.                 {
  76.                         printf("Colour map is > 256 entries\n");
  77.                         return(0);
  78.                 }
  79.  
  80.                 printf("%-10s : %s\n", "Colour Map","Red Green Blue");
  81.  
  82.                 /* read colour map */
  83.  
  84.                 for(j=0; j<3; j++)
  85.                 {
  86.                         for(i=0; i<ras.ras_maplength/3; i++)
  87.                         {
  88.                                 cmap[i][j] = fgetc(file);
  89.                         }
  90.                 }
  91.  
  92.                 for(i=0; i<ras.ras_maplength/3; i++)
  93.                 {
  94.                         printf("%10d : %02X  %02X  %02X\n",i,
  95.                                                          cmap[i][0],
  96.                                                          cmap[i][1],
  97.                                                          cmap[i][2]);
  98.                 }
  99.         }
  100.  
  101.         fclose(file);
  102.  
  103.         return(0);
  104. }
  105.