[Midnightbsd-cvs] src [12320] trunk/sys/teken: sync with FreeBSD 11-stable
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Feb 8 14:46:23 EST 2020
Revision: 12320
http://svnweb.midnightbsd.org/src/?rev=12320
Author: laffer1
Date: 2020-02-08 14:46:22 -0500 (Sat, 08 Feb 2020)
Log Message:
-----------
sync with FreeBSD 11-stable
Modified Paths:
--------------
trunk/sys/teken/demo/Makefile
trunk/sys/teken/demo/teken_demo.c
trunk/sys/teken/libteken/Makefile
trunk/sys/teken/libteken/teken.3
trunk/sys/teken/sequences
trunk/sys/teken/stress/Makefile
trunk/sys/teken/stress/teken_stress.c
trunk/sys/teken/teken.c
trunk/sys/teken/teken.h
trunk/sys/teken/teken_scs.h
trunk/sys/teken/teken_subr.h
trunk/sys/teken/teken_subr_compat.h
Modified: trunk/sys/teken/demo/Makefile
===================================================================
--- trunk/sys/teken/demo/Makefile 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/demo/Makefile 2020-02-08 19:46:22 UTC (rev 12320)
@@ -1,5 +1,5 @@
# $MidnightBSD$
-# $FreeBSD: stable/10/sys/teken/demo/Makefile 226341 2011-10-13 14:20:27Z ed $
+# $FreeBSD: stable/11/sys/teken/demo/Makefile 226341 2011-10-13 14:20:27Z ed $
PROG= teken_demo
LDADD= -lncursesw -lteken -lutil
Modified: trunk/sys/teken/demo/teken_demo.c
===================================================================
--- trunk/sys/teken/demo/teken_demo.c 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/demo/teken_demo.c 2020-02-08 19:46:22 UTC (rev 12320)
@@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: stable/10/sys/teken/demo/teken_demo.c 262861 2014-03-06 18:30:56Z jhb $
+ * $FreeBSD: stable/11/sys/teken/demo/teken_demo.c 286797 2015-08-15 08:29:13Z ed $
*/
#include <sys/ioctl.h>
@@ -38,7 +38,7 @@
#include <unistd.h>
#include <ncurses.h>
-#if defined(__MidnightBSD__)
+#if defined(__FreeBSD__)
#include <libutil.h>
#elif defined(__linux__)
#include <pty.h>
@@ -73,7 +73,7 @@
#define NCOLS 80
#define NROWS 24
-struct pixel buffer[NCOLS][NROWS];
+static struct pixel buffer[NCOLS][NROWS];
static int ptfd;
Modified: trunk/sys/teken/libteken/Makefile
===================================================================
--- trunk/sys/teken/libteken/Makefile 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/libteken/Makefile 2020-02-08 19:46:22 UTC (rev 12320)
@@ -1,5 +1,5 @@
# $MidnightBSD$
-# $FreeBSD: stable/10/sys/teken/libteken/Makefile 221698 2011-05-09 16:27:39Z ed $
+# $FreeBSD: stable/11/sys/teken/libteken/Makefile 221698 2011-05-09 16:27:39Z ed $
LIB= teken
SHLIB_MAJOR= 0
Modified: trunk/sys/teken/libteken/teken.3
===================================================================
--- trunk/sys/teken/libteken/teken.3 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/libteken/teken.3 2020-02-08 19:46:22 UTC (rev 12320)
@@ -23,9 +23,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: stable/10/sys/teken/libteken/teken.3 223574 2011-06-26 18:25:10Z ed $
+.\" $FreeBSD: stable/11/sys/teken/libteken/teken.3 330916 2018-03-14 07:47:26Z eadler $
.\"
-.Dd May 9, 2011
+.Dd Mar 13, 2017
.Dt TEKEN 3
.Os
.Sh NAME
@@ -58,6 +58,8 @@
.Ft const char *
.Fn teken_get_sequence "teken_t *t" "unsigned int id"
.Ft teken_color_t
+.Fn teken_256to16 "teken_color_t color"
+.Ft teken_color_t
.Fn teken_256to8 "teken_color_t color"
.Ft void
.Fn teken_get_defattr_cons25 "teken_t *t" "int *fg" "int *bg"
@@ -164,10 +166,22 @@
any modern applications.
.Pp
The
+.Fn teken_256to16
+function converts an xterm-256 256-color code to an xterm 16-color code
+whose color with default palettes is as similar as possible (not very
+similar).
+The lower 3 bits of the result are the ANSI color and the next lowest
+bit is brightness.
+Other layers (hardare and software) that only support 16 colors can use
+this to avoid knowing the details of 256-color codes.
+.Pp
+The
.Fn teken_256to8
-function converts a color code to one of the 8 primary colors, allowing
-the terminal to be rendered on graphics hardware that only supports 8 or
-16 colors (e.g. VGA).
+function is similar to
+.Fn teken_256to16
+except it converts to an ANSI 8-color code.
+This is more accurate than discarding the brigtness bit in the result of
+.Fn teken_256to16 .
.Pp
The
.Fn teken_get_defattr_cons25
@@ -189,7 +203,7 @@
.Sh SEE ALSO
.Xr ncurses 3 ,
.Xr termcap 3 ,
-.Xr syscons 4 .
+.Xr syscons 4
.Sh HISTORY
The
.Nm
Modified: trunk/sys/teken/sequences
===================================================================
--- trunk/sys/teken/sequences 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/sequences 2020-02-08 19:46:22 UTC (rev 12320)
@@ -23,7 +23,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $FreeBSD: stable/10/sys/teken/sequences 214817 2010-11-05 00:56:21Z ed $
+# $FreeBSD: stable/11/sys/teken/sequences 214817 2010-11-05 00:56:21Z ed $
# $MidnightBSD$
# File format is as follows:
Modified: trunk/sys/teken/stress/Makefile
===================================================================
--- trunk/sys/teken/stress/Makefile 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/stress/Makefile 2020-02-08 19:46:22 UTC (rev 12320)
@@ -1,5 +1,5 @@
# $MidnightBSD$
-# $FreeBSD: stable/10/sys/teken/stress/Makefile 221698 2011-05-09 16:27:39Z ed $
+# $FreeBSD: stable/11/sys/teken/stress/Makefile 221698 2011-05-09 16:27:39Z ed $
PROG= teken_stress
LDADD= -lteken
Modified: trunk/sys/teken/stress/teken_stress.c
===================================================================
--- trunk/sys/teken/stress/teken_stress.c 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/stress/teken_stress.c 2020-02-08 19:46:22 UTC (rev 12320)
@@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: stable/10/sys/teken/stress/teken_stress.c 226100 2011-10-07 12:42:03Z ed $
+ * $FreeBSD: stable/11/sys/teken/stress/teken_stress.c 226100 2011-10-07 12:42:03Z ed $
*/
#include <sys/cdefs.h>
Modified: trunk/sys/teken/teken.c
===================================================================
--- trunk/sys/teken/teken.c 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/teken.c 2020-02-08 19:46:22 UTC (rev 12320)
@@ -24,17 +24,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: stable/10/sys/teken/teken.c 287776 2015-09-14 09:12:28Z ed $
+ * $FreeBSD: stable/11/sys/teken/teken.c 330916 2018-03-14 07:47:26Z eadler $
*/
#include <sys/cdefs.h>
-#if defined(__MidnightBSD__) && defined(_KERNEL)
+#if defined(__FreeBSD__) && defined(_KERNEL)
#include <sys/param.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/systm.h>
#define teken_assert(x) MPASS(x)
-#else /* !(__MidnightBSD__ && _KERNEL) */
+#else /* !(__FreeBSD__ && _KERNEL) */
#include <sys/types.h>
#include <assert.h>
#include <limits.h>
@@ -42,7 +42,7 @@
#include <stdio.h>
#include <string.h>
#define teken_assert(x) assert(x)
-#endif /* __MidnightBSD__ && _KERNEL */
+#endif /* __FreeBSD__ && _KERNEL */
/* debug messages */
#define teken_printf(x,...)
@@ -453,55 +453,203 @@
return (0);
}
+#define k TC_BLACK
+#define b TC_BLUE
+#define y TC_BROWN
+#define c TC_CYAN
+#define g TC_GREEN
+#define m TC_MAGENTA
+#define r TC_RED
+#define w TC_WHITE
+#define K (TC_BLACK | TC_LIGHT)
+#define B (TC_BLUE | TC_LIGHT)
+#define Y (TC_BROWN | TC_LIGHT)
+#define C (TC_CYAN | TC_LIGHT)
+#define G (TC_GREEN | TC_LIGHT)
+#define M (TC_MAGENTA | TC_LIGHT)
+#define R (TC_RED | TC_LIGHT)
+#define W (TC_WHITE | TC_LIGHT)
+
+/**
+ * The xterm-256 color map has steps of 0x28 (in the range 0-0xff), except
+ * for the first step which is 0x5f. Scale to the range 0-6 by dividing
+ * by 0x28 and rounding down. The range of 0-5 cannot represent the
+ * larger first step.
+ *
+ * This table is generated by the follow rules:
+ * - if all components are equal, the result is black for (0, 0, 0) and
+ * (2, 2, 2), else white; otherwise:
+ * - subtract the smallest component from all components
+ * - if this gives only one nonzero component, then that is the color
+ * - else if one component is 2 or more larger than the other nonzero one,
+ * then that component gives the color
+ * - else there are 2 nonzero components. The color is that of a small
+ * equal mixture of these components (cyan, yellow or magenta). E.g.,
+ * (0, 5, 6) (Turquoise2) is a much purer cyan than (0, 2, 3)
+ * (DeepSkyBlue4), but we map both to cyan since we can't represent
+ * delicate shades of either blue or cyan and blue would be worse.
+ * Here it is important that components of 1 never occur. Blue would
+ * be twice as large as green in (0, 1, 2).
+ */
+static const teken_color_t teken_256to8tab[] = {
+ /* xterm normal colors: */
+ k, r, g, y, b, m, c, w,
+
+ /* xterm bright colors: */
+ k, r, g, y, b, m, c, w,
+
+ /* Red0 submap. */
+ k, b, b, b, b, b,
+ g, c, c, b, b, b,
+ g, c, c, c, b, b,
+ g, g, c, c, c, b,
+ g, g, g, c, c, c,
+ g, g, g, g, c, c,
+
+ /* Red2 submap. */
+ r, m, m, b, b, b,
+ y, k, b, b, b, b,
+ y, g, c, c, b, b,
+ g, g, c, c, c, b,
+ g, g, g, c, c, c,
+ g, g, g, g, c, c,
+
+ /* Red3 submap. */
+ r, m, m, m, b, b,
+ y, r, m, m, b, b,
+ y, y, w, b, b, b,
+ y, y, g, c, c, b,
+ g, g, g, c, c, c,
+ g, g, g, g, c, c,
+
+ /* Red4 submap. */
+ r, r, m, m, m, b,
+ r, r, m, m, m, b,
+ y, y, r, m, m, b,
+ y, y, y, w, b, b,
+ y, y, y, g, c, c,
+ g, g, g, g, c, c,
+
+ /* Red5 submap. */
+ r, r, r, m, m, m,
+ r, r, r, m, m, m,
+ r, r, r, m, m, m,
+ y, y, y, r, m, m,
+ y, y, y, y, w, b,
+ y, y, y, y, g, c,
+
+ /* Red6 submap. */
+ r, r, r, r, m, m,
+ r, r, r, r, m, m,
+ r, r, r, r, m, m,
+ r, r, r, r, m, m,
+ y, y, y, y, r, m,
+ y, y, y, y, y, w,
+
+ /* Grey submap. */
+ k, k, k, k, k, k,
+ k, k, k, k, k, k,
+ w, w, w, w, w, w,
+ w, w, w, w, w, w,
+};
+
+/*
+ * This table is generated from the previous one by setting TC_LIGHT for
+ * entries whose luminosity in the xterm256 color map is 60% or larger.
+ * Thus the previous table is currently not really needed. It will be
+ * used for different fine tuning of the tables.
+ */
+static const teken_color_t teken_256to16tab[] = {
+ /* xterm normal colors: */
+ k, r, g, y, b, m, c, w,
+
+ /* xterm bright colors: */
+ K, R, G, Y, B, M, C, W,
+
+ /* Red0 submap. */
+ k, b, b, b, b, b,
+ g, c, c, b, b, b,
+ g, c, c, c, b, b,
+ g, g, c, c, c, b,
+ g, g, g, c, c, c,
+ g, g, g, g, c, c,
+
+ /* Red2 submap. */
+ r, m, m, b, b, b,
+ y, K, b, b, B, B,
+ y, g, c, c, B, B,
+ g, g, c, c, C, B,
+ g, G, G, C, C, C,
+ g, G, G, G, C, C,
+
+ /* Red3 submap. */
+ r, m, m, m, b, b,
+ y, r, m, m, B, B,
+ y, y, w, B, B, B,
+ y, y, G, C, C, B,
+ g, G, G, C, C, C,
+ g, G, G, G, C, C,
+
+ /* Red4 submap. */
+ r, r, m, m, m, b,
+ r, r, m, m, M, B,
+ y, y, R, M, M, B,
+ y, y, Y, W, B, B,
+ y, Y, Y, G, C, C,
+ g, G, G, G, C, C,
+
+ /* Red5 submap. */
+ r, r, r, m, m, m,
+ r, R, R, M, M, M,
+ r, R, R, M, M, M,
+ y, Y, Y, R, M, M,
+ y, Y, Y, Y, W, B,
+ y, Y, Y, Y, G, C,
+
+ /* Red6 submap. */
+ r, r, r, r, m, m,
+ r, R, R, R, M, M,
+ r, R, R, R, M, M,
+ r, R, R, R, M, M,
+ y, Y, Y, Y, R, M,
+ y, Y, Y, Y, Y, W,
+
+ /* Grey submap. */
+ k, k, k, k, k, k,
+ K, K, K, K, K, K,
+ w, w, w, w, w, w,
+ W, W, W, W, W, W,
+};
+
+#undef k
+#undef b
+#undef y
+#undef c
+#undef g
+#undef m
+#undef r
+#undef w
+#undef K
+#undef B
+#undef Y
+#undef C
+#undef G
+#undef M
+#undef R
+#undef W
+
teken_color_t
teken_256to8(teken_color_t c)
{
- unsigned int r, g, b;
- if (c < 16) {
- /* Traditional color indices. */
- return (c % 8);
- } else if (c >= 244) {
- /* Upper grayscale colors. */
- return (TC_WHITE);
- } else if (c >= 232) {
- /* Lower grayscale colors. */
- return (TC_BLACK);
- }
+ return (teken_256to8tab[c % 256]);
+}
- /* Convert to RGB. */
- c -= 16;
- b = c % 6;
- g = (c / 6) % 6;
- r = c / 36;
+teken_color_t
+teken_256to16(teken_color_t c)
+{
- if (r < g) {
- /* Possibly green. */
- if (g < b)
- return (TC_BLUE);
- else if (g > b)
- return (TC_GREEN);
- else
- return (TC_CYAN);
- } else if (r > g) {
- /* Possibly red. */
- if (r < b)
- return (TC_BLUE);
- else if (r > b)
- return (TC_RED);
- else
- return (TC_MAGENTA);
- } else {
- /* Possibly brown. */
- if (g < b)
- return (TC_BLUE);
- else if (g > b)
- return (TC_BROWN);
- else if (r < 3)
- return (TC_BLACK);
- else
- return (TC_WHITE);
- }
+ return (teken_256to16tab[c % 256]);
}
static const char * const special_strings_cons25[] = {
Modified: trunk/sys/teken/teken.h
===================================================================
--- trunk/sys/teken/teken.h 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/teken.h 2020-02-08 19:46:22 UTC (rev 12320)
@@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: stable/10/sys/teken/teken.h 262861 2014-03-06 18:30:56Z jhb $
+ * $FreeBSD: stable/11/sys/teken/teken.h 330916 2018-03-14 07:47:26Z eadler $
*/
#ifndef _TEKEN_H_
@@ -57,6 +57,7 @@
#define TC_CYAN 6
#define TC_WHITE 7
#define TC_NCOLORS 8
+#define TC_LIGHT 8 /* ORed with the others. */
typedef struct {
teken_unit_t tp_row;
@@ -204,6 +205,7 @@
void teken_set_cons25(teken_t *);
/* Color conversion. */
+teken_color_t teken_256to16(teken_color_t);
teken_color_t teken_256to8(teken_color_t);
#endif /* !_TEKEN_H_ */
Modified: trunk/sys/teken/teken_scs.h
===================================================================
--- trunk/sys/teken/teken_scs.h 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/teken_scs.h 2020-02-08 19:46:22 UTC (rev 12320)
@@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: stable/10/sys/teken/teken_scs.h 203659 2010-02-08 09:16:59Z ed $
+ * $FreeBSD: stable/11/sys/teken/teken_scs.h 203659 2010-02-08 09:16:59Z ed $
*/
static inline teken_char_t
Modified: trunk/sys/teken/teken_subr.h
===================================================================
--- trunk/sys/teken/teken_subr.h 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/teken_subr.h 2020-02-08 19:46:22 UTC (rev 12320)
@@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: stable/10/sys/teken/teken_subr.h 287776 2015-09-14 09:12:28Z ed $
+ * $FreeBSD: stable/11/sys/teken/teken_subr.h 287098 2015-08-24 07:49:27Z ed $
*/
static void teken_subr_cursor_up(teken_t *, unsigned int);
Modified: trunk/sys/teken/teken_subr_compat.h
===================================================================
--- trunk/sys/teken/teken_subr_compat.h 2020-02-08 19:43:52 UTC (rev 12319)
+++ trunk/sys/teken/teken_subr_compat.h 2020-02-08 19:46:22 UTC (rev 12320)
@@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: stable/10/sys/teken/teken_subr_compat.h 214817 2010-11-05 00:56:21Z ed $
+ * $FreeBSD: stable/11/sys/teken/teken_subr_compat.h 330916 2018-03-14 07:47:26Z eadler $
*/
static void
@@ -41,8 +41,8 @@
teken_subr_cons25_set_adapter_background(teken_t *t, unsigned int c)
{
- t->t_defattr.ta_bgcolor = cons25_colors[c % 8];
- t->t_curattr.ta_bgcolor = cons25_colors[c % 8];
+ t->t_defattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
+ t->t_curattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
}
static void
@@ -49,15 +49,8 @@
teken_subr_cons25_set_adapter_foreground(teken_t *t, unsigned int c)
{
- t->t_defattr.ta_fgcolor = cons25_colors[c % 8];
- t->t_curattr.ta_fgcolor = cons25_colors[c % 8];
- if (c >= 8) {
- t->t_defattr.ta_format |= TF_BOLD;
- t->t_curattr.ta_format |= TF_BOLD;
- } else {
- t->t_defattr.ta_format &= ~TF_BOLD;
- t->t_curattr.ta_format &= ~TF_BOLD;
- }
+ t->t_defattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
+ t->t_curattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
}
static const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
More information about the Midnightbsd-cvs
mailing list