rebuild geeqie
[oi-userland.git] / components / x11 / xcolor / src / XCrDynCmap.c
blobf872f9e74a60a3787e0f52aa98e08d97c2ae342b
1 /*-
2 * XCrDynCmap.c - X11 library routine to create dynamic colormaps.
4 * Copyright (c) 1990, 2011, Oracle and/or its affiliates. All rights reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
25 * Author: Patrick J. Naughton
26 * naughton@sun.com
30 #include <X11/X.h>
31 #include <X11/Xos.h>
32 #include <X11/Xlib.h>
33 #include <X11/Xutil.h>
34 #include "xcolor.h"
36 Status
37 XCreateDynamicColormap(
38 Display *dsp,
39 int screen,
40 Colormap *cmap, /* return */
41 Visual **visual, /* return */
42 XColor *colors,
43 int count,
44 u_char *red,
45 u_char *green,
46 u_char *blue)
48 XVisualInfo vinfo;
49 unsigned long pixels[256];
50 int i,
51 ncolors,
52 planes;
53 unsigned long pmasks;
54 Status allocReturn;
56 planes = DisplayPlanes(dsp, screen);
57 if (!XMatchVisualInfo(dsp, screen, planes, PseudoColor, &vinfo))
58 if (!XMatchVisualInfo(dsp, screen, planes, GrayScale, &vinfo))
59 if (!XMatchVisualInfo(dsp, screen, planes, DirectColor, &vinfo))
60 return BadMatch;
63 *visual = vinfo.visual;
64 *cmap = XCreateColormap(dsp, RootWindow(dsp, screen),
65 *visual, AllocNone);
66 ncolors = vinfo.colormap_size;
68 if (count > ncolors)
69 return BadValue;
71 allocReturn = XAllocColorCells(dsp, *cmap,
72 False, &pmasks, 0,
73 pixels, ncolors);
75 /* This should return Success, but it doesn't... Xlib bug?
76 * (I'll ignore the return value for now...)
78 #ifdef NOTDEF
79 if (allocReturn != Success)
80 return allocReturn;
81 #endif /* NOTDEF */
83 for (i = 0; i < ncolors - count; i++) {
84 colors[i].pixel = pixels[i];
85 XQueryColor(dsp, DefaultColormap(dsp, screen), &colors[i]);
87 for (i = ncolors - count; i < ncolors; i++) {
88 colors[i].pixel = pixels[i];
89 colors[i].red = *red++ << 8;
90 colors[i].green = *green++ << 8;
91 colors[i].blue = *blue++ << 8;
92 colors[i].flags = DoRed | DoGreen | DoBlue;
94 XStoreColors(dsp, *cmap, colors, ncolors);
95 return Success;