Mercurial > hg > batmud > maputils
changeset 784:c80fb894df24
Add scaling of output image size (by integer value).
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 09 Jun 2009 14:17:38 +0000 |
parents | 7ff68371d0ea |
children | 04dd8afd4094 |
files | map2ppm.c |
diffstat | 1 files changed, 29 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/map2ppm.c Tue Jun 09 10:52:20 2009 +0000 +++ b/map2ppm.c Tue Jun 09 14:17:38 2009 +0000 @@ -15,6 +15,7 @@ optInputIsDiff = FALSE, optUseANSI = FALSE, optCityFormat = FALSE; +int optScale = 1; /* Arguments @@ -28,6 +29,7 @@ { 5, 'o', "output", "Output filename", OPT_ARGREQ }, { 6, 'A', "ansi-colors", "Use ANSI colors", OPT_NONE }, { 7, 'c', "city-format", "Input is a city map", OPT_NONE }, + { 8, 's', "scale", "Scale value (integer)", OPT_ARGREQ }, }; const int optListN = (sizeof(optList) / sizeof(optarg_t)); @@ -81,6 +83,14 @@ THMSG(2, "Input is handled as a city map\n"); break; + case 8: + optScale = atoi(optArg); + if (optScale < 1 || optScale > 50) { + THERR("Invalid scale value %d, must be 1 < x < 50.\n", optScale); + return FALSE; + } + THMSG(2, "Output scaling set to %d.\n", optScale); + break; default: THERR("Unknown option '%s'.\n", currArg); return FALSE; @@ -109,13 +119,13 @@ { FILE *outFile; mapblock_t *map; - int x, y; + int x, y, xscale, yscale; size_t s; unsigned char *d; - char tmpStr[64]; + char str[64]; /* Initialize */ - th_init("map2ppm", "ASCII map to PPM image converter", "0.2", NULL, NULL); + th_init("map2ppm", "ASCII map to PPM image converter", "0.4", NULL, NULL); th_verbosityLevel = 0; /* Parse arguments */ @@ -149,21 +159,22 @@ /* Write header for 24-bit PPM */ THMSG(1, "Outputting 24-bit PPM image of %dx%d ...\n", - map->w, map->h); + map->w * optScale, map->h * optScale); - snprintf(tmpStr, sizeof(tmpStr), + snprintf(str, sizeof(str), "P6\n%d %d\n255\n", - map->w, map->h); + map->w * optScale, map->h * optScale); - fputs(tmpStr, outFile); + fputs(str, outFile); - s = strlen(tmpStr); + s = strlen(str); d = map->d; - for (y = 0; y < map->h; y++) - for (x = 0; x < map->w; x++) { + for (y = 0; y < map->h; y++) { + for (yscale = 0; yscale < optScale; yscale++) + for (x = 0; x < map->w; x++) { int qr, qg, qb, c; qr = 255; qg = qb = 0; - c = (unsigned char )*d; + c = (unsigned char) d[y * map->w + x]; if (optInputIsDiff) { if (c < nmapPieces) { @@ -190,11 +201,13 @@ } } - fputc(qr, outFile); - fputc(qg, outFile); - fputc(qb, outFile); - d++; - s += 3; + for (xscale = 0; xscale < optScale; xscale++) { + fputc(qr, outFile); + fputc(qg, outFile); + fputc(qb, outFile); + s += 3; + } + } } fclose(outFile);