home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
graphics
/
sprtools_1
/
c
/
spr2clr
< prev
next >
Wrap
Text File
|
1998-04-03
|
4KB
|
117 lines
/************************************************************************
* *
* spr2clr.c *
* *
* Archimedes sprite to clear format bitmap converter *
* *
* Version 2.00 (27-Aug-1993) *
* *
* (C) 1993 DEEJ Technology PLC *
* *
************************************************************************/
#define CREATOR "spr2clr version 2.00 (27-Aug-1993)"
#define VERSION 200
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "io.h"
#include "sprite.h"
#include "clear.h"
int main(int argc, char **argv)
{
FILE *inf, *outf, *errf;
int i,x,y,Y;
uint r,g,b,rgb;
int line_size;
uchar *clr_buf;
spr_info_str spr;
clear_hdr 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;
/* write creator string */
strcpy(string,CREATOR);
for(i=0; i<(int)strlen(string); i++)
fputc(string[i], outf);
fputc(0, outf);
hdr.version = VERSION;
hdr.width = spr.X;
hdr.height = Y;
hdr.bpp = spr.bpp==15 ? 16 : spr.bpp;
line_size = (spr.pix<=8) ? spr.X : spr.X*3;
if((clr_buf = (uchar*)malloc(line_size)) == 0)
{
fprintf(errf,"Unable to allocate clearbuffer\n");
exit(1);
}
write_struct(LE, (BYTE*)&hdr, clear_hdr_descr, outf);
if(spr.bpp <= 8)
{
for(i=0; i<spr.cols; i++)
{
r = (spr.palette[i] >> 8) & 0xFF;
g = (spr.palette[i] >> 16) & 0xFF;
b = (spr.palette[i] >> 24) & 0xFF;
fputc(r, outf);
fputc(g, outf);
fputc(b, outf);
}
}
sprintf(string,"Generating clear %dx%dx%d:",spr.X,Y,hdr.bpp);
progress_start(string);
for(y=0; y<Y; y+=spr.Yasp)
{
for(x=0; x<spr.X; x++)
{
if(spr.bpp <= 8)
{
clr_buf[x] = read_pixel_val(&spr, x, y/spr.Yasp);
}
else
{
rgb = read_pixel_RGB(&spr, x, y/spr.Yasp);
r = (rgb >> 8) & 0xFF;
g = (rgb >> 16) & 0xFF;
b = (rgb >> 24) & 0xFF;
clr_buf[x*3+0] = r;
clr_buf[x*3+1] = g;
clr_buf[x*3+2] = b;
}
}
fwrite(clr_buf, line_size, 1, outf);
if(spr.Yasp==2)
fwrite(clr_buf, line_size, 1, outf);
progress(y,Y);
}
progress_finish();
return(0);
}