|
Packit |
b749da |
/*
|
|
Packit |
b749da |
* Copyright © 2000 Keith Packard
|
|
Packit |
b749da |
*
|
|
Packit |
b749da |
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
Packit |
b749da |
* documentation for any purpose is hereby granted without fee, provided that
|
|
Packit |
b749da |
* the above copyright notice appear in all copies and that both that
|
|
Packit |
b749da |
* copyright notice and this permission notice appear in supporting
|
|
Packit |
b749da |
* documentation, and that the name of Keith Packard not be used in
|
|
Packit |
b749da |
* advertising or publicity pertaining to distribution of the software without
|
|
Packit |
b749da |
* specific, written prior permission. Keith Packard makes no
|
|
Packit |
b749da |
* representations about the suitability of this software for any purpose. It
|
|
Packit |
b749da |
* is provided "as is" without express or implied warranty.
|
|
Packit |
b749da |
*
|
|
Packit |
b749da |
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
Packit |
b749da |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
Packit |
b749da |
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
Packit |
b749da |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
Packit |
b749da |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
Packit |
b749da |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
Packit |
b749da |
* PERFORMANCE OF THIS SOFTWARE.
|
|
Packit |
b749da |
*/
|
|
Packit |
b749da |
|
|
Packit |
b749da |
#include "xftint.h"
|
|
Packit |
b749da |
|
|
Packit |
b749da |
_X_EXPORT Bool
|
|
Packit |
b749da |
XftColorAllocName (Display *dpy,
|
|
Packit |
b749da |
_Xconst Visual *visual,
|
|
Packit |
b749da |
Colormap cmap,
|
|
Packit |
b749da |
_Xconst char *name,
|
|
Packit |
b749da |
XftColor *result)
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
XColor screen, exact;
|
|
Packit |
b749da |
|
|
Packit |
b749da |
if (!XAllocNamedColor (dpy, cmap, name, &screen, &exact))
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
/* XXX stick standard colormap stuff here */
|
|
Packit |
b749da |
return False;
|
|
Packit |
b749da |
}
|
|
Packit |
b749da |
|
|
Packit |
b749da |
result->pixel = screen.pixel;
|
|
Packit |
b749da |
result->color.red = exact.red;
|
|
Packit |
b749da |
result->color.green = exact.green;
|
|
Packit |
b749da |
result->color.blue = exact.blue;
|
|
Packit |
b749da |
result->color.alpha = 0xffff;
|
|
Packit |
b749da |
return True;
|
|
Packit |
b749da |
}
|
|
Packit |
b749da |
|
|
Packit |
b749da |
static short
|
|
Packit |
b749da |
maskbase (unsigned long m)
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
short i;
|
|
Packit |
b749da |
|
|
Packit |
b749da |
if (!m)
|
|
Packit |
b749da |
return 0;
|
|
Packit |
b749da |
i = 0;
|
|
Packit |
b749da |
while (!(m&1))
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
m>>=1;
|
|
Packit |
b749da |
i++;
|
|
Packit |
b749da |
}
|
|
Packit |
b749da |
return i;
|
|
Packit |
b749da |
}
|
|
Packit |
b749da |
|
|
Packit |
b749da |
static short
|
|
Packit |
b749da |
masklen (unsigned long m)
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
unsigned long y;
|
|
Packit |
b749da |
|
|
Packit |
b749da |
y = (m >> 1) &033333333333;
|
|
Packit |
b749da |
y = m - y - ((y >>1) & 033333333333);
|
|
Packit |
b749da |
return (short) (((y + (y >> 3)) & 030707070707) % 077);
|
|
Packit |
b749da |
}
|
|
Packit |
b749da |
|
|
Packit |
b749da |
_X_EXPORT Bool
|
|
Packit |
b749da |
XftColorAllocValue (Display *dpy,
|
|
Packit |
b749da |
Visual *visual,
|
|
Packit |
b749da |
Colormap cmap,
|
|
Packit |
b749da |
_Xconst XRenderColor *color,
|
|
Packit |
b749da |
XftColor *result)
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
if (visual->class == TrueColor)
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
int red_shift, red_len;
|
|
Packit |
b749da |
int green_shift, green_len;
|
|
Packit |
b749da |
int blue_shift, blue_len;
|
|
Packit |
b749da |
|
|
Packit |
b749da |
red_shift = maskbase (visual->red_mask);
|
|
Packit |
b749da |
red_len = masklen (visual->red_mask);
|
|
Packit |
b749da |
green_shift = maskbase (visual->green_mask);
|
|
Packit |
b749da |
green_len = masklen (visual->green_mask);
|
|
Packit |
b749da |
blue_shift = maskbase (visual->blue_mask);
|
|
Packit |
b749da |
blue_len = masklen (visual->blue_mask);
|
|
Packit |
b749da |
result->pixel = (((color->red >> (16 - red_len)) << red_shift) |
|
|
Packit |
b749da |
((color->green >> (16 - green_len)) << green_shift) |
|
|
Packit |
b749da |
((color->blue >> (16 - blue_len)) << blue_shift));
|
|
Packit |
b749da |
}
|
|
Packit |
b749da |
else
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
XColor xcolor;
|
|
Packit |
b749da |
|
|
Packit |
b749da |
xcolor.red = color->red;
|
|
Packit |
b749da |
xcolor.green = color->green;
|
|
Packit |
b749da |
xcolor.blue = color->blue;
|
|
Packit |
b749da |
if (!XAllocColor (dpy, cmap, &xcolor))
|
|
Packit |
b749da |
return False;
|
|
Packit |
b749da |
result->pixel = xcolor.pixel;
|
|
Packit |
b749da |
}
|
|
Packit |
b749da |
result->color.red = color->red;
|
|
Packit |
b749da |
result->color.green = color->green;
|
|
Packit |
b749da |
result->color.blue = color->blue;
|
|
Packit |
b749da |
result->color.alpha = color->alpha;
|
|
Packit |
b749da |
return True;
|
|
Packit |
b749da |
}
|
|
Packit |
b749da |
|
|
Packit |
b749da |
_X_EXPORT void
|
|
Packit |
b749da |
XftColorFree (Display *dpy,
|
|
Packit |
b749da |
Visual *visual,
|
|
Packit |
b749da |
Colormap cmap,
|
|
Packit |
b749da |
XftColor *color)
|
|
Packit |
b749da |
{
|
|
Packit |
b749da |
if (visual->class != TrueColor)
|
|
Packit |
b749da |
XFreeColors (dpy, cmap, &color->pixel, 1, 0);
|
|
Packit |
b749da |
}
|