1
/* $Xorg: XRGB.c,v 1.3 2000/08/17 19:45:04 cpqbld Exp $ */
4
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
7
* This file is a component of an X Window System-specific implementation
8
* of Xcms based on the TekColor Color Management System. Permission is
9
* hereby granted to use, copy, modify, sell, and otherwise distribute this
10
* software and its documentation for any purpose and without fee, provided
11
* that this copyright, permission, and disclaimer notice is reproduced in
12
* all copies of this software and in supporting documentation. TekColor
13
* is a trademark of Tektronix, Inc.
15
* Tektronix makes no representation about the suitability of this software
16
* for any purpose. It is provided "as is" and with all faults.
18
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
19
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
21
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
22
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
23
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
24
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
31
* Convert color specifications in XcmsRGB format in one array of
32
* XcmsColor structures to RGB in an array of XColor structures.
36
/* $XFree86: xc/lib/X11/XRGB.c,v 3.3 2001/07/29 05:01:11 tsi Exp $ */
45
static unsigned short const MASK[17] = {
46
0x0000, /* 0 bitsPerRGB */
47
0x8000, /* 1 bitsPerRGB */
48
0xc000, /* 2 bitsPerRGB */
49
0xe000, /* 3 bitsPerRGB */
50
0xf000, /* 4 bitsPerRGB */
51
0xf800, /* 5 bitsPerRGB */
52
0xfc00, /* 6 bitsPerRGB */
53
0xfe00, /* 7 bitsPerRGB */
54
0xff00, /* 8 bitsPerRGB */
55
0xff80, /* 9 bitsPerRGB */
56
0xffc0, /* 10 bitsPerRGB */
57
0xffe0, /* 11 bitsPerRGB */
58
0xfff0, /* 12 bitsPerRGB */
59
0xfff8, /* 13 bitsPerRGB */
60
0xfffc, /* 14 bitsPerRGB */
61
0xfffe, /* 15 bitsPerRGB */
62
0xffff /* 16 bitsPerRGB */
67
/************************************************************************
69
* API PRIVATE ROUTINES *
71
************************************************************************/
75
* _XcmsRGB_to_XColor -
80
_XcmsRGB_to_XColor(pColors, pXColors, nColors)
86
* Translates a color specification in XcmsRGBFormat in a XcmsColor
87
* structure to an XColor structure.
93
for (; nColors--; pXColors++, pColors++) {
94
pXColors->pixel = pColors->pixel;
95
pXColors->red = pColors->spec.RGB.red;
96
pXColors->green = pColors->spec.RGB.green;
97
pXColors->blue = pColors->spec.RGB.blue;
98
pXColors->flags = (DoRed | DoGreen | DoBlue);
110
_XColor_to_XcmsRGB(ccc, pXColors, pColors, nColors)
114
unsigned int nColors;
117
* Translates an RGB color specification in an XColor
118
* structure to an XcmsRGB structure.
120
* IMPORTANT NOTE: Bit replication that may have been caused
121
* with ResolveColor() routine in the X Server is undone
122
* here if requested! For example, if red = 0xcaca and the
123
* bits_per_rgb is 8, then spec.RGB.red will be 0xca00.
129
int bits_per_rgb = ccc->visual->bits_per_rgb;
131
for (; nColors--; pXColors++, pColors++) {
132
pColors->spec.RGB.red = (pXColors->red & MASK[bits_per_rgb]);
133
pColors->spec.RGB.green = (pXColors->green & MASK[bits_per_rgb]);
134
pColors->spec.RGB.blue = (pXColors->blue & MASK[bits_per_rgb]);
135
pColors->format = XcmsRGBFormat;
136
pColors->pixel = pXColors->pixel;
148
_XcmsResolveColor(ccc, pXcmsColor)
150
XcmsColor *pXcmsColor;
153
* Uses the X Server ResolveColor() algorithm to
154
* modify values to closest values supported by hardware.
155
* Old algorithm simply masked low-order bits. The new algorithm
156
* has the effect of replicating significant bits into lower order
157
* bits in order to stretch the hardware value into all 16 bits.
159
* On a display with N-bit DACs, the "hardware" color is computed as:
161
* ((unsignedlong)(ClientValue >> (16-N)) * 0xFFFF) / ((1 << N) - 1)
171
shift = 16 - ccc->visual->bits_per_rgb;
172
max_color = (1 << ccc->visual->bits_per_rgb) - 1;
175
pXcmsColor->spec.RGB.red =
176
((unsigned long)(pXcmsColor->spec.RGB.red >> shift) * 0xFFFF)
178
pXcmsColor->spec.RGB.green =
179
((unsigned long)(pXcmsColor->spec.RGB.green >> shift) * 0xFFFF)
181
pXcmsColor->spec.RGB.blue =
182
((unsigned long)(pXcmsColor->spec.RGB.blue >> shift) * 0xFFFF)
189
* _XcmsUnresolveColor
194
_XcmsUnresolveColor(ccc, pColor)
199
* Masks out insignificant bits.
205
* format == XcmsRGBFormat
208
int bits_per_rgb = ccc->visual->bits_per_rgb;
210
pColor->spec.RGB.red &= MASK[bits_per_rgb];
211
pColor->spec.RGB.green &= MASK[bits_per_rgb];
212
pColor->spec.RGB.blue &= MASK[bits_per_rgb];
223
_XUnresolveColor(ccc, pXColor)
228
* Masks out insignificant bits.
234
int bits_per_rgb = ccc->visual->bits_per_rgb;
236
pXColor->red &= MASK[bits_per_rgb];
237
pXColor->green &= MASK[bits_per_rgb];
238
pXColor->blue &= MASK[bits_per_rgb];