From dee978d1ba016c8f327516f684900f95ee7a2b30 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 11 Jun 2017 01:26:13 +0000 Subject: [PATCH] ncurses 6.0 - patch 20170610 + add option "-xp" to picsmap.c, to use init_extended_pair(). + make simple performance fixes for picsmap.c + improve aspect ratio of images read from "convert" in picsmap.c --- NEWS | 7 +- VERSION | 2 +- dist.mk | 4 +- ncurses/base/lib_mouse.c | 13 +- package/debian-mingw/changelog | 4 +- package/debian-mingw64/changelog | 4 +- package/debian/changelog | 4 +- package/mingw-ncurses.nsi | 4 +- package/mingw-ncurses.spec | 2 +- package/ncurses.spec | 2 +- test/picsmap.c | 200 +++++++++++++++++++++++-------- 11 files changed, 173 insertions(+), 73 deletions(-) diff --git a/NEWS b/NEWS index e996f092..e158c539 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.2851 2017/06/03 23:27:40 tom Exp $ +-- $Id: NEWS,v 1.2855 2017/06/10 22:10:46 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -45,6 +45,11 @@ See the AUTHORS file for the corresponding full names. Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20170610 + + add option "-xp" to picsmap.c, to use init_extended_pair(). + + make simple performance fixes for picsmap.c + + improve aspect ratio of images read from "convert" in picsmap.c + 20170603 + add option to picsmap to use color-palette files, e.g., for mapping to xterm-256color. diff --git a/VERSION b/VERSION index 3ec21987..5b6dd1ba 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5:0:9 6.0 20170603 +5:0:9 6.0 20170610 diff --git a/dist.mk b/dist.mk index 21f7d7f0..afbaf93e 100644 --- a/dist.mk +++ b/dist.mk @@ -25,7 +25,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.1166 2017/05/29 23:10:42 tom Exp $ +# $Id: dist.mk,v 1.1167 2017/06/10 10:38:18 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -37,7 +37,7 @@ SHELL = /bin/sh # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 6 NCURSES_MINOR = 0 -NCURSES_PATCH = 20170603 +NCURSES_PATCH = 20170610 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c index 161e443d..01c7195b 100644 --- a/ncurses/base/lib_mouse.c +++ b/ncurses/base/lib_mouse.c @@ -84,7 +84,7 @@ #define CUR SP_TERMTYPE #endif -MODULE_ID("$Id: lib_mouse.c,v 1.173 2017/04/30 01:22:04 tom Exp $") +MODULE_ID("$Id: lib_mouse.c,v 1.174 2017/06/10 23:27:20 tom Exp $") #include @@ -1028,7 +1028,8 @@ decode_X10_bstate(SCREEN *sp, MEVENT * eventp, unsigned intro) static bool decode_xterm_X10(SCREEN *sp, MEVENT * eventp) { - unsigned char kbuf[4]; +#define MAX_KBUF 3 + unsigned char kbuf[MAX_KBUF + 1]; size_t grabbed; int res; bool result; @@ -1039,7 +1040,7 @@ decode_xterm_X10(SCREEN *sp, MEVENT * eventp) # endif _nc_globals.read_thread = pthread_self(); # endif - for (grabbed = 0; grabbed < 3; grabbed += (size_t) res) { + for (grabbed = 0; grabbed < MAX_KBUF; grabbed += (size_t) res) { /* For VIO mouse we add extra bit 64 to disambiguate button-up. */ res = (int) read( @@ -1048,14 +1049,14 @@ decode_xterm_X10(SCREEN *sp, MEVENT * eventp) #else sp->_ifd, #endif - kbuf + grabbed, 3 - grabbed); + kbuf + grabbed, (size_t) (MAX_KBUF - (int) grabbed)); if (res == -1) break; } #if USE_PTHREADS_EINTR _nc_globals.read_thread = 0; #endif - kbuf[3] = '\0'; + kbuf[MAX_KBUF] = '\0'; TR(TRACE_IEVENT, ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf)); @@ -1191,7 +1192,7 @@ read_SGR(SCREEN *sp, SGR_DATA * result) kbuf + grabbed, 1); if (res == -1) break; - if ((grabbed + 3) >= (int) sizeof(kbuf)) { + if ((grabbed + MAX_KBUF) >= (int) sizeof(kbuf)) { result->nerror++; break; } diff --git a/package/debian-mingw/changelog b/package/debian-mingw/changelog index cdff83f4..edceaed7 100644 --- a/package/debian-mingw/changelog +++ b/package/debian-mingw/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.0+20170603) unstable; urgency=low +ncurses6 (6.0+20170610) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Mon, 29 May 2017 19:10:42 -0400 + -- Thomas E. Dickey Sat, 10 Jun 2017 06:38:19 -0400 ncurses6 (5.9-20131005) unstable; urgency=low diff --git a/package/debian-mingw64/changelog b/package/debian-mingw64/changelog index cdff83f4..edceaed7 100644 --- a/package/debian-mingw64/changelog +++ b/package/debian-mingw64/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.0+20170603) unstable; urgency=low +ncurses6 (6.0+20170610) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Mon, 29 May 2017 19:10:42 -0400 + -- Thomas E. Dickey Sat, 10 Jun 2017 06:38:19 -0400 ncurses6 (5.9-20131005) unstable; urgency=low diff --git a/package/debian/changelog b/package/debian/changelog index d642403d..e62bc966 100644 --- a/package/debian/changelog +++ b/package/debian/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.0+20170603) unstable; urgency=low +ncurses6 (6.0+20170610) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Mon, 29 May 2017 19:10:42 -0400 + -- Thomas E. Dickey Sat, 10 Jun 2017 06:38:19 -0400 ncurses6 (5.9-20120608) unstable; urgency=low diff --git a/package/mingw-ncurses.nsi b/package/mingw-ncurses.nsi index 0bf54948..151e1898 100644 --- a/package/mingw-ncurses.nsi +++ b/package/mingw-ncurses.nsi @@ -1,4 +1,4 @@ -; $Id: mingw-ncurses.nsi,v 1.214 2017/05/29 23:10:42 tom Exp $ +; $Id: mingw-ncurses.nsi,v 1.215 2017/06/10 10:38:18 tom Exp $ ; TODO add examples ; TODO bump ABI to 6 @@ -10,7 +10,7 @@ !define VERSION_MAJOR "6" !define VERSION_MINOR "0" !define VERSION_YYYY "2017" -!define VERSION_MMDD "0603" +!define VERSION_MMDD "0610" !define VERSION_PATCH ${VERSION_YYYY}${VERSION_MMDD} !define MY_ABI "5" diff --git a/package/mingw-ncurses.spec b/package/mingw-ncurses.spec index 82783ae2..08db8d9c 100644 --- a/package/mingw-ncurses.spec +++ b/package/mingw-ncurses.spec @@ -3,7 +3,7 @@ Summary: shared libraries for terminal handling Name: mingw32-ncurses6 Version: 6.0 -Release: 20170603 +Release: 20170610 License: X11 Group: Development/Libraries Source: ncurses-%{version}-%{release}.tgz diff --git a/package/ncurses.spec b/package/ncurses.spec index cc2f441b..8a704789 100644 --- a/package/ncurses.spec +++ b/package/ncurses.spec @@ -1,7 +1,7 @@ Summary: shared libraries for terminal handling Name: ncurses6 Version: 6.0 -Release: 20170603 +Release: 20170610 License: X11 Group: Development/Libraries Source: ncurses-%{version}-%{release}.tgz diff --git a/test/picsmap.c b/test/picsmap.c index ba8caa42..92e233d7 100644 --- a/test/picsmap.c +++ b/test/picsmap.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: picsmap.c,v 1.35 2017/06/04 00:20:15 tom Exp $ + * $Id: picsmap.c,v 1.50 2017/06/11 00:37:27 tom Exp $ * * Author: Thomas E. Dickey * @@ -37,11 +37,11 @@ * TODO write picture left-to-right/top-to-bottom * TODO write picture randomly * TODO add one-shot option vs repeat-count before exiting - * TODO add option for init_color - * TODO add option for init_color vs init_extended_color - * TODO add option for init_pair vs alloc_pair + * TODO add option "-xc" for init_color vs init_extended_color + * TODO add option "-xa" for init_pair vs alloc_pair * TODO use pad to allow pictures larger than screen * TODO improve load of image-file's color-table using tsearch. + * TODO add option to just use convert (which can scale) vs builtin xbm/xpm. */ #include @@ -97,19 +97,31 @@ static bool in_curses = FALSE; static RGB_NAME *rgb_table; static RGB_DATA *all_colors; +#if HAVE_ALLOC_PAIR && HAVE_INIT_EXTENDED_COLOR +#define USE_EXTENDED_COLORS 1 +static bool use_extended_pairs = FALSE; +static bool use_extended_colors = FALSE; +#else +#define USE_EXTENDED_COLORS 0 +#endif + static void free_data(char **data) { - free(data[0]); - free(data); + if (data != 0) { + free(data[0]); + free(data); + } } static void free_pics_head(PICS_HEAD * pics) { - free(pics->pairs); - free(pics->cells); - free(pics); + if (pics != 0) { + free(pics->pairs); + free(pics->cells); + free(pics); + } } /* @@ -169,12 +181,15 @@ usage(void) { static const char *msg[] = { - "Usage: picsmap [options] [imagefile [...]]", - "Read/display one or more xbm/xpm files (possibly use \"convert\")", - "", - "Options:", - " -p palette", - " -r rgb-path" + "Usage: picsmap [options] [imagefile [...]]" + ,"Read/display one or more xbm/xpm files (possibly use \"convert\")" + ,"" + ,"Options:" + ," -p palette" + ," -r rgb-path" +#if USE_EXTENDED_COLORS + ," -x [p] use extension (p=init_extended_pair)" +#endif }; size_t n; @@ -205,43 +220,41 @@ static void init_palette(const char *palette_file) { if (palette_file != 0) { + char **data = read_file(palette_file); int cp; all_colors = typeMalloc(RGB_DATA, (unsigned) COLORS); for (cp = 0; cp < COLORS; ++cp) { - color_content(cp, + color_content((short) cp, &all_colors[cp].red, &all_colors[cp].green, &all_colors[cp].blue); - if (palette_file != 0) { - char **data = read_file(palette_file); - if (data != 0) { - int n; - int red, green, blue; - int scale = 1000; - int c; - for (n = 0; data[n] != 0; ++n) { - if (sscanf(data[n], "scale:%d", &c) == 1) { - scale = c; - } else if (sscanf(data[n], "%d:%d %d %d", - &c, - &red, - &green, - &blue) == 4 - && okCOLOR(c) - && okRGB(red) - && okRGB(green) - && okRGB(blue)) { - /* *INDENT-EQLS* */ - all_colors[c].red = ScaledColor(red); - all_colors[c].green = ScaledColor(green); - all_colors[c].blue = ScaledColor(blue); - } - } - free_data(data); + } + if (palette_file != 0 && data != 0) { + int n; + int red, green, blue; + int scale = 1000; + int c; + for (n = 0; data[n] != 0; ++n) { + if (sscanf(data[n], "scale:%d", &c) == 1) { + scale = c; + } else if (sscanf(data[n], "%d:%d %d %d", + &c, + &red, + &green, + &blue) == 4 + && okCOLOR(c) + && okRGB(red) + && okRGB(green) + && okRGB(blue)) { + /* *INDENT-EQLS* */ + all_colors[c].red = ScaledColor(red); + all_colors[c].green = ScaledColor(green); + all_colors[c].blue = ScaledColor(blue); } } } + free_data(data); } else if (COLORS > 1) { /* *INDENT-EQLS* */ int power2 = 1; @@ -252,7 +265,7 @@ init_palette(const char *palette_file) power2 <<= 1; } - if (power2 != COLORS || (shift % 3) != 0) { + if ((power2 != COLORS) || ((shift % 3) != 0)) { giveup("With %d colors, you need a palette-file", COLORS); } } @@ -344,6 +357,15 @@ skip_cs(const char *s) return s; } +static char * +skip_word(char *s) +{ + s = skip_s(s); + while (isgraph(UChar(*s))) + s++; + return s; +} + static int match_c(const char *source, const char *pattern,...) { @@ -677,7 +699,7 @@ parse_xpm(char **data) result->high = num[1]; result->colors = num[2]; result->pairs = typeCalloc(PICS_PAIR, result->colors); - cells = (size_t) (result->wide * result->high); + cells = (result->wide * result->high); result->cells = typeCalloc(PICS_CELL, cells); list = typeCalloc(char *, result->colors); cpp = num[3]; @@ -763,13 +785,38 @@ parse_xpm(char **data) static PICS_HEAD * parse_img(const char *filename) { - char *cmd = malloc(strlen(filename) + 80); + char *cmd = malloc(strlen(filename) + 256); FILE *pp; char buffer[BUFSIZ]; bool failed = FALSE; PICS_HEAD *result = typeCalloc(PICS_HEAD, 1); + int pic_x = 0; + int pic_y = 0; + int width = in_curses ? COLS : 80; + + sprintf(cmd, "identify \"%s\"", filename); + + if ((pp = popen(cmd, "r")) != 0) { + if (fgets(buffer, sizeof(buffer), pp) != 0) { + size_t n = strlen(filename); + if (strlen(buffer) > n && + !strncmp(buffer, filename, n) && + 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; + } else { + pic_x = pic_y = 0; + } + } + pclose(pp); + } + if (pic_x <= 0 || pic_y <= 0) + goto finish; + + sprintf(cmd, "convert -resize %dx%d\\! -thumbnail %dx \"%s\" txt:-", + pic_x, pic_y, width, filename); - sprintf(cmd, "convert -thumbnail %dx \"%s\" txt:-", COLS, filename); if ((pp = popen(cmd, "r")) != 0) { int count = 0; int col = 0; @@ -841,7 +888,10 @@ parse_img(const char *filename) } } which = col + (row * result->wide); - result->cells[which].ch = '#'; /* TODO: space? */ + result->cells[which].ch = ((in_curses || + check == 0xffffff) + ? ' ' + : '#'); result->cells[which].fg = (c < result->colors) ? c : -1; } else { failed = TRUE; @@ -860,6 +910,7 @@ parse_img(const char *filename) } } } + finish: free(cmd); if (failed) { @@ -913,12 +964,22 @@ show_picture(PICS_HEAD * pics) { int y, x; int n; + int my_pair, my_color; if (has_colors()) { for (n = 0; n < pics->colors; ++n) { - init_pair((short) (n + 1), - (short) map_color(pics->pairs[n].fg), - COLOR_BLACK); + my_pair = (n + 1); + my_color = map_color(pics->pairs[n].fg); +#if USE_EXTENDED_COLORS + if (use_extended_pairs) { + init_extended_pair(my_pair, my_color, my_color); + } else +#endif + { + my_pair &= 0x7fff; + my_color &= 0x7fff; + init_pair((short) my_pair, (short) my_color, (short) my_color); + } } attrset(COLOR_PAIR(1)); erase(); @@ -931,8 +992,21 @@ show_picture(PICS_HEAD * pics) if (x >= COLS) break; n = (y * pics->wide + x); - attrset(COLOR_PAIR(pics->cells[n].fg + 1)); - addch((chtype) pics->cells[n].ch); + my_pair = pics->cells[n].fg + 1; +#if USE_EXTENDED_COLORS + if (use_extended_pairs) { + cchar_t temp; + wchar_t wch[2]; + wch[0] = (wchar_t) pics->cells[n].ch; + wch[1] = 0; + setcchar(&temp, wch, A_NORMAL, (short) my_pair, &my_pair); + add_wch(&temp); + } else +#endif + { + attrset(COLOR_PAIR(my_pair)); + addch((chtype) pics->cells[n].ch); + } } } mvgetch(0, 0); @@ -946,7 +1020,7 @@ main(int argc, char *argv[]) const char *palette_path = 0; const char *rgb_path = "/etc/X11/rgb.txt"; - while ((n = getopt(argc, argv, "p:r:")) != -1) { + while ((n = getopt(argc, argv, "p:r:x:")) != -1) { switch (n) { case 'p': palette_path = optarg; @@ -954,6 +1028,26 @@ main(int argc, char *argv[]) case 'r': rgb_path = optarg; break; +#if USE_EXTENDED_COLORS + case 'x': + { + char *s = optarg; + while (*s) { + switch (*s++) { + case 'p': + use_extended_pairs = TRUE; + break; + case 'c': + use_extended_colors = TRUE; + break; + default: + usage(); + break; + } + } + } + break; +#endif default: usage(); break; -- 2.44.0