-
Notifications
You must be signed in to change notification settings - Fork 2
/
QueryColor.c
68 lines (52 loc) · 1.38 KB
/
QueryColor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "nxlib.h"
/* convert an X11 pixelval to Microwindows colorval*/
GR_COLOR
_nxColorvalFromPixelval(Display *dpy, unsigned long pixelval)
{
XColor c;
/* convert pixelval to colorval*/
c.pixel = pixelval;
XQueryColor(dpy, _nxDefaultColormap(dpy), &c);
return GR_RGB(c.red >> 8, c.green >> 8, c.blue >> 8);
}
static int
queryColor(Display * display, nxColormap * local, XColor * def)
{
if (def->pixel >= local->cur_color)
return 0;
_nxPixel2RGB(display, local->colorval[def->pixel].value, &def->red,
&def->green, &def->blue);
def->flags |= (DoRed | DoGreen | DoBlue);
return 1;
}
int
XQueryColor(Display * display, Colormap colormap, XColor * def)
{
nxColormap *local;
if (XDefaultVisual(display, 0)->class == TrueColor) {
_nxPixel2RGB(display, def->pixel, &def->red, &def->green,
&def->blue);
return 1;
}
if (!(local = _nxFindColormap(colormap)))
return 0;
return queryColor(display, local, def);
}
int
XQueryColors(Display * display, Colormap colormap, XColor * def_in,
int ncolors)
{
nxColormap *local;
int i;
if (XDefaultVisual(display, 0)->class == TrueColor) {
for (i = 0; i < ncolors; i++)
_nxPixel2RGB(display, def_in[i].pixel, &def_in[i].red,
&def_in[i].green, &def_in[i].blue);
return 1;
}
if (!(local = _nxFindColormap(colormap)))
return 0;
for (i = 0; i < ncolors; i++)
queryColor(display, local, &def_in[i]);
return 1;
}