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

  1. /************************************************************************
  2.  *                                    *
  3.  * Starbase bitmap information                        *
  4.  *                                    *
  5.  * Version 1.00 (21-Jun-1992)                        *
  6.  *        2.00 (23-Aug-1993)                        *
  7.  *                                    *
  8.  * (C) 1992/3 DEEJ Technology PLC                    *
  9.  *                                    *
  10.  ************************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "io.h"
  15. #include "sb.h"
  16.  
  17. #define CSIZE 256
  18.  
  19. float cmap[CSIZE][3];
  20.  
  21. bf_header hdr;
  22.  
  23. int main(int argc, char** argv)
  24. {
  25.         int  i,j,r,g,b;
  26.     uint *ptr;
  27.         FILE *file;
  28.  
  29.         if(argc>1 && strcmp(argv[argc-1],"-c")!=0)
  30.                 file = fopen(argv[argc-1],"r");
  31.         else
  32.                 file = stdin;
  33.  
  34.         if(file == 0)
  35.         {
  36.                 fprintf(stderr,"Could not open file\n");
  37.                 return(1);
  38.         }
  39.         
  40.         read_struct(BE, (BYTE*)&hdr, bf_header_descr, file);
  41.  
  42.         printf("file id          : %s\n",hdr.file_id);
  43.         printf("revision         : %d\n",hdr.rev);
  44.         printf("device id        : %s\n",hdr.device_id);
  45.         printf("bitmap offset    : %d\n",hdr.bm_loc);
  46.         printf("end of bitmap    : %d\n",hdr.eod_loc);
  47.         printf("x,y start        : %d,%d\n",hdr.xstart,hdr.ystart);
  48.         printf("x,y length       : %d,%d\n",hdr.xlen,hdr.ylen);
  49.         printf("data format      : %d\n",hdr.bm_mode);
  50.         printf("bits per pixel   : %d\n",hdr.depth);
  51.         printf("pixel alignment  : %d\n",hdr.pixel_align);
  52.         printf("number of  banks : %d\n",hdr.num_banks);
  53.         printf("display enable   : %d\n",hdr.disp_en);
  54.         printf("colour map mode  : %d\n",hdr.cmap_mode);
  55.         printf("colour map size  : %d\n",hdr.csize);
  56.         printf("background index : %d\n",hdr.back_index);
  57.  
  58.         if(argc>1 && strcmp(argv[1],"-c")==0)
  59.         {
  60.                 printf("\n");
  61.  
  62.                 if(hdr.csize>256)
  63.                 {
  64.                         fprintf(stderr,"colour map is > 256\n");
  65.                 }
  66.                 else
  67.                 {
  68.                         fread(&cmap,sizeof(float),hdr.csize*3,file);
  69.  
  70.                         printf("%-10s : %5s %5s %5s\n",
  71.                                "Colour Map","Red","Green","Blue");
  72.  
  73.                         for(i=0; i<hdr.csize; i++)
  74.                         {
  75.                 for(j=0; j<3; j++)
  76.                 {
  77.                     ptr = (uint*)&cmap[i][j];
  78.                                     *ptr = endian(BE,*ptr);
  79.                 }
  80.  
  81.                                 r = (int)(cmap[i][0]*255.0); r=(r>255) ? 255:r;
  82.                                 g = (int)(cmap[i][1]*255.0); g=(g>255) ? 255:g;
  83.                                 b = (int)(cmap[i][2]*255.0); b=(b>255) ? 255:b;
  84.  
  85.                                 printf("%10d : %5d %5d %5d\n",i,r,g,b);
  86.                         }
  87.                 }
  88.         }
  89.  
  90.         fclose(file);
  91.  
  92.         return(0);
  93. }
  94.