home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / graphics / sprtools_1 / c / spr2clr < prev    next >
Text File  |  1998-04-03  |  4KB  |  117 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  * spr2clr.c                                                            *
  4.  *                                                                      *
  5.  * Archimedes sprite to clear format bitmap converter                   *
  6.  *                                                                      *
  7.  * Version 2.00 (27-Aug-1993)                                           *
  8.  *                                                                      *
  9.  * (C) 1993 DEEJ Technology PLC                                         *
  10.  *                                                                      *
  11.  ************************************************************************/
  12.  
  13. #define CREATOR "spr2clr version 2.00 (27-Aug-1993)"
  14. #define VERSION 200
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include "io.h"
  20. #include "sprite.h"
  21. #include "clear.h"
  22.  
  23.  
  24. int main(int argc, char **argv)
  25. {
  26.         FILE *inf, *outf, *errf;
  27.         int          i,x,y,Y;
  28.         uint         r,g,b,rgb;
  29.         int          line_size;
  30.         uchar       *clr_buf;
  31.         spr_info_str spr;
  32.         clear_hdr    hdr;
  33.         char         string[256];
  34.  
  35.         file_args(argc, argv, &inf, &outf, &errf); 
  36.  
  37.         read_sprite(&spr, inf);
  38.  
  39.         /* account for square/reqtangular pixels */
  40.  
  41.         if(spr.Yasp == 2)
  42.                 Y = spr.Y*2;
  43.         else
  44.                 Y = spr.Y;
  45.  
  46.         /* write creator string */
  47.  
  48.         strcpy(string,CREATOR);
  49.  
  50.         for(i=0; i<(int)strlen(string); i++)
  51.                 fputc(string[i], outf);
  52.         fputc(0, outf);
  53.  
  54.         hdr.version = VERSION;
  55.         hdr.width   = spr.X;
  56.         hdr.height  = Y;
  57.         hdr.bpp     = spr.bpp==15 ? 16 : spr.bpp;
  58.  
  59.         line_size = (spr.pix<=8) ? spr.X : spr.X*3;
  60.  
  61.         if((clr_buf = (uchar*)malloc(line_size)) == 0)
  62.         {
  63.                 fprintf(errf,"Unable to allocate clearbuffer\n");
  64.                 exit(1);
  65.         }
  66.  
  67.         write_struct(LE, (BYTE*)&hdr, clear_hdr_descr, outf);
  68.  
  69.         if(spr.bpp <= 8)
  70.         {
  71.                 for(i=0; i<spr.cols; i++)
  72.                 {
  73.                         r = (spr.palette[i] >>  8) & 0xFF;
  74.                         g = (spr.palette[i] >> 16) & 0xFF;
  75.                         b = (spr.palette[i] >> 24) & 0xFF;
  76.         
  77.                         fputc(r, outf);
  78.                         fputc(g, outf);
  79.                         fputc(b, outf);
  80.                 }
  81.         }
  82.  
  83.         sprintf(string,"Generating clear %dx%dx%d:",spr.X,Y,hdr.bpp);
  84.         progress_start(string);
  85.  
  86.         for(y=0; y<Y; y+=spr.Yasp)
  87.         {
  88.                 for(x=0; x<spr.X; x++)
  89.                 {
  90.                         if(spr.bpp <= 8)
  91.                         {
  92.                                 clr_buf[x] = read_pixel_val(&spr, x, y/spr.Yasp);
  93.                         }
  94.                         else
  95.                         {
  96.                                 rgb = read_pixel_RGB(&spr, x, y/spr.Yasp);
  97.  
  98.                                 r = (rgb >>  8) & 0xFF;
  99.                                 g = (rgb >> 16) & 0xFF;
  100.                                 b = (rgb >> 24) & 0xFF;
  101.  
  102.                                 clr_buf[x*3+0] = r;
  103.                                 clr_buf[x*3+1] = g;
  104.                                 clr_buf[x*3+2] = b;
  105.                         }
  106.                 }
  107.                 fwrite(clr_buf, line_size, 1, outf);
  108.                 if(spr.Yasp==2)
  109.                         fwrite(clr_buf, line_size, 1, outf);
  110.  
  111.                 progress(y,Y);
  112.         }
  113.  
  114.         progress_finish();
  115.         return(0);
  116. }
  117.