home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * Archimedes extended sprite to PC Windows 3 BMP bitmap converter *
- * *
- * Version 3.00 (02-Feb-1995) *
- * *
- * (C) 1992-5 DEEJ Technology PLC *
- * *
- ************************************************************************/
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "io.h"
- #include "bmp.h"
- #include "sprite.h"
-
- int main(int argc, char** argv)
- {
- FILE *inf, *outf, *errf;
- int i,x,y;
- int Y,y2;
- int size, pal_size, line_size;
- uint rgb, bgr;
- uchar p;
- BYTE *bmp_buf;
- spr_info_str spr;
- bmp_hdr_str bmp;
- char string[256];
-
- file_args(argc, argv, &inf, &outf, &errf);
- read_sprite(&spr, inf);
-
- if(spr.bpp!=1 && spr.bpp!=4 && spr.bpp!=8 && spr.bpp!=24)
- {
- fprintf(errf, "Only 1,4,8 & 24 BPP images can be handled\n");
- return(1);
- }
-
- Y = spr.Y * spr.Yasp;
- line_size = spr.pix==32 ? ((spr.X*3+3) & ~3) : spr.line_size;
- size = spr.Y*line_size;
- pal_size = spr.has_palette*4;
-
- if((bmp_buf = malloc(size)) == 0)
- {
- fprintf(stderr,"Unable to allocate BMP buffer\n");
- return(1);
- }
-
- bmp.id[0] = 'B';
- bmp.id[1] = 'M';
- bmp.file_size = size+pal_size+0x36;
- bmp.resurved1 = 0;
- bmp.resurved1 = 0;
- bmp.bitmap_offset = 0x36+pal_size;
- bmp.subheader_size = 0x28;
- bmp.width = spr.X;
- bmp.height = Y;
- bmp.bit_planes = 1;
- bmp.bits_per_pixel = spr.bpp;
- bmp.compression = 0;
- bmp.bitmap_size = size;
- bmp.X_pix_per_meter = 0;
- bmp.Y_pix_per_meter = 0;
- bmp.palette_entries = spr.has_palette;
- bmp.colours = spr.cols;
-
- write_struct(LE, (void*)&bmp, bmp_whdr_descr, outf);
-
- if(spr.bpp <= 8)
- {
- for(i=0; i<spr.cols; i++)
- {
- bgr = swap_endian(spr.palette[i]); /* BMP is opposite endian */
- fputdLE(bgr,outf);
- }
- }
-
- sprintf(string,"Generating BMP %dx%dx%d:",spr.X,Y,spr.bpp);
- progress_start(string);
-
- for(y=Y-1; y>=0; y-=spr.Yasp)
- {
- y2 = y/spr.Yasp;
-
- if(spr.bpp != 24)
- {
- for(x=0; x<spr.line_size; x++)
- {
- p = spr.spr_data[x + y2*spr.line_size];
-
- switch(spr.bpp)
- {
- case 1:
- bmp_buf[x] = bit_swap(p);
- break;
-
- case 4:
- bmp_buf[x] = bit4_swap(p);
- break;
-
- case 8:
- bmp_buf[x] = p;
- break;
- }
- }
- }
- else
- {
- for(x=0; x<spr.X; x++)
- {
- rgb = read_pixel_RGB(&spr, x, y2);
-
- bmp_buf[x*3+0] = rgb >> 24;
- bmp_buf[x*3+1] = rgb >> 16;
- bmp_buf[x*3+2] = rgb >> 8;
- }
- }
- /* write one or two lines depending on Y aspect */
-
- fwrite(bmp_buf, line_size, 1, outf);
-
- if(spr.Yasp == 2)
- fwrite(bmp_buf, line_size, 1, outf);
-
- progress(Y-y-1,Y);
- }
- progress_finish();
-
- fclose(inf);
- fclose(outf);
- return(0);
- }
-