[hackers] [wmii] Fix some RGBA color bugs. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sun, 20 Jun 2010 19:59:37 +0000 (UTC)

changeset: 2737:f0a80512c1f4
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Sun Jun 20 15:59:27 2010 -0400
files: alternative_wmiircs/python/pygmi/fs.py lib/libstuff/x11/colors/parsecolor.c lib/libstuff/x11/initdisplay.c
description:
Fix some RGBA color bugs.

diff -r a8d034ae66de -r f0a80512c1f4 alternative_wmiircs/python/pygmi/fs.py
--- a/alternative_wmiircs/python/pygmi/fs.py Sun Jun 20 14:24:04 2010 -0400
+++ b/alternative_wmiircs/python/pygmi/fs.py Sun Jun 20 15:59:27 2010 -0400
@@ -486,10 +486,6 @@
             self._label = label
         if colors is not None:
             self._colors = colors
- try:
- unicode(self._label)
- except:
- print repr(self._label)
         return ' '.join([Color(c).hex for c in self._colors or self.colors] + [unicode(self._label or '')])
 
     colors = property(
diff -r a8d034ae66de -r f0a80512c1f4 lib/libstuff/x11/colors/parsecolor.c
--- a/lib/libstuff/x11/colors/parsecolor.c Sun Jun 20 14:24:04 2010 -0400
+++ b/lib/libstuff/x11/colors/parsecolor.c Sun Jun 20 15:59:27 2010 -0400
@@ -6,7 +6,6 @@
 ulong
 pixelvalue(Window *w, Color *c) {
         XColor xc;
- ulong pixel;
 
         if(w->visual->class != TrueColor) {
                 if(c->pixel != ~0UL)
@@ -17,13 +16,15 @@
                 XAllocColor(display, w->colormap, &xc);
                 return c->pixel = xc.pixel;
         }
- pixel = ((ulong)(c->alpha&0xff00) << 16)
- | ((ulong)(c->red&0xff00) << 8)
- | ((ulong)(c->green&0xff00) << 0)
- | ((ulong)(c->blue&0xff00) >> 8);
- if(w->depth < 32)
- pixel |= 0xffUL << 24;
- return pixel;
+ if(w->depth == 32 || c->alpha == 0)
+ return (((ulong)c->alpha & 0xff00) << 16)
+ | (((ulong)c->red & 0xff00) << 8)
+ | (((ulong)c->green & 0xff00) << 0)
+ | (((ulong)c->blue & 0xff00) >> 8);
+ else
+ return ((ulong)c->red * 0xffff / c->alpha & 0xff00) << 8
+ | ((ulong)c->green * 0xffff / c->alpha & 0xff00) << 0
+ | ((ulong)c->blue * 0xffff / c->alpha & 0xff00) >> 8;
 }
 
 bool
diff -r a8d034ae66de -r f0a80512c1f4 lib/libstuff/x11/initdisplay.c
--- a/lib/libstuff/x11/initdisplay.c Sun Jun 20 14:24:04 2010 -0400
+++ b/lib/libstuff/x11/initdisplay.c Sun Jun 20 15:59:27 2010 -0400
@@ -22,10 +22,12 @@
 Lfmt(Fmt *f) {
         Color c;
 
+#define fix(c, m) (ushort)((c.alpha ? ((ulong)c.m * 0xffff) / c.alpha : 0) >> 8)
         c = va_arg(f->args, Color);
         return fmtprint(f, c.alpha < 0xff00 ? "rgba:%02uhx/%02uhx/%02uhx/%02uhx"
                                             : "#%02uhx%02uhx%02uhx",
- c.red >> 8, c.green >> 8, c.blue >> 8, c.alpha >> 8);
+ fix(c, red), fix(c, green), fix(c, blue), c.alpha >> 8);
+#undef fix
 }
 
 static int
Received on Sun Jun 20 2010 - 19:59:37 UTC

This archive was generated by hypermail 2.2.0 : Sun Jun 20 2010 - 20:00:09 UTC