X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fpicsmap.c;h=b582f3aada5d0828c0f110e3ba434363bebb7e27;hp=09b46ee9cb0b26cbd7f1294ac1411785d36dbc55;hb=HEAD;hpb=79b07cae47a6fa064aa4d2ea70fe930884751eb4 diff --git a/test/picsmap.c b/test/picsmap.c index 09b46ee9..b582f3aa 100644 --- a/test/picsmap.c +++ b/test/picsmap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2021,2022 Thomas E. Dickey * + * Copyright 2018-2022,2023 Thomas E. Dickey * * Copyright 2017,2018 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: picsmap.c,v 1.142 2022/02/06 01:44:34 tom Exp $ + * $Id: picsmap.c,v 1.149 2023/04/23 23:20:37 tom Exp $ * * Author: Thomas E. Dickey * @@ -53,13 +53,6 @@ #include #include -#if HAVE_STDINT_H -#include -#define my_intptr_t intptr_t -#else -#define my_intptr_t long -#endif - #if HAVE_TSEARCH #include #endif @@ -487,27 +480,28 @@ read_file(const char *filename) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: picsmap [options] [imagefile [...]]" ,"Read/display one or more xbm/xpm files (possibly use \"convert\")" ,"" + ,USAGE_COMMON ,"Options:" - ," -a ratio aspect-ratio correction for ImageMagick" + ," -a ratio aspect-ratio correction for ImageMagick" #if HAVE_USE_DEFAULT_COLORS - ," -d invoke use_default_colors" + ," -d invoke use_default_colors" #endif - ," -L add debugging information to logfile" - ," -l logfile write informational messages to logfile" - ," -p palette color-palette file (default \"$TERM.dat\")" - ," -q less verbose" - ," -r rgb-path xpm uses X rgb color-names (default \"" RGB_PATH "\")" - ," -s SECS pause for SECS seconds after display vs getch" + ," -L add debugging information to logfile" + ," -l FILE write informational messages to FILE" + ," -p FILE color-palette file (default \"$TERM.dat\")" + ," -q less verbose" + ," -r FILE xpm uses X rgb color-names in FILE (default \"" RGB_PATH "\")" + ," -s SECS pause for SECS seconds after display vs getch" #if USE_EXTENDED_COLORS - ," -x [pc] use extension (p=extended-pairs, c=extended-colors)" - ," Either/both extension may be given" + ," -x [pc] use extension (p=extended-pairs, c=extended-colors)" + ," Either/both extension may be given" #endif }; size_t n; @@ -517,7 +511,7 @@ usage(void) fflush(stdout); for (n = 0; n < SIZEOF(msg); n++) fprintf(stderr, "%s\n", msg[n]); - cleanup(EXIT_FAILURE); + cleanup(ok ? EXIT_SUCCESS : EXIT_FAILURE); } static void @@ -541,7 +535,7 @@ giveup(const char *fmt, ...) fflush(logfp); } - usage(); + usage(FALSE); } /* @@ -1383,7 +1377,6 @@ parse_img(const char *filename) char *t; char *s = t = strchr(buffer, '#'); bool matched = FALSE; - bool blurred = FALSE; if (s != 0) { /* after the "#RGB", there are differences - just ignore */ @@ -1391,6 +1384,7 @@ parse_img(const char *filename) ++s; *++s = '\0'; } + if (match_c(buffer, "%d,%d: (%d,%d,%d,%d) #%x ", &col, &row, @@ -1401,25 +1395,33 @@ parse_img(const char *filename) "%d,%d: (%f%%,%f%%,%f%%,%d) #%x ", &col, &row, &rf, &gf, &bf, &nocolor, + &check) || + match_c(buffer, + "%d,%d: (%f%%,%f%%,%f%%) #%x ", + &col, &row, + &rf, &gf, &bf, &check)) { matched = TRUE; - blurred = TRUE; /* 6.9.11 scaling is broken... */ + #define fp_fix(n) (int) (MaxRGB * (((n) > 100.0 ? 100.0 : (n)) / 100.0)) + r = fp_fix(rf); g = fp_fix(gf); b = fp_fix(bf); } + if ((s - t) > 8) /* 6 hex digits vs 8 */ + check /= 256; if (matched) { int which, c; + int want_r = (check >> 16) & 0xff; + int want_g = (check >> 8) & 0xff; + int want_b = (check >> 0) & 0xff; + +#define fp_err(tst,ref) ((tst > MaxRGB) || ((tst - ref)*(tst - ref)) > 4) - if ((s - t) > 8) /* 6 hex digits vs 8 */ - check /= 256; - if (blurred) { - /* revisit this when ImageMagick is fixed */ - } else if (r > MaxRGB || - g > MaxRGB || - b > MaxRGB || - check != (unsigned) ((r << 16) | (g << 8) | b)) { + if (fp_err(r, want_r) || + fp_err(g, want_g) || + fp_err(b, want_b)) { okay = FALSE; break; } @@ -1519,6 +1521,7 @@ init_display(const char *palette_path, int opt_d) (void) opt_d; if (isatty(fileno(stdout))) { in_curses = TRUE; + setlocale(LC_ALL, ""); initscr(); cbreak(); noecho(); @@ -1714,24 +1717,27 @@ report_colors(PICS_HEAD * pics) } } } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { - int n; + int ch; int opt_d = FALSE; char ignore_ch; const char *palette_path = 0; const char *rgb_path = RGB_PATH; - while ((n = getopt(argc, argv, "a:dLl:p:qr:s:x:")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "a:dLl:p:qr:s:x:")) != -1) { + switch (ch) { 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(); + usage(FALSE); } break; #if HAVE_USE_DEFAULT_COLORS @@ -1771,21 +1777,25 @@ main(int argc, char *argv[]) use_extended_colors = TRUE; break; default: - usage(); + usage(FALSE); break; } } } break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) { char **rgb_data = read_file(rgb_path); + int n; if (rgb_data) rgb_table = parse_rgb(rgb_data); @@ -1818,7 +1828,7 @@ main(int argc, char *argv[]) free(rgb_table); free(all_colors); } else { - usage(); + usage(FALSE); } cleanup(EXIT_SUCCESS);