Added depth option

This commit is contained in:
alpine9000
2016-04-07 16:21:00 +10:00
parent 68f957d3eb
commit 852a089dff
+13 -5
View File
@@ -6,7 +6,7 @@
config_t config = { config_t config = {
.verbose = 0, .verbose = 0,
.bitDepth = 4, .bitDepth = 0,
.inputFile = 0 .inputFile = 0
}; };
@@ -15,7 +15,9 @@ config_t config = {
static unsigned static unsigned
get_tile_address(tmx_map *m, unsigned int gid) get_tile_address(tmx_map *m, unsigned int gid)
{ {
printf("get_tile_address %d\n", gid); if (config.verbose) {
printf("get_tile_address %d\n", gid);
}
tmx_tileset* ts = m->ts_head; tmx_tileset* ts = m->ts_head;
unsigned baseAddress = 0; unsigned baseAddress = 0;
@@ -24,7 +26,9 @@ get_tile_address(tmx_map *m, unsigned int gid)
tmx_tile* t = ts->tiles; tmx_tile* t = ts->tiles;
if (t[i].id+ts->firstgid == gid) { if (t[i].id+ts->firstgid == gid) {
unsigned address = baseAddress + (t[i].ul_y * ((ts->image->width/8) * config.bitDepth)) + (t[i].ul_x/8); unsigned address = baseAddress + (t[i].ul_y * ((ts->image->width/8) * config.bitDepth)) + (t[i].ul_x/8);
printf("%s - baseAddress = %d address = %d\n", ts->name, baseAddress, address); if (config.verbose) {
printf("%s - baseAddress = %d address = %d\n", ts->name, baseAddress, address);
}
return address; return address;
} }
} }
@@ -73,7 +77,7 @@ void
usage() usage()
{ {
fprintf(stderr, fprintf(stderr,
"%s: --input <input.tmx>\n"\ "%s: --input <input.tmx> --depth <num bitplanes>\n"\
"options:\n"\ "options:\n"\
" --help\n"\ " --help\n"\
" --verbose\n", config.argv[0]); " --verbose\n", config.argv[0]);
@@ -94,6 +98,7 @@ main(int argc, char *argv[])
{"verbose", no_argument, &config.verbose, 1}, {"verbose", no_argument, &config.verbose, 1},
{"help", no_argument, 0, '?'}, {"help", no_argument, 0, '?'},
{"input", required_argument, 0, 'i'}, {"input", required_argument, 0, 'i'},
{"depth", required_argument, 0, 'd'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@@ -110,6 +115,9 @@ main(int argc, char *argv[])
case 'i': case 'i':
config.inputFile = optarg; config.inputFile = optarg;
break; break;
case 'd':
sscanf(optarg, "%d", &config.bitDepth);
break;
case '?': case '?':
usage(); usage();
break; break;
@@ -120,7 +128,7 @@ main(int argc, char *argv[])
} }
if (config.inputFile == 0) { if (config.inputFile == 0 || config.bitDepth == 0) {
usage(); usage();
abort(); abort();
} }