home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * Archimedes sprite to rasterfile format bitmap converter *
- * *
- * Version 2.00 (18-Nov-1993) *
- * *
- * (C) 1989/1993 DEEJ Technology PLC *
- * *
- ************************************************************************/
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "io.h"
- #include "sprite.h"
- #include "ras.h"
-
- int main(int argc, char **argv)
- {
- FILE *inf, *outf, *errf;
- int i,j,x,y,X,Y;
- uchar *ras_buf;
- uint p;
- int line_size;
- spr_info_str spr;
- rasterfile hdr;
- char string[256];
-
- file_args(argc, argv, &inf, &outf, &errf);
-
- read_sprite(&spr, inf);
-
- /* account for square/reqtangular pixels */
-
- if(spr.Yasp == 2)
- Y = spr.Y*2;
- else
- Y = spr.Y;
-
- hdr.ras_magic = RAS_MAGIC;
- hdr.ras_width = spr.X;
- hdr.ras_height = Y;
- hdr.ras_type = RT_STANDARD;
- hdr.ras_maptype = spr.has_palette ? RMT_EQUAL_RGB : RMT_NONE;
- hdr.ras_maplength = spr.has_palette * 3;
-
- switch(spr.bpp)
- {
- case 1:
- hdr.ras_depth = 1;
- line_size = ((spr.X + 15)/8) & ~1;
- break;
-
- case 2:
- case 4:
- case 8:
- hdr.ras_depth = 8;
- line_size = (spr.X + 1) & ~1;
- break;
-
- case 15:
- case 24:
- hdr.ras_depth = 24;
- line_size = (spr.X*3 + 1) & ~1;
- break;
- }
-
- hdr.ras_length = line_size * Y;
-
- if((ras_buf = (uchar*)malloc(line_size)) == 0)
- {
- fprintf(errf,"Unable to allocate raster buffer\n");
- exit(1);
- }
-
- write_struct(BE, (BYTE*)&hdr, rasterfile_descr, outf);
-
- /* write colour map if bpp<=8 */
-
- if(spr.has_palette)
- {
- for(j=8; j<=24; j+=8)
- {
- for(i=0; i<spr.has_palette; i++)
- {
- fputc(spr.palette[i] >> j, outf);
- }
- }
- }
-
- sprintf(string,"Generating raster %dx%dx%d:",spr.X,Y,hdr.ras_depth);
- progress_start(string);
-
- X = hdr.ras_depth==1 ? line_size : spr.X;
-
- for(y=0; y<Y; y+=spr.Yasp)
- {
- for(x=0; x<X; x++)
- {
-
- switch(hdr.ras_depth)
- {
- case 1:
- p = spr.spr_data[x+y*spr.line_size];
- ras_buf[x] = bit_swap(p);
- break;
-
- case 8:
- ras_buf[x] = read_pixel_val(&spr,x,y/spr.Yasp);
- break;
-
- case 24:
- p = read_pixel_val(&spr,x,y/spr.Yasp);
- ras_buf[x*3 ] = p >> 24;
- ras_buf[x*3+1] = p >> 16;
- ras_buf[x*3+2] = p >> 8;
- break;
- }
- }
-
- /* write one or two lines depending on Y aspect */
-
- fwrite(ras_buf, line_size, 1, outf);
-
- if(spr.Yasp == 2)
- fwrite(ras_buf, line_size, 1, outf);
-
- progress(y,Y);
- }
-
- progress_finish();
- }
-