Introduction
Introduction Statistics Contact Development Disclaimer Help
tAdd RGB color definition - st - [fork] customized build of st, the simple term…
git clone git://src.adamsgaard.dk/st
Log
Files
Refs
README
LICENSE
---
commit 8dde8cde41caa311718d2b990ea3356272ee25ee
parent 33ad83d49213749f4fcec850327f57a33ca8b921
Author: Roberto E. Vargas Caballero <[email protected]>
Date: Fri, 19 Jul 2013 20:34:36 +0200
Add RGB color definition
This patch uses the bit 24 in the color descriptor as an indicator
of RGB color, so we can take the values and generating the XftColour
directly in xdraws.
Diffstat:
M st.c | 119 ++++++++++++++++++++++-------…
1 file changed, 85 insertions(+), 34 deletions(-)
---
diff --git a/st.c b/st.c
t@@ -77,6 +77,13 @@ char *argv0;
#define IS_SET(flag) ((term.mode & (flag)) != 0)
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)…
+#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
+#define IS_TRUECOL(x) (1 << 24 & (x))
+#define TRUERED(x) (((x) & 0xff0000) >> 8)
+#define TRUEGREEN(x) (((x) & 0xff00))
+#define TRUEBLUE(x) (((x) & 0xff) << 8)
+
+
#define VT102ID "\033[?6c"
enum glyph_attribute {
t@@ -158,8 +165,8 @@ typedef unsigned short ushort;
typedef struct {
char c[UTF_SIZ]; /* character code */
uchar mode; /* attribute flags */
- ushort fg; /* foreground */
- ushort bg; /* background */
+ ulong fg; /* foreground */
+ ulong bg; /* background */
} Glyph;
typedef Glyph *Line;
t@@ -354,7 +361,7 @@ static void tsetdirtattr(int);
static void tsetmode(bool, bool, int *, int);
static void tfulldirt(void);
static void techo(char *, int);
-
+static ulong tdefcolor(int *, int *, int);
static inline bool match(uint, uint);
static void ttynew(void);
static void ttyread(void);
t@@ -1618,9 +1625,58 @@ tdeleteline(int n) {
tscrollup(term.c.y, n);
}
+ulong
+tdefcolor(int *attr, int *npar, int l) {
+ long idx = -1;
+ uint r, g, b;
+
+ switch (attr[*npar + 1]) {
+ case 2: /* direct colour in RGB space */
+ if (*npar + 4 >= l) {
+ fprintf(stderr,
+ "erresc(38): Incorrect number of parameters (%…
+ *npar);
+ break;
+ }
+ r = attr[*npar + 2];
+ g = attr[*npar + 3];
+ b = attr[*npar + 4];
+ *npar += 4;
+ if(!BETWEEN(r, 0, 255) || !BETWEEN(g, 0, 255) || !BETWEEN(b, 0…
+ fprintf(stderr, "erresc: bad rgb color (%d,%d,%d)\n",
+ r, g, b);
+ else
+ idx = TRUECOLOR(r, g, b);
+ break;
+ case 5: /* indexed colour */
+ if (*npar + 2 >= l) {
+ fprintf(stderr,
+ "erresc(38): Incorrect number of parameters (%…
+ *npar);
+ break;
+ }
+ *npar += 2;
+ if(!BETWEEN(attr[*npar], 0, 255))
+ fprintf(stderr, "erresc: bad fgcolor %d\n", attr[*npar…
+ else
+ idx = attr[*npar];
+ break;
+ case 0: /* implemented defined (only foreground) */
+ case 1: /* transparent */
+ case 3: /* direct colour in CMY space */
+ case 4: /* direct colour in CMYK space */
+ default:
+ fprintf(stderr,
+ "erresc(38): gfx attr %d unknown\n", attr[*npar]);
+ }
+
+ return idx;
+}
+
void
tsetattr(int *attr, int l) {
int i;
+ ulong idx;
for(i = 0; i < l; i++) {
switch(attr[i]) {
t@@ -1665,39 +1721,15 @@ tsetattr(int *attr, int l) {
term.c.attr.mode &= ~ATTR_REVERSE;
break;
case 38:
- if(i + 2 < l && attr[i + 1] == 5) {
- i += 2;
- if(BETWEEN(attr[i], 0, 255)) {
- term.c.attr.fg = attr[i];
- } else {
- fprintf(stderr,
- "erresc: bad fgcolor %d\n",
- attr[i]);
- }
- } else {
- fprintf(stderr,
- "erresc(38): gfx attr %d unknown\n",
- attr[i]);
- }
+ if ((idx = tdefcolor(attr, &i, l)) >= 0)
+ term.c.attr.fg = idx;
break;
case 39:
term.c.attr.fg = defaultfg;
break;
case 48:
- if(i + 2 < l && attr[i + 1] == 5) {
- i += 2;
- if(BETWEEN(attr[i], 0, 255)) {
- term.c.attr.bg = attr[i];
- } else {
- fprintf(stderr,
- "erresc: bad bgcolor %d\n",
- attr[i]);
- }
- } else {
- fprintf(stderr,
- "erresc(48): gfx attr %d unknown\n",
- attr[i]);
- }
+ if ((idx = tdefcolor(attr, &i, l)) >= 0)
+ term.c.attr.bg = idx;
break;
case 49:
term.c.attr.bg = defaultbg;
t@@ -2916,7 +2948,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, i…
FcPattern *fcpattern, *fontpattern;
FcFontSet *fcsets[] = { NULL };
FcCharSet *fccharset;
- Colour *fg, *bg, *temp, revfg, revbg;
+ Colour *fg, *bg, *temp, revfg, revbg, truefg, truebg;
XRenderColor colfg, colbg;
Rectangle r;
t@@ -2936,8 +2968,27 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, …
if(base.fg == defaultfg)
base.fg = defaultunderline;
}
- fg = &dc.col[base.fg];
- bg = &dc.col[base.bg];
+ if(IS_TRUECOL(base.fg)) {
+ colfg.red = TRUERED(base.fg);
+ colfg.green = TRUEGREEN(base.fg);
+ colfg.blue = TRUEBLUE(base.fg);
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &truefg);
+ fg = &truefg;
+ } else {
+ fg = &dc.col[base.fg];
+ }
+
+ if(IS_TRUECOL(base.bg)) {
+ colbg.green = TRUEGREEN(base.bg);
+ colbg.red = TRUERED(base.bg);
+ colbg.blue = TRUEBLUE(base.bg);
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &truebg);
+ bg = &truebg;
+ } else {
+ bg = &dc.col[base.bg];
+ }
+
+
if(base.mode & ATTR_BOLD) {
if(BETWEEN(base.fg, 0, 7)) {
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.