comparison src/video/Xext/XmuStdCmap/VisCmap.c @ 2185:2032348afed1

This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is available and to keep people form having to install yet another library I have added the essential parts of Xmu in src/video/extensions/XmuStdCmap and an include file in src/video/extensions. The support makes use of standard X11 mechanisms to create color maps and make sure that an application uses the same color map for each window/visual combination. This should make it possible for gamma support to be implemented based on a single color map per application. Hurm... it looks like "make indent" modified a few extra files. Those are getting committed too.
author Bob Pendleton <bob@pendleton.com>
date Thu, 12 Jul 2007 20:00:50 +0000
parents
children
comparison
equal deleted inserted replaced
2184:8f8516e79a13 2185:2032348afed1
1 /* $Xorg: VisCmap.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
2
3 /*
4
5 Copyright 1989, 1998 The Open Group
6
7 Permission to use, copy, modify, distribute, and sell this software and its
8 documentation for any purpose is hereby granted without fee, provided that
9 the above copyright notice appear in all copies and that both that
10 copyright notice and this permission notice appear in supporting
11 documentation.
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23 Except as contained in this notice, the name of The Open Group shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from The Open Group.
26
27 */
28 /* $XFree86: xc/lib/Xmu/VisCmap.c,v 1.6 2001/01/17 19:42:57 dawes Exp $ */
29
30 /*
31 * Author: Donna Converse, MIT X Consortium
32 */
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37 #include <stdio.h>
38 #include <math.h>
39 #include <X11/Xlib.h>
40 #include <X11/Xatom.h>
41 #include <X11/Xutil.h>
42 #include "../extensions/StdCmap.h"
43
44 /*
45 * To create all of the appropriate standard colormaps for a given visual on
46 * a given screen, use XmuVisualStandardColormaps.
47 *
48 * Define all appropriate standard colormap properties for the given visual.
49 * If replace is true, any previous definition will be removed.
50 * If retain is true, new properties will be retained for the duration of
51 * the server session. Return 0 on failure, non-zero on success.
52 * On failure, no new properties will be defined, and, old ones may have
53 * been removed if replace was True.
54 *
55 * Not all standard colormaps are meaningful to all visual classes. This
56 * routine will check and define the following properties for the following
57 * classes, provided that the size of the colormap is not too small.
58 *
59 * DirectColor and PseudoColor
60 * RGB_DEFAULT_MAP
61 * RGB_BEST_MAP
62 * RGB_RED_MAP
63 * RGB_GREEN_MAP
64 * RGB_BLUE_MAP
65 * RGB_GRAY_MAP
66 *
67 * TrueColor and StaticColor
68 * RGB_BEST_MAP
69 *
70 * GrayScale and StaticGray
71 * RGB_GRAY_MAP
72 */
73
74 Status
75 XmuVisualStandardColormaps(Display * dpy, int screen, VisualID visualid,
76 unsigned int depth, Bool replace, Bool retain)
77 /*
78 * dpy - specifies server connection
79 * screen - specifies screen number
80 * visualid - specifies the visual
81 * depth - specifies the visual
82 * replace specifies - whether to replace
83 * retain - specifies whether to retain
84 */
85 {
86 Status status;
87 int n;
88 long vinfo_mask;
89 XVisualInfo vinfo_template, *vinfo;
90
91 status = 0;
92 vinfo_template.screen = screen;
93 vinfo_template.visualid = visualid;
94 vinfo_template.depth = depth;
95 vinfo_mask = VisualScreenMask | VisualIDMask | VisualDepthMask;
96 if ((vinfo =
97 XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL)
98 return 0;
99
100 if (vinfo->colormap_size <= 2) {
101 /* Monochrome visuals have no standard maps; considered successful */
102 XFree((char *) vinfo);
103 return 1;
104 }
105
106 switch (vinfo->class) {
107 case PseudoColor:
108 case DirectColor:
109 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
110 XA_RGB_DEFAULT_MAP, replace,
111 retain);
112 if (!status)
113 break;
114
115 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
116 XA_RGB_GRAY_MAP, replace, retain);
117 if (!status) {
118 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
119 break;
120 }
121
122 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
123 XA_RGB_RED_MAP, replace, retain);
124 if (!status) {
125 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
126 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
127 break;
128 }
129
130 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
131 XA_RGB_GREEN_MAP, replace, retain);
132 if (!status) {
133 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
134 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
135 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
136 break;
137 }
138
139 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
140 XA_RGB_BLUE_MAP, replace, retain);
141 if (!status) {
142 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
143 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
144 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
145 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GREEN_MAP);
146 break;
147 }
148 /* fall through */
149
150 case StaticColor:
151 case TrueColor:
152
153 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
154 XA_RGB_BEST_MAP, replace, retain);
155 if (!status && (vinfo->class == PseudoColor ||
156 vinfo->class == DirectColor)) {
157 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
158 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
159 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
160 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GREEN_MAP);
161 XmuDeleteStandardColormap(dpy, screen, XA_RGB_BLUE_MAP);
162 }
163 break;
164 /* the end for PseudoColor, DirectColor, StaticColor, and TrueColor */
165
166 case GrayScale:
167 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
168 XA_RGB_DEFAULT_MAP, replace,
169 retain);
170 if (!status)
171 break;
172 /*FALLTHROUGH*/ case StaticGray:
173
174 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
175 XA_RGB_GRAY_MAP, replace, retain);
176 if (!status && vinfo->class == GrayScale) {
177 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
178 break;
179 }
180 }
181
182 XFree((char *) vinfo);
183 return status;
184 }