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

  1. /************************************************************************
  2.  *                                    *
  3.  * Archimedes sprite information                    *
  4.  *                                    *
  5.  * Version 1.00 (09-Mar-1989)                        *
  6.  *         2.00 (17-Jun-1993) - New sprite library routines used    *
  7.  *         2.10 (17-Aug-1993)                        *
  8.  *         3.00 (14-Sep-1993) - Colour statisitics added        *
  9.  *         4.02 (13-Jan-1994) - Deep sprite info added            *
  10.  *                                    *
  11.  * (C) 1989-1994 DEEJ Technology PLC                    *
  12.  *                                    *
  13.  ************************************************************************/
  14.  
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "io.h"
  19. #include "sprite.h"
  20. #include "palette.h"
  21.  
  22. /* uncomment to get stats on hash table usage */
  23. /*
  24. #define HASH_STAT
  25. */
  26.         
  27. int main(int argc, char** argv)
  28. {
  29.         int  i;
  30.     int  xres, yres, type;
  31.         FILE *file;
  32.  
  33.         spr_info_str spr;
  34.  
  35.         if(argc>1 && argv[argc-1][0]!='-')
  36.                 file = fopen(argv[argc-1],"r");
  37.         else
  38.                 file = stdin;
  39.  
  40.         if(file == 0)
  41.         {
  42.                 fprintf(stderr,"Could not open file\n");
  43.                 return(1);
  44.         }
  45.  
  46.         read_sprite_header(&spr,file);
  47.  
  48.     type = (unsigned)spr.mode >> 27;
  49.     xres = (spr.mode >>  1) & 0xFFF;
  50.     yres = (spr.mode >> 14) & 0xFFF;
  51.  
  52.     if(type==0)
  53.     {
  54.             printf("Mode        : %d (0x%X)\n", spr.mode, spr.mode);
  55.     }
  56.     else
  57.     {
  58.             printf("Mode (deep) : 0x%X (%d:%dx%d)\n", spr.mode,
  59.                       type,xres,yres);
  60.     }
  61.         printf("Resolution  : %dx%d\n",     spr.X,    spr.Y);
  62.         printf("Pixel apsect: %dx%d\n",     spr.Xasp, spr.Yasp);
  63.         printf("Line size   : %d\n",        spr.line_size);
  64.         printf("BPP/spacing : %d/%d\n",     spr.bpp,  spr.pix);
  65.         printf("Colours     : %d\n",        spr.cols);
  66.         printf("Palette     : %s (%d)\n",   spr.has_palette ? "Yes":"No",
  67.                         spr.has_palette);
  68.  
  69.         if(argc>1 && strcmp(argv[1],"-c")==0)
  70.         {
  71.                 printf("\n");
  72.                 if(spr.has_palette)
  73.                 {
  74.                         printf("Palette BBGGRRXX  red,green,blue\n");
  75.  
  76.                         for(i=0; i<spr.cols; i++)
  77.                         {
  78.                                 printf("%5d : %08X  %3d %3d %3d\n",
  79.                                         i, spr.palette[i],
  80.                                         (spr.palette[i] >> 8)  & 0xFF,
  81.                                         (spr.palette[i] >> 16) & 0xFF,
  82.                                         (spr.palette[i] >> 24) & 0xFF);
  83.                         }
  84.                 }
  85.                 else
  86.                 {
  87.                         printf("Sprite has no palette\n");
  88.                 }
  89.         }
  90.  
  91.         if(argc>1 && strcmp(argv[1],"-s")==0)
  92.         {
  93.                 hist_info *hist;
  94.  
  95.                 /* read sprite data */
  96.  
  97.                 alloc_spr_data(&spr);
  98.                 fread(spr.spr_data, spr.line_size, spr.Y, file);
  99.  
  100.                 /* build and report on histogram */
  101.  
  102. #ifdef HASH_STAT
  103.                 printf("\n");
  104. #endif
  105.                 hist = build_histogram(&spr);
  106. #ifdef HASH_STAT
  107.                 printf("\n");
  108.  
  109.                 printf("Hash used   : %-7d %3d%%\n",hist->hash_used,
  110.                                                     hist->hash_used*
  111.                                                     100/HASH_SIZE);
  112.                 printf("Hash hits   : %-7d %3d%%\n",hist->hash_hits,
  113.                                                     hist->hash_hits*
  114.                                                     100/(spr.X*spr.Y));
  115.                 printf("Hash misses : %-7d %3d%%\n",hist->hash_miss,
  116.                                                     hist->hash_miss*
  117.                                                     100/(spr.X*spr.Y));
  118.                 printf("Hash chain  : %-7d\n",      hist->hash_chain);
  119.                 printf("\n");
  120. #endif
  121.                 printf("Colours used: %d\n",hist->colours);
  122.                 printf("used > 1    : %d\n",hist->more1);
  123.                 printf("used > 10   : %d\n",hist->more10);
  124.                 printf("used > 100  : %d\n",hist->more100);
  125.                 printf("used > %.2f%%: %-5d (%d pixels)\n",
  126.                                             100.0/(float)FILTER_FRAC,
  127.                                             hist->more_frac,
  128.                                             hist->fraction);
  129.                 printf("Maximum use : %d\n",hist->max_use);
  130.                 printf("Average use : %d\n",hist->avg_use);
  131.         }
  132.         fclose(file);
  133. }
  134.