home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * Archimedes colour sprite to X windows bitmap/pixmap converter *
- * *
- * From v2.00 Works with any size of Mode 0/18/23 1x1 aspect ratio sprs *
- * From v3.00 Reads palette to remove the need for inverting later *
- * From v4.00 Buffers input lines for improved performace *
- * From v4.10 Recognises VGA & SVGA mono modes *
- * From v4.20 Uses new sprite library functions *
- * From v4.30 Uses new io library functions *
- * From v5.00 Renamed, outputs in bitmap & 2 pixmap formats *
- * *
- * Version 5.01 (25-Nov-1993) *
- * *
- * (C) 1989/1990/1992/1993 DEEJ Technology PLC *
- * *
- ************************************************************************/
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "io.h"
- #include "sprite.h"
-
- void make_bitmap(void);
- void make_pixmap(int);
-
- FILE *inf, *outf, *errf;
- spr_info_str spr;
-
- int main(int argc, char **argv)
- {
- char type;
- char string[256];
-
- if(argc>1 && argv[1][0]=='-')
- {
- type = argv[1][1];
-
- switch(type)
- {
- case 'h':
- fprintf(stderr,
- "%s [<flags>] [<sprite>] [<output>] [<error>]\n",
- argv[0]);
- fprintf(stderr,
- "<flags> := -h : help\n");
- fprintf(stderr,
- "<flags> := -b : 2 colour X bitmap format (default)\n");
- fprintf(stderr,
- " -c : 2-16 colour X pixmap format\n");
- fprintf(stderr,
- " -p : 2-16 colour X pixmap 2 format\n");
- fprintf(stderr,
- "Input defaults to stdin, output to stdout,\n");
- fprintf(stderr,
- "error/progress to stderr\n");
-
- return(0);
- break;
-
- case 'b':
- case 'c':
- case 'p':
- /* flag ok */
- break;
-
- default:
- fprintf(stderr,"Unknown flag '%c'\n",type);
- return(1);
- break;
- }
-
- argc--; argv++;
- }
- else
- {
- type = 'b';
- }
-
- file_args(argc, argv, &inf, &outf, &errf);
-
- read_sprite(&spr, inf);
-
- if(type=='b')
- {
- if(spr.bpp!=1)
- {
- fprintf(errf,"Only 1 BPP bitmaps supported\n");
- return(2);
- }
- else
- {
- sprintf(string,"Generating bitmap %dx%d :",spr.X,spr.Y);
- progress_start(string);
-
- make_bitmap();
- }
- }
- else
- {
- if(spr.bpp>4)
- {
- fprintf(errf,"Only 1-4 BPP pixmaps supported\n");
- return(2);
- }
- else
- {
- sprintf(string,"Generating pixmap %dx%dx%d :",
- spr.X,spr.Y,spr.bpp);
- progress_start(string);
-
- make_pixmap(type=='c' ? 1:2);
- }
- }
-
- progress_finish();
-
- return(0);
- }
-
- void make_bitmap(void)
- {
- int x,y;
- int count,inv;
- uchar a;
- uchar *line;
-
- if((spr.palette[0] & 0xFFFFFF00) != 0)
- inv = 1;
- else
- inv = 0;
-
- fprintf(outf, "#define bitmap_width %d\n",spr.X);
- fprintf(outf, "#define bitmap_height %d\n",spr.Y);
- fprintf(outf, "static char bitmap_bits[] = {\n");
-
- count=0;
-
- for(y=0; y<spr.Y; y++)
- {
- line = spr.spr_data + y*spr.line_size;
-
- for(x=0; x<(spr.X+7)/8; x++)
- {
- a=line[x];
- if(inv) a=a^255; /* a EOR 255 for invert */
- fprintf(outf, "0x%X,",a);
- if(++count>=16)
- {
- fputc('\n', outf);
- count=0;
- }
- }
- progress(y,spr.Y);
- }
- fprintf(outf,"\n}\n");
- fflush(outf);
- }
-
- void make_pixmap(int type)
- {
- /*
- static char cols[] = " .,:;!|$-=+*o0O@";
- */
- static char cols[] = "0123456789ABCDEF";
- char format[256];
- char *line;
- int i,x,y;
-
- if((line=malloc(spr.X+1))==0)
- {
- fprintf(errf,"Unable to allocate line buffer\n");
- exit(3);
- }
-
- if(type==1)
- {
- fprintf(outf,"/* XPM */\n");
- fprintf(outf,"static char *pixmap[] = {\n");
- fprintf(outf,"/* width height ncolours, cpp, [x_hot y_hot] */\n");
- strcpy(format,"\"%d %d %d %d\",\n");
- }
- else
- {
- fprintf(outf,"! XPM2\n");
-
- strcpy(format,"%d %d %d %d\n");
- }
-
- fprintf(outf, format, spr.X, spr.Y, spr.cols, 1);
-
- if(type==1)
- {
- fprintf(outf,"/* colours */\n");
-
- strcpy(format,"\"%c\tc #%04x%04x%04x\",\n");
- }
- else
- {
- strcpy(format,"%c c #%04x%04x%04x\n");
- }
-
- for(i=0; i<spr.cols; i++)
- {
- fprintf(outf,format,cols[i],
- ((spr.palette[i] >> 8) & 0xFF) * 0x101,
- ((spr.palette[i] >> 16) & 0xFF) * 0x101,
- ((spr.palette[i] >> 24) & 0xFF) * 0x101);
- }
-
- if(type==1)
- {
- fprintf(outf,"/* pixels */\n");
-
- strcpy(format,"\"%s\",\n");
- }
- else
- {
- strcpy(format,"%s\n");
- }
-
- for(y=0; y<spr.Y; y++)
- {
- for(x=0; x<spr.X; x++)
- {
- line[x] = cols[read_pixel_val(&spr, x, y)];
- }
-
- if(y==(spr.Y-1) && type==1)
- {
- strcpy(format,"\"%s\"};\n");
- }
-
- fprintf(outf,format,line);
-
- progress(y,spr.Y);
- }
- }
-