3 * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
6 * This file is a component of an X Window System-specific implementation
7 * of Xcms based on the TekColor Color Management System. Permission is
8 * hereby granted to use, copy, modify, sell, and otherwise distribute this
9 * software and its documentation for any purpose and without fee, provided
10 * that this copyright, permission, and disclaimer notice is reproduced in
11 * all copies of this software and in supporting documentation. TekColor
12 * is a trademark of Tektronix, Inc.
14 * Tektronix makes no representation about the suitability of this software
15 * for any purpose. It is provided "as is" and with all faults.
17 * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
18 * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19 * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
20 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21 * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
22 * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23 * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
30 * Source for XcmsAllocNamedColor
46 * XcmsAllocNamedColor -
54 _Xconst char *colorname,
55 XcmsColor *pColor_scrn_return,
56 XcmsColor *pColor_exact_return,
57 XcmsColorFormat result_format)
60 * Finds the color specification associated with the color
61 * name in the Device-Independent Color Name Database, then
62 * converts that color specification to an RGB format. This
63 * RGB value is then used in a call to XAllocColor to allocate
64 * a read-only color cell.
67 * 0 if failed to parse string or find any entry in the database.
68 * 1 if succeeded in converting color name to XcmsColor.
69 * 2 if succeeded in converting color name to another color name.
74 xAllocNamedColorReply rep;
75 xAllocNamedColorReq *req;
79 Status retval2 = XcmsSuccess;
85 * 0. Check for invalid arguments.
87 if (dpy == NULL || colorname[0] == '\0' || pColor_scrn_return == 0
88 || pColor_exact_return == NULL) {
92 if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) {
97 * 1. Convert string to a XcmsColor using Xcms and i18n mechanism
99 if ((retval1 = _XcmsResolveColorString(ccc, &colorname,
100 &tmpColor, result_format)) == XcmsFailure) {
103 if (retval1 == _XCMS_NEWNAME) {
106 memcpy((char *)pColor_exact_return, (char *)&tmpColor, sizeof(XcmsColor));
109 * 2. Convert tmpColor to RGB
110 * Assume pColor_exact_return is now adjusted to Client White Point
112 if ((retval2 = XcmsConvertColors(ccc, &tmpColor,
113 1, XcmsRGBFormat, (Bool *) NULL)) == XcmsFailure) {
118 * 3. Convert to XColor and call XAllocColor
120 _XcmsRGB_to_XColor(&tmpColor, &XColor_in_out, 1);
121 if (XAllocColor(ccc->dpy, cmap, &XColor_in_out) == 0) {
126 * 4. pColor_scrn_return
128 * Now convert to the target format.
129 * We can ignore the return value because we're already in a
130 * device-dependent format.
132 _XColor_to_XcmsRGB(ccc, &XColor_in_out, pColor_scrn_return, 1);
133 if (result_format != XcmsRGBFormat) {
134 if (result_format == XcmsUndefinedFormat) {
135 result_format = pColor_exact_return->format;
137 if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
138 (Bool *) NULL) == XcmsFailure) {
143 return(retval1 > retval2 ? retval1 : retval2);
147 * All previous methods failed, so lets pass it to the server
152 GetReq(AllocNamedColor, req);
155 nbytes = req->nbytes = strlen(colorname);
156 req->length += (nbytes + 3) >> 2; /* round up to mult of 4 */
158 _XSend(dpy, colorname, nbytes);
159 /* _XSend is more efficient that Data, since _XReply follows */
161 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
167 exact_def.red = rep.exactRed;
168 exact_def.green = rep.exactGreen;
169 exact_def.blue = rep.exactBlue;
171 hard_def.red = rep.screenRed;
172 hard_def.green = rep.screenGreen;
173 hard_def.blue = rep.screenBlue;
175 exact_def.pixel = hard_def.pixel = rep.pixel;
181 * Now convert to the target format.
183 _XColor_to_XcmsRGB(ccc, &exact_def, pColor_exact_return, 1);
184 _XColor_to_XcmsRGB(ccc, &hard_def, pColor_scrn_return, 1);
185 if (result_format != XcmsRGBFormat
186 && result_format != XcmsUndefinedFormat) {
187 if (XcmsConvertColors(ccc, pColor_exact_return, 1, result_format,
188 (Bool *) NULL) == XcmsFailure) {
191 if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
192 (Bool *) NULL) == XcmsFailure) {