Fix colour-model and simplify xloadcols()

Signed-off-by: Christoph Lohmann <20h@r-36.net>
dev
FRIGN 2014-05-22 15:00:33 +02:00 committed by Christoph Lohmann
parent cf890e5bf0
commit 3544e354b2
1 changed files with 21 additions and 37 deletions

54
st.c
View File

@ -340,7 +340,7 @@ typedef struct {
/* Drawing Context */ /* Drawing Context */
typedef struct { typedef struct {
Colour col[LEN(colorname) < 256 ? 256 : LEN(colorname)]; Colour col[MAX(LEN(colorname), 256)];
Font font, bfont, ifont, ibfont; Font font, bfont, ifont, ibfont;
GC gc; GC gc;
} DC; } DC;
@ -2715,7 +2715,7 @@ sixd_to_16bit(int x) {
void void
xloadcols(void) { xloadcols(void) {
int i, r, g, b; int i;
XRenderColor color = { .alpha = 0xffff }; XRenderColor color = { .alpha = 0xffff };
static bool loaded; static bool loaded;
Colour *cp; Colour *cp;
@ -2725,7 +2725,7 @@ xloadcols(void) {
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
} }
/* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */ /* load colours [0-15] and [256-LEN(colorname)] (config.h) */
for(i = 0; i < LEN(colorname); i++) { for(i = 0; i < LEN(colorname); i++) {
if(!colorname[i]) if(!colorname[i])
continue; continue;
@ -2734,27 +2734,20 @@ xloadcols(void) {
} }
} }
/* load colors [16-255] ; same colors as xterm */ /* load colours [16-231] ; same colours as xterm */
for(i = 16, r = 0; r < 6; r++) { for(i = 16; i < 6*6*6+16; i++) {
for(g = 0; g < 6; g++) { color.red = sixd_to_16bit( ((i-16)/36)%6 );
for(b = 0; b < 6; b++) { color.green = sixd_to_16bit( ((i-16)/6) %6 );
color.red = sixd_to_16bit(r); color.blue = sixd_to_16bit( ((i-16)/1) %6 );
color.green = sixd_to_16bit(g); if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i]))
color.blue = sixd_to_16bit(b); die("Could not allocate color %d\n", i);
if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) {
die("Could not allocate color %d\n", i);
}
i++;
}
}
} }
for(r = 0; r < 24; r++, i++) { /* load colours [232-255] ; grayscale */
color.red = color.green = color.blue = 0x0808 + 0x0a0a * r; for(; i < 256; i++) {
if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, color.red = color.green = color.blue = 0x0808 + 0x0a0a * (i-(6*6*6+16));
&dc.col[i])) { if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i]))
die("Could not allocate color %d\n", i); die("Could not allocate color %d\n", i);
}
} }
loaded = true; loaded = true;
} }
@ -3149,22 +3142,13 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
} }
if(base.mode & ATTR_BOLD) { if(base.mode & ATTR_BOLD) {
if(BETWEEN(base.fg, 0, 7)) {
/* basic system colors */
fg = &dc.col[base.fg + 8];
} else if(BETWEEN(base.fg, 16, 195)) {
/* 256 colors */
fg = &dc.col[base.fg + 36];
} else if(BETWEEN(base.fg, 232, 251)) {
/* greyscale */
fg = &dc.col[base.fg + 4];
}
/* /*
* Those ranges will not be brightened: * change basic system colours [0-7]
* 8 - 15 bright system colors * to bright system colours [8-15]
* 196 - 231 highest 256 color cube
* 252 - 255 brightest colors in greyscale
*/ */
if(BETWEEN(base.fg, 0, 7))
fg = &dc.col[base.fg + 8];
font = &dc.bfont; font = &dc.bfont;
frcflags = FRC_BOLD; frcflags = FRC_BOLD;
} }