[PATCH] Fix colour-model and simplify xloadcols()

From: FRIGN <dev_AT_frign.de>
Date: Thu, 22 May 2014 15:00:33 +0200

---
 st.c | 56 ++++++++++++++++++++------------------------------------
 1 file changed, 20 insertions(+), 36 deletions(-)
diff --git a/st.c b/st.c
index 78d8a01..a6b4ada 100644
--- a/st.c
+++ b/st.c
_AT_@ -340,7 +340,7 @@ typedef struct {
=20
 /* Drawing Context */
 typedef struct {
-	Colour col[LEN(colorname) < 256 ? 256 : LEN(colorname)];
+	Colour col[MAX(LEN(colorname), 256)];
 	Font font, bfont, ifont, ibfont;
 	GC gc;
 } DC;
_AT_@ -2715,7 +2715,7 @@ sixd_to_16bit(int x) {
=20
 void
 xloadcols(void) {
-	int i, r, g, b;
+	int i;
 	XRenderColor color =3D { .alpha =3D 0xffff };
 	static bool loaded;
 	Colour *cp;
_AT_@ -2725,7 +2725,7 @@ xloadcols(void) {
 			XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
 	}
=20
-	/* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */
+	/* load colours [0-15] and [256-LEN(colorname)] (config.h) */
 	for(i =3D 0; i < LEN(colorname); i++) {
 		if(!colorname[i])
 			continue;
_AT_@ -2734,27 +2734,20 @@ xloadcols(void) {
 		}
 	}
=20
-	/* load colors [16-255] ; same colors as xterm */
-	for(i =3D 16, r =3D 0; r < 6; r++) {
-		for(g =3D 0; g < 6; g++) {
-			for(b =3D 0; b < 6; b++) {
-				color.red =3D sixd_to_16bit(r);
-				color.green =3D sixd_to_16bit(g);
-				color.blue =3D sixd_to_16bit(b);
-				if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) {
-					die("Could not allocate color %d\n", i);
-				}
-				i++;
-			}
-		}
+	/* load colours [16-231] ; same colours as xterm */
+	for(i =3D 16; i < 6*6*6+16; i++) {
+		color.red   =3D sixd_to_16bit( ((i-16)/36)%6 );
+		color.green =3D sixd_to_16bit( ((i-16)/6) %6 );
+		color.blue  =3D sixd_to_16bit( ((i-16)/1) %6 );
+		if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i]))
+			die("Could not allocate color %d\n", i);
 	}
-
-	for(r =3D 0; r < 24; r++, i++) {
-		color.red =3D color.green =3D color.blue =3D 0x0808 + 0x0a0a * r;
-		if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color,
-					&dc.col[i])) {
+=09
+	/* load colours [232-255] ; grayscale */
+	for(; i < 256; i++) {
+		color.red =3D color.green =3D color.blue =3D 0x0808 + 0x0a0a * (i-(6*6*6=
+16));
+		if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i]))
 			die("Could not allocate color %d\n", i);
-		}
 	}
 	loaded =3D true;
 }
_AT_@ -3149,22 +3142,13 @@ xdraws(char *s, Glyph base, int x, int y, int charl=
en, int bytelen) {
 	}
=20
 	if(base.mode & ATTR_BOLD) {
-		if(BETWEEN(base.fg, 0, 7)) {
-			/* basic system colors */
-			fg =3D &dc.col[base.fg + 8];
-		} else if(BETWEEN(base.fg, 16, 195)) {
-			/* 256 colors */
-			fg =3D &dc.col[base.fg + 36];
-		} else if(BETWEEN(base.fg, 232, 251)) {
-			/* greyscale */
-			fg =3D &dc.col[base.fg + 4];
-		}
 		/*
-		 * Those ranges will not be brightened:
-		 *    8 - 15 =E2=80=93 bright system colors
-		 *    196 - 231 =E2=80=93 highest 256 color cube
-		 *    252 - 255 =E2=80=93 brightest colors in greyscale
+		 * change basic system colours [0-7]=20
+		 * to bright system colours [8-15]
 		 */
+		if(BETWEEN(base.fg, 0, 7))
+			fg =3D &dc.col[base.fg + 8];
+	=09
 		font =3D &dc.bfont;
 		frcflags =3D FRC_BOLD;
 	}
--=20
1.8.3.2
--Multipart=_Thu__22_May_2014_15_03_21_+0200_.8QaHVePpW.jnYbQ--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Thu May 22 2014 - 17:48:03 CEST