void wrpalette_carr(FILE *fp, const char *name, struct cmapent *cmap, int ncol);
enum { OUT_IMG, OUT_C, OUT_ASM } outmode;
+static const char *otype_suffix[] = {".png", ".c", ".s"};
+
int tile_xsz = 8, tile_ysz = 8;
+const char *output_filename;
int main(int argc, char **argv)
{
if(argv[i][0] == '-') {
if(argv[i][2] == 0) {
switch(argv[i][1]) {
+ case 'o':
+ output_filename = argv[++i];
+ break;
+
case 't':
if(sscanf(argv[++i], "%dx%d", &tile_xsz, &tile_ysz) != 2) {
fprintf(stderr, "-t must be followed by the tile size (WxH)\n");
{
printf("Usage: %s [options] <img1> [<img2> ... <imgN>]\n", argv0);
printf("Options:\n");
+ printf(" -o <file>: output file\n");
printf(" -t WxH: tile size (default 8x8)\n");
printf(" -c: output C array\n");
printf(" -s: output GNU assembler data\n");
}
*mapptr++ = idx;
+ if(i < 2) {
+ printf("%2dx%-2d: %d\n", j, i, idx);
+ }
sptr += tile.scansz;
}
- sptr += (tile_ysz - 1) * tile.scansz;
+ sptr += (tile_ysz - 1) * tile.pitch;
}
ntiles = dynarr_size(tiles);
tile = tiles[0];
tile.height = ntiles * tile_ysz;
- outfile = alloca(strlen(basename) + 5);
+ if(output_filename) {
+ outfile = (char*)output_filename;
+ } else {
+ outfile = alloca(strlen(basename) + 5);
+ sprintf(outfile, "%s%s", basename, otype_suffix[outmode]);
+ }
switch(outmode) {
case OUT_IMG:
- sprintf(outfile, "%s.png", basename);
-
if(save_image(&tile, outfile) == -1) {
fprintf(stderr, "failed to write output image\n");
goto err;
break;
case OUT_C:
- sprintf(outfile, "%s.c", basename);
-
if(!(fp = fopen(outfile, "w"))) {
fprintf(stderr, "failed to open output file: %s: %s\n", outfile, strerror(errno));
goto err;
break;
case OUT_ASM:
- sprintf(outfile, "%s.s", basename);
/* TODO */
break;
}