]> ncurses.scripts.mit.edu Git - ncurses.git/commitdiff
ncurses 6.0 - patch 20170610
authorThomas E. Dickey <dickey@invisible-island.net>
Sun, 11 Jun 2017 01:26:13 +0000 (01:26 +0000)
committerThomas E. Dickey <dickey@invisible-island.net>
Sun, 11 Jun 2017 01:26:13 +0000 (01:26 +0000)
+ 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
VERSION
dist.mk
ncurses/base/lib_mouse.c
package/debian-mingw/changelog
package/debian-mingw64/changelog
package/debian/changelog
package/mingw-ncurses.nsi
package/mingw-ncurses.spec
package/ncurses.spec
test/picsmap.c

diff --git a/NEWS b/NEWS
index e996f092329b113223dc6a3b9a7712082ab025a0..e158c5396ada524987417e7f27b3eeaf4eb4246a 100644 (file)
--- 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 3ec21987b23d411c4589b24429f1755f3d566756..5b6dd1bad6ae513d849f94654868a571a3686883 100644 (file)
--- 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 21f7d7f0015abbf573c0715588eab7b8fa70318e..afbaf93e82c6115be3cd4fb0ab35b46be8a18e1b 100644 (file)
--- 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)
index 161e443d2b8d6a7113af39a9891988cbe2674ff9..01c7195b7d8e740d65c86e7e8aaec0896cd5d651 100644 (file)
@@ -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 <tic.h>
 
@@ -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;
        }
index cdff83f420d3a8c062ea9614c7dc33e15e0c5110..edceaed7e89be90381dfc1947ab2cce30a06f7a0 100644 (file)
@@ -1,8 +1,8 @@
-ncurses6 (6.0+20170603) unstable; urgency=low
+ncurses6 (6.0+20170610) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey <dickey@invisible-island.net>  Mon, 29 May 2017 19:10:42 -0400
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 10 Jun 2017 06:38:19 -0400
 
 ncurses6 (5.9-20131005) unstable; urgency=low
 
index cdff83f420d3a8c062ea9614c7dc33e15e0c5110..edceaed7e89be90381dfc1947ab2cce30a06f7a0 100644 (file)
@@ -1,8 +1,8 @@
-ncurses6 (6.0+20170603) unstable; urgency=low
+ncurses6 (6.0+20170610) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey <dickey@invisible-island.net>  Mon, 29 May 2017 19:10:42 -0400
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 10 Jun 2017 06:38:19 -0400
 
 ncurses6 (5.9-20131005) unstable; urgency=low
 
index d642403d343dbc7081d2885219c3e3591b6ca053..e62bc966d8c7753e080ab32b5c74bd3dc7bbdddb 100644 (file)
@@ -1,8 +1,8 @@
-ncurses6 (6.0+20170603) unstable; urgency=low
+ncurses6 (6.0+20170610) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey <dickey@invisible-island.net>  Mon, 29 May 2017 19:10:42 -0400
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 10 Jun 2017 06:38:19 -0400
 
 ncurses6 (5.9-20120608) unstable; urgency=low
 
index 0bf5494851ff6e58654e18d4712740c547f9ec3d..151e1898ee8f26d7a6206a15bd57e93ae13cba35 100644 (file)
@@ -1,4 +1,4 @@
-; $Id: mingw-ncurses.nsi,v 1.214 2017/05/29 23:10:42 tom Exp $\r
+; $Id: mingw-ncurses.nsi,v 1.215 2017/06/10 10:38:18 tom Exp $\r
 \r
 ; TODO add examples\r
 ; TODO bump ABI to 6\r
@@ -10,7 +10,7 @@
 !define VERSION_MAJOR "6"\r
 !define VERSION_MINOR "0"\r
 !define VERSION_YYYY  "2017"\r
-!define VERSION_MMDD  "0603"\r
+!define VERSION_MMDD  "0610"\r
 !define VERSION_PATCH ${VERSION_YYYY}${VERSION_MMDD}\r
 \r
 !define MY_ABI   "5"\r
index 82783ae240fcbb613d72894ea94468a798ad3d83..08db8d9c626ae64bd08faf8dace96a044302567f 100644 (file)
@@ -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
index cc2f441b439c198313c70ac5df23836792d0e7c9..8a7047891ff5e78d69d3692310d3982cb6c26a97 100644 (file)
@@ -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
index ba8caa426dbcf179ae179bbe146f21b04c09d49a..92e233d7929ff9d2c5ee30829b14f698b54e230d 100644 (file)
@@ -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
  *
  * 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 <test.priv.h>
 
@@ -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;