force alpha >= 0xff00 to be fully opaque, fix undocumented #aarrggbb format to work...
authorroot <root>
Wed, 23 Jan 2008 09:14:58 +0000 (09:14 +0000)
committerroot <root>
Wed, 23 Jan 2008 09:14:58 +0000 (09:14 +0000)
src/rxvttoolkit.C
src/rxvttoolkit.h

index a1f8bd3..3d6f39d 100644 (file)
@@ -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))
index 487ded4..d009a9d 100644 (file)
@@ -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