# HG changeset patch # User John Tsiombikas # Date 1500229823 -10800 # Node ID 0b96363742d30969738d34f5179442a13580477f # Parent c5e5bf1769d862891a8f35e5e452314a07782459 added palette export, and fixed a planar pixel output bug diff -r c5e5bf1769d8 -r 0b96363742d3 .hgignore --- a/.hgignore Sat Jul 15 13:32:49 2017 +0300 +++ b/.hgignore Sun Jul 16 21:30:23 2017 +0300 @@ -6,3 +6,6 @@ \.iff$ \.lbm$ \.bin$ +\.img$ +\.pal$ +\.cmap$ diff -r c5e5bf1769d8 -r 0b96363742d3 Makefile --- a/Makefile Sat Jul 15 13:32:49 2017 +0300 +++ b/Makefile Sun Jul 16 21:30:23 2017 +0300 @@ -3,6 +3,7 @@ bin = lbm2bin +CFLAGS = -pedantic -Wall -g LDFLAGS = -lm $(bin): $(obj) diff -r c5e5bf1769d8 -r 0b96363742d3 src/main.c --- a/src/main.c Sat Jul 15 13:32:49 2017 +0300 +++ b/src/main.c Sun Jul 16 21:30:23 2017 +0300 @@ -1,15 +1,19 @@ #include #include #include +#include #include #include "image.h" static int proc_image(const char *fname); static const char *modestr(int cmode); static void output_planar(FILE *fp, struct image *img); -static void output_chunky(FILE *fp, struct image *img); +static void output_linear(FILE *fp, struct image *img); +static void output_palette(FILE *fp, struct image *img, int pcol_bits); static int planar = 0; +static int pcol_bits = 8; +static int verbose = 0; int main(int argc, char **argv) { @@ -19,19 +23,30 @@ if(argv[i][0] == '-') { if(argv[i][2] == 0) { switch(argv[i][1]) { + case 'a': + planar = 1; + pcol_bits = 4; + break; + case 'p': planar = 1; break; - case 'c': + case 'l': planar = 0; break; + case 'v': + verbose = 1; + break; + case 'h': printf("usage: %s [options] ... \n", argv[0]); printf("Options:\n"); - printf(" -p: output image in planar format (default)\n"); - printf(" -c: output image in chunky format\n"); + printf(" -a: amiga mode (4bit palette colors & planar format)\n"); + printf(" -p: output image in planar format\n"); + printf(" -c: output image in linear (chunky) format\n"); + printf(" -v: verbose output\n"); printf(" -h: print usage and exit\n"); return 0; @@ -71,9 +86,11 @@ if(!(suffix = strrchr(outfname, '.'))) { suffix = outfname + strlen(outfname); } - strcpy(suffix, ".bin"); + strcpy(suffix, ".img"); - printf("processing %s -> %s\n", fname, outfname); + if(verbose) { + printf("processing %s -> %s\n", fname, outfname); + } if(!(fp = fopen(outfname, "wb"))) { fprintf(stderr, "failed to open output file: %s: %s\n", outfname, strerror(errno)); @@ -82,23 +99,48 @@ return -1; } - printf(" bits per pixel: %d\n", img.bpp); - if(img.num_ranges) { - printf(" color ranges:\n"); - for(i=0; ibpp; i++) { for(y=0; yheight; y++) { for(x=0; xwidth; x++) { - acc |= (((*pptr++ >> i) & 1) << acc_bit); + acc |= (((*pptr >> i) & 1) << acc_bit); if(--acc_bit == 0) { fputc(acc, fp); acc_bit = 7; acc = 0; + ++pptr; } } } } } -static void output_chunky(FILE *fp, struct image *img) +static void output_linear(FILE *fp, struct image *img) { int i, j; unsigned char *pptr = img->pixels; @@ -136,6 +179,29 @@ } } +static void output_palette(FILE *fp, struct image *img, int pcol_bits) +{ + int i, num_colors; + + num_colors = 1 << img->bpp; + + assert(pcol_bits == 8 || pcol_bits == 4); + + if(pcol_bits == 8) { + for(i=0; ipalette[i].r, fp); + fputc(img->palette[i].g, fp); + fputc(img->palette[i].b, fp); + } + } else { + /* nibble colors */ + for(i=0; ipalette[i].b | (img->palette[i].g << 4), fp); + fputc(img->palette[i].r, fp); + } + } +} + static const char *modestr(int cmode) { switch(cmode) {