diff options
author | FRIGN <dev@frign.de> | 2014-05-22 15:00:33 +0200 |
---|---|---|
committer | Christoph Lohmann <20h@r-36.net> | 2014-05-24 13:47:00 +0200 |
commit | 3544e354b2dcdfcced1a2f4aeedb4d479abd543c (patch) | |
tree | 2f6990de957406c94228d82fa6a2f27dbd98a3de | |
parent | cf890e5bf06a65a35fe195aa1ef8ae3e1eb55f51 (diff) | |
download | st-3544e354b2dcdfcced1a2f4aeedb4d479abd543c.tar.gz st-3544e354b2dcdfcced1a2f4aeedb4d479abd543c.zip |
Fix colour-model and simplify xloadcols()
Signed-off-by: Christoph Lohmann <20h@r-36.net>
-rw-r--r-- | st.c | 56 |
1 files changed, 20 insertions, 36 deletions
@@ -340,7 +340,7 @@ typedef struct { | |||
340 | 340 | ||
341 | /* Drawing Context */ | 341 | /* Drawing Context */ |
342 | typedef struct { | 342 | typedef struct { |
343 | Colour col[LEN(colorname) < 256 ? 256 : LEN(colorname)]; | 343 | Colour col[MAX(LEN(colorname), 256)]; |
344 | Font font, bfont, ifont, ibfont; | 344 | Font font, bfont, ifont, ibfont; |
345 | GC gc; | 345 | GC gc; |
346 | } DC; | 346 | } DC; |
@@ -2715,7 +2715,7 @@ sixd_to_16bit(int x) { | |||
2715 | 2715 | ||
2716 | void | 2716 | void |
2717 | xloadcols(void) { | 2717 | xloadcols(void) { |
2718 | int i, r, g, b; | 2718 | int i; |
2719 | XRenderColor color = { .alpha = 0xffff }; | 2719 | XRenderColor color = { .alpha = 0xffff }; |
2720 | static bool loaded; | 2720 | static bool loaded; |
2721 | Colour *cp; | 2721 | Colour *cp; |
@@ -2725,7 +2725,7 @@ xloadcols(void) { | |||
2725 | XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); | 2725 | XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); |
2726 | } | 2726 | } |
2727 | 2727 | ||
2728 | /* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */ | 2728 | /* load colours [0-15] and [256-LEN(colorname)] (config.h) */ |
2729 | for(i = 0; i < LEN(colorname); i++) { | 2729 | for(i = 0; i < LEN(colorname); i++) { |
2730 | if(!colorname[i]) | 2730 | if(!colorname[i]) |
2731 | continue; | 2731 | continue; |
@@ -2734,27 +2734,20 @@ xloadcols(void) { | |||
2734 | } | 2734 | } |
2735 | } | 2735 | } |
2736 | 2736 | ||
2737 | /* load colors [16-255] ; same colors as xterm */ | 2737 | /* load colours [16-231] ; same colours as xterm */ |
2738 | for(i = 16, r = 0; r < 6; r++) { | 2738 | for(i = 16; i < 6*6*6+16; i++) { |
2739 | for(g = 0; g < 6; g++) { | 2739 | color.red = sixd_to_16bit( ((i-16)/36)%6 ); |
2740 | for(b = 0; b < 6; b++) { | 2740 | color.green = sixd_to_16bit( ((i-16)/6) %6 ); |
2741 | color.red = sixd_to_16bit(r); | 2741 | color.blue = sixd_to_16bit( ((i-16)/1) %6 ); |
2742 | color.green = sixd_to_16bit(g); | 2742 | if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) |
2743 | color.blue = sixd_to_16bit(b); | 2743 | die("Could not allocate color %d\n", i); |
2744 | if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) { | ||
2745 | die("Could not allocate color %d\n", i); | ||
2746 | } | ||
2747 | i++; | ||
2748 | } | ||
2749 | } | ||
2750 | } | 2744 | } |
2751 | 2745 | ||
2752 | for(r = 0; r < 24; r++, i++) { | 2746 | /* load colours [232-255] ; grayscale */ |
2753 | color.red = color.green = color.blue = 0x0808 + 0x0a0a * r; | 2747 | for(; i < 256; i++) { |
2754 | if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, | 2748 | color.red = color.green = color.blue = 0x0808 + 0x0a0a * (i-(6*6*6+16)); |
2755 | &dc.col[i])) { | 2749 | if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) |
2756 | die("Could not allocate color %d\n", i); | 2750 | die("Could not allocate color %d\n", i); |
2757 | } | ||
2758 | } | 2751 | } |
2759 | loaded = true; | 2752 | loaded = true; |
2760 | } | 2753 | } |
@@ -3149,22 +3142,13 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { | |||
3149 | } | 3142 | } |
3150 | 3143 | ||
3151 | if(base.mode & ATTR_BOLD) { | 3144 | if(base.mode & ATTR_BOLD) { |
3152 | if(BETWEEN(base.fg, 0, 7)) { | ||
3153 | /* basic system colors */ | ||
3154 | fg = &dc.col[base.fg + 8]; | ||
3155 | } else if(BETWEEN(base.fg, 16, 195)) { | ||
3156 | /* 256 colors */ | ||
3157 | fg = &dc.col[base.fg + 36]; | ||
3158 | } else if(BETWEEN(base.fg, 232, 251)) { | ||
3159 | /* greyscale */ | ||
3160 | fg = &dc.col[base.fg + 4]; | ||
3161 | } | ||
3162 | /* | 3145 | /* |
3163 | * Those ranges will not be brightened: | 3146 | * change basic system colours [0-7] |
3164 | * 8 - 15 – bright system colors | 3147 | * to bright system colours [8-15] |
3165 | * 196 - 231 – highest 256 color cube | ||
3166 | * 252 - 255 – brightest colors in greyscale | ||
3167 | */ | 3148 | */ |
3149 | if(BETWEEN(base.fg, 0, 7)) | ||
3150 | fg = &dc.col[base.fg + 8]; | ||
3151 | |||
3168 | font = &dc.bfont; | 3152 | font = &dc.bfont; |
3169 | frcflags = FRC_BOLD; | 3153 | frcflags = FRC_BOLD; |
3170 | } | 3154 | } |