parsecolor.c (966B)
1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #include "../x11.h" 5 6 ulong 7 pixelvalue(Window *w, Color *c) { 8 XColor xc; 9 10 if(w->visual == nil || w->visual->class != TrueColor) { 11 if(c->pixel != ~0UL) 12 return c->pixel; 13 xc.red = c->red; 14 xc.green = c->green; 15 xc.blue = c->blue; 16 XAllocColor(display, w->colormap, &xc); 17 return c->pixel = xc.pixel; 18 } 19 if(w->depth == 32 || c->alpha == 0) 20 return (((ulong)c->alpha & 0xff00) << 16) 21 | (((ulong)c->red & 0xff00) << 8) 22 | (((ulong)c->green & 0xff00) << 0) 23 | (((ulong)c->blue & 0xff00) >> 8); 24 else 25 return ((ulong)c->red * 0xffff / c->alpha & 0xff00) << 8 26 | ((ulong)c->green * 0xffff / c->alpha & 0xff00) << 0 27 | ((ulong)c->blue * 0xffff / c->alpha & 0xff00) >> 8; 28 } 29 30 bool 31 parsecolor(const char *name, Color *ret) { 32 ret->pixel = ~0UL; 33 return XRenderParseColor(display, (char*)(uintptr_t)name, (XRenderColor*)ret); 34 }