home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * sb2spr.c *
- * *
- * starbase bitmap to extened sprite format *
- * *
- * Version 2.00 (24-Jun-1993) *
- * *
- * (C) 1992/3 DEEJ Technology PLC *
- * *
- ************************************************************************/
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "io.h"
- #include "sprite.h"
- #include "sb.h"
-
- #define CSIZE 256
-
- int main(int argc, char** argv)
- {
- FILE *inf, *outf, *errf;
- int i,j,x,y;
- char c;
- uint r,g,b;
- uint *ptr;
- uchar *sb_buf;
- float cmap[CSIZE][3];
- spr_info_str spr;
- bf_header hdr;
- char string[256];
-
- file_args(argc, argv, &inf, &outf, &errf);
-
- read_struct(BE, (BYTE*)&hdr, bf_header_descr, inf);
-
- if(hdr.bm_mode!=-1 || hdr.pixel_align!=8 ||
- hdr.num_banks!=1 || hdr.csize>256)
- {
- fprintf(stderr,"\nCannot convert this image\n\n");
- return(1);
- }
-
- spr.X = hdr.xlen;
- spr.Y = hdr.ylen;
- spr.Xasp = 1;
- spr.Yasp = 1;
- spr.bpp = hdr.depth;
-
- fill_info(&spr);
-
- fread(&cmap, sizeof(float)*3, hdr.csize, inf);
-
- for(i=0; i<hdr.csize; i++)
- {
- for(j=0; j<3; j++)
- {
- ptr = (uint*)&cmap[i][j];
- *ptr = endian(BE,*ptr);
- }
-
- r = (int)(cmap[i][0]*255.0); r=(r>255) ? 255:r;
- g = (int)(cmap[i][1]*255.0); g=(g>255) ? 255:g;
- b = (int)(cmap[i][2]*255.0); b=(b>255) ? 255:b;
-
- spr.palette[i] = (b<<24) + (g<<16) + (r<<8);
- }
-
- /*
- * WARNING: it is dangerous to assume size of structures
- * in memory is the same in the file when read with read_struct
- */
-
- if(hdr.bm_loc < (sizeof(bf_header)+sizeof(float)*3*hdr.csize))
- {
- fprintf(errf,"Bitmap location is wrong\n");
- return(2);
- }
- else
- {
- for(i=(sizeof(bf_header)+sizeof(float)*3*hdr.csize);
- i<hdr.bm_loc; i++)
- c = fgetc(inf);
- }
-
- alloc_spr_data(&spr);
-
- if((sb_buf = (uchar*)malloc(spr.X)) == 0)
- {
- fprintf(errf,"Unable to allocate sb buffer\n");
- exit(1);
- }
-
- sprintf(string,"Generating sprite %dx%dx%d:",spr.X,spr.Y,spr.bpp);
- progress_start(string);
-
- for(y=0; y<spr.Y; y++)
- {
- fread(sb_buf, spr.X, 1, inf);
-
- for(x=0; x<spr.X; x++)
- {
- write_pixel_val(&spr, x, y, sb_buf[x]);
- }
- progress(y,spr.Y);
- }
- write_sprite(&spr,outf);
-
- progress_finish();
- }
-