Initialize Tizen 2.3
[framework/uifw/xorg/lib/libx11.git] / src / LookupCol.c
1 /*
2
3 Copyright 1985, 1998  The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30 #include <stdio.h>
31 #include "Xlibint.h"
32 #include "Xcmsint.h"
33
34
35 Status
36 XLookupColor (
37         register Display *dpy,
38         Colormap cmap,
39         _Xconst char *spec,
40         XColor *def,
41         XColor *scr)
42 {
43         register int n;
44         xLookupColorReply reply;
45         register xLookupColorReq *req;
46         XcmsCCC ccc;
47         XcmsColor cmsColor_exact;
48
49 #ifdef XCMS
50         /*
51          * Let's Attempt to use Xcms and i18n approach to Parse Color
52          */
53         if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
54             const char *tmpName = spec;
55
56             switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact,
57                                             XcmsRGBFormat)) {
58             case XcmsSuccess:
59             case XcmsSuccessWithCompression:
60                 _XcmsRGB_to_XColor(&cmsColor_exact, def, 1);
61                 memcpy((char *)scr, (char *)def, sizeof(XColor));
62                 _XUnresolveColor(ccc, scr);
63                 return(1);
64             case XcmsFailure:
65             case _XCMS_NEWNAME:
66                 /*
67                  * if the result was _XCMS_NEWNAME tmpName points to
68                  * a string in cmsColNm.c:pairs table, for example,
69                  * gray70 would become tekhvc:0.0/70.0/0.0
70                  */
71                 break;
72             }
73         }
74 #endif
75
76         /*
77          * Xcms and i18n methods failed, so lets pass it to the server
78          * for parsing.
79          */
80
81         n = strlen (spec);
82         LockDisplay(dpy);
83         GetReq (LookupColor, req);
84         req->cmap = cmap;
85         req->nbytes = n;
86         req->length += (n + 3) >> 2;
87         Data (dpy, spec, (long)n);
88         if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
89             UnlockDisplay(dpy);
90             SyncHandle();
91             return (0);
92             }
93         def->red   = reply.exactRed;
94         def->green = reply.exactGreen;
95         def->blue  = reply.exactBlue;
96
97         scr->red   = reply.screenRed;
98         scr->green = reply.screenGreen;
99         scr->blue  = reply.screenBlue;
100
101         UnlockDisplay(dpy);
102         SyncHandle();
103         return (1);
104 }