From dcf5c373ec2141fe58235edadfe13bb4412353c6 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 23 Jan 2008 09:14:58 +0000 Subject: [PATCH] force alpha >= 0xff00 to be fully opaque, fix undocumented #aarrggbb format to work like #rrggbb --- src/rxvttoolkit.C | 21 ++++++++++----------- src/rxvttoolkit.h | 3 +-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/rxvttoolkit.C b/src/rxvttoolkit.C index a1f8bd39..3d6f39de 100644 --- a/src/rxvttoolkit.C +++ b/src/rxvttoolkit.C @@ -675,6 +675,9 @@ insert_component (unsigned int value, unsigned int mask, unsigned int shift) bool rxvt_color::alloc (rxvt_screen *screen, const rgba &color) { + //TODO: only supports 24 bit truecolour + int alpha = color.a >= 0xff00 ? 0xffff : color.a; + #if XFT XRenderPictFormat *format; @@ -688,12 +691,12 @@ rxvt_color::alloc (rxvt_screen *screen, const rgba &color) c.color.red = color.r; c.color.green = color.g; c.color.blue = color.b; - c.color.alpha = color.a; + c.color.alpha = alpha; c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) | insert_component (color.g, format->direct.greenMask, format->direct.green) | insert_component (color.b, format->direct.blueMask , format->direct.blue ) - | insert_component (color.a, format->direct.alphaMask, format->direct.alpha); + | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); return true; } @@ -704,7 +707,7 @@ rxvt_color::alloc (rxvt_screen *screen, const rgba &color) d.red = color.r; d.green = color.g; d.blue = color.b; - d.alpha = color.a; + d.alpha = alpha; return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); } @@ -751,14 +754,10 @@ rxvt_color::set (rxvt_screen *screen, const char *name) // parse the non-standard "#aarrggbb" format if (name[0] == '#' && strlen (name) == 1+2+2+2+2 && 4 == sscanf (name+1, "%2hx%2hx%2hx%2hx%c", &c.a, &c.r, &c.g, &c.b, &eos)) { - if (c.r) - c.r = (c.r << 8) | 0x0ff; - if (c.g) - c.g = (c.g << 8) | 0x0ff; - if (c.b) - c.b = (c.b << 8) | 0x0ff; - if (c.a) - c.a = (c.a << 8) | 0x0ff; + c.r <<= 8; + c.g <<= 8; + c.b <<= 8; + c.a <<= 8; } // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format else if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) diff --git a/src/rxvttoolkit.h b/src/rxvttoolkit.h index 487ded42..d009a9db 100644 --- a/src/rxvttoolkit.h +++ b/src/rxvttoolkit.h @@ -334,8 +334,7 @@ struct rxvt_color bool is_opaque () const { #if XFT - //TODO: only supports 24 bit truecolour - return c.color.alpha < 0xff00; + return c.color.alpha == rgba::MAX_CC; #else return 1; #endif -- 2.34.1