X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fpicsmap.c;h=597f4a82b80387815b080871da19cb610e09c6f6;hp=be8903ab3bf55b0a174ba2eb9c33227851940f32;hb=8d3ea9021573747ecd129228ba7782a03243f62c;hpb=06078d3fa68db669ed37178c01873546b4b28745 diff --git a/test/picsmap.c b/test/picsmap.c index be8903ab..597f4a82 100644 --- a/test/picsmap.c +++ b/test/picsmap.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: picsmap.c,v 1.108 2017/11/19 02:56:12 tom Exp $ + * $Id: picsmap.c,v 1.112 2017/11/26 00:10:57 tom Exp $ * * Author: Thomas E. Dickey * @@ -76,7 +76,9 @@ #define Scaled256(n) (NCURSES_COLOR_T) (int)(((n) * 1000.0) / 256) #define ScaledColor(n) (NCURSES_COLOR_T) (int)(((n) * 1000.0) / scale) +#ifndef RGB_PATH #define RGB_PATH "/etc/X11/rgb.txt" +#endif #include @@ -112,6 +114,7 @@ static void warning(const char *fmt,...) GCC_PRINTFLIKE(1, 2); static int gather_c_values(int); static FILE *logfp = 0; +static double aspect_ratio = 0.6; static bool in_curses = FALSE; static bool debugging = FALSE; static bool quiet = FALSE; @@ -452,9 +455,10 @@ read_file(const char *filename) for (j = 0; (size_t) j < size; ++j) { if (blob[j] == '\0' || (UChar(blob[j]) < 32 && - !isspace(blob[j])) || - (UChar(blob[j]) >= 128 && UChar(blob[j]) < 160)) + !isspace(UChar(blob[j]))) || + (UChar(blob[j]) >= 128 && UChar(blob[j]) < 160)) { binary = TRUE; + } if (blob[j] == '\n') { blob[j] = '\0'; if (k && !binary) { @@ -497,6 +501,7 @@ usage(void) ,"Read/display one or more xbm/xpm files (possibly use \"convert\")" ,"" ,"Options:" + ," -a ratio aspect-ratio correction for ImageMagick" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors" #endif @@ -1277,7 +1282,7 @@ parse_img(const char *filename) isspace(UChar(buffer[n])) && sscanf(skip_word(buffer + n), " %dx%d ", &pic_x, &pic_y) == 2) { /* distort image to make it show normally on terminal */ - pic_x = (166 * pic_x) / 100; + pic_x = (int) ((double) pic_x / aspect_ratio); } else { pic_x = pic_y = 0; } @@ -1634,11 +1639,20 @@ main(int argc, char *argv[]) { int n; int opt_d = FALSE; + char ignore_ch; const char *palette_path = 0; - const char *rgb_path = "/etc/X11/rgb.txt"; + const char *rgb_path = RGB_PATH; - while ((n = getopt(argc, argv, "dLl:p:qr:s:x:")) != -1) { + while ((n = getopt(argc, argv, "a:dLl:p:qr:s:x:")) != -1) { switch (n) { + case 'a': + if (sscanf(optarg, "%lf%c", &aspect_ratio, &ignore_ch) != 1 + || aspect_ratio < 0.1 + || aspect_ratio > 10.) { + fprintf(stderr, "Expected a number in [0.1 to 10.]: %s\n", optarg); + usage(); + } + break; #if HAVE_USE_DEFAULT_COLORS case 'd': opt_d = TRUE;