home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * sun raster to extended sprite format bitmap converter *
- * *
- * Version 2.00 (18-Nov-1993) *
- * 2.50 (17-Jun-1994) 24 bit raster file extensions *
- * *
- * (C) 1993/4 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;
- FILE *outf;
- FILE *errf;
- int i,j;
- int x,y;
- int X;
- int line_size;
- int line_off;
- uint p;
- uchar *ras_buf;
- uchar cmap[256][3];
- rasterfile hdr;
- spr_info_str spr;
- char string[256];
-
- file_args(argc, argv, &inf, &outf, &errf);
-
- read_struct(BE, (BYTE*)&hdr, rasterfile_descr, inf);
-
- if(hdr.ras_magic != RAS_MAGIC)
- {
- fprintf(errf, "This is not a raster file\n");
- return(1);
- }
-
- if(hdr.ras_type!=RT_OLD && hdr.ras_type!=RT_STANDARD)
- {
- fprintf(errf, "Only RT_OLD & RT_STANDARD types supported\n");
- return(2);
- }
-
- if(hdr.ras_maptype!=RMT_EQUAL_RGB && hdr.ras_maptype!=RMT_NONE)
- {
- fprintf(errf, "Only RMT_EQUAL_RGB and RMT_NONE map types supported\n");
- return(3);
- }
-
- if(hdr.ras_depth!=1 && hdr.ras_depth!=8 && hdr.ras_depth!=24)
- {
- fprintf(errf, "Only images with 1,8 or 24 BPP can be handled\n");
- return(4);
- }
-
- spr.X = hdr.ras_width;
- spr.Y = hdr.ras_height;
- spr.Xasp = 1;
- spr.Yasp = 1;
- spr.bpp = hdr.ras_depth;
-
- fill_info(&spr);
-
- alloc_spr_data(&spr);
-
- switch(hdr.ras_depth)
- {
- case 1:
- line_size = ((hdr.ras_width + 15)/8) & ~1;
- break;
- case 8:
- line_size = (hdr.ras_width + 1) & ~1;
- break;
-
- case 24:
- line_size = (hdr.ras_width*3 + 1) & ~1;
- break;
- }
-
- if((ras_buf=(uchar*)malloc(line_size)) == 0)
- {
- fprintf(errf,"Unable to allocate raster buffer\n");
- exit(5);
- }
-
- /* read colour map */
-
- if(hdr.ras_maptype!=RMT_NONE)
- {
- for(j=0; j<3; j++)
- {
- for(i=0; i<hdr.ras_maplength/3; i++)
- {
- cmap[i][j] = fgetc(inf);
- }
- }
-
- for(i=0; i<spr.cols; i++)
- {
- spr.palette[i] = (cmap[i][2] << 24) |
- (cmap[i][1] << 16) |
- (cmap[i][0] << 8);
- }
- }
-
- sprintf(string,"Generating sprite %dx%dx%d:",spr.X,spr.Y,spr.bpp);
- progress_start(string);
-
- X = spr.bpp==24 ? spr.X : spr.line_size;
-
- for(y=0; y<spr.Y; y++)
- {
- fread(ras_buf, line_size, 1, inf);
-
- line_off = y * spr.line_size;
-
- for(x=0; x<X; x++)
- {
-
- switch(spr.bpp)
- {
- case 1:
- spr.spr_data[x+line_off] = bit_swap(ras_buf[x]);
- break;
-
- case 8:
- spr.spr_data[x+line_off] = ras_buf[x];
- break;
-
- case 24:
- p = (ras_buf[x*3 ] << 24) +
- (ras_buf[x*3+1] << 16) +
- (ras_buf[x*3+2] << 8);
- write_pixel_val(&spr, x, y, p);
- break;
- }
- }
- progress(y,spr.Y);
- }
-
- write_sprite(&spr, outf);
-
- progress_finish();
- }
-