annotate src/video/x11/SDL_x11gamma.c @ 3039:829043b363d1

Fix fullscreen crash with DirectFB <= 1.2.0
author Couriersud <couriersud@arcor.de>
date Tue, 13 Jan 2009 23:27:08 +0000
parents a6694a812119
children b36579172f27
rev   line source
2162
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
1 /*
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2221
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
2162
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
4
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
9
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
13 Lesser General Public License for more details.
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
14
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
18
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
19 Sam Lantinga
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
20 slouken@libsdl.org
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
21 */
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
22 #include "SDL_config.h"
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
23 #include "../SDL_sysvideo.h"
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
24 #include "SDL_x11video.h"
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
25
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
26 static int numCmaps = 0;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
27
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
28 typedef struct
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
29 {
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
30 Display *display;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
31 int scrNum;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
32 Colormap colormap;
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
33 Visual visual;
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
34 Uint16 *ramp;
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
35 } cmapTableEntry;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
36
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
37 cmapTableEntry *cmapTable = NULL;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
38
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
39 /* To reduce the overhead as much as possible lets do as little as
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
40 possible. When we do have to create a colormap keep track of it and
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
41 reuse it. We're going to do this for both DirectColor and
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
42 PseudoColor colormaps. */
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
43
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
44 Colormap
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
45 X11_LookupColormap(Display * display, int scrNum, VisualID vid)
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
46 {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
47 int i;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
48
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
49 for (i = 0; i < numCmaps; i++) {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
50 if (cmapTable[i].display == display &&
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
51 cmapTable[i].scrNum == scrNum &&
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
52 cmapTable[i].visual.visualid == vid) {
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
53 return cmapTable[i].colormap;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
54 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
55 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
56
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
57 return 0;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
58 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
59
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
60
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
61 void
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
62 X11_TrackColormap(Display * display, int scrNum, Colormap colormap,
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
63 Visual * visual, XColor * ramp)
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
64 {
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
65 int i;
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
66 Uint16 *newramp;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
67 int ncolors;
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
68
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
69 /* search the table to find out if we already have this one. We
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
70 only want one entry for each display, screen number, visualid,
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
71 and colormap combination */
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
72 for (i = 0; i < numCmaps; i++) {
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
73 if (cmapTable[i].display == display &&
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
74 cmapTable[i].scrNum == scrNum &&
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
75 cmapTable[i].visual.visualid == visual->visualid &&
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
76 cmapTable[i].colormap == colormap) {
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
77 return;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
78 }
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
79 }
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
80
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
81 /* increase the table by one entry. If the table is NULL create the
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
82 first entrty */
2221
Sam Lantinga <slouken@libsdl.org>
parents: 2216
diff changeset
83 cmapTable =
Sam Lantinga <slouken@libsdl.org>
parents: 2216
diff changeset
84 SDL_realloc(cmapTable, (numCmaps + 1) * sizeof(cmapTableEntry));
2216
82a133b784c9 changed to use SDL_realloc()
Bob Pendleton <bob@pendleton.com>
parents: 2214
diff changeset
85 if (NULL == cmapTable) {
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
86 SDL_SetError("Out of memory in X11_TrackColormap()");
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
87 return;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
88 }
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
89
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
90 cmapTable[numCmaps].display = display;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
91 cmapTable[numCmaps].scrNum = scrNum;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
92 cmapTable[numCmaps].colormap = colormap;
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
93 SDL_memcpy(&cmapTable[numCmaps].visual, visual, sizeof(Visual));
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
94 cmapTable[numCmaps].ramp = NULL;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
95
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
96 newramp = SDL_malloc(3 * 256 * sizeof(Uint16)); /* The size of *all* SDL gamma ramps */
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
97 if (NULL == newramp) {
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
98 SDL_SetError("Out of memory in X11_TrackColormap()");
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
99 return;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
100 }
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
101 SDL_memset(newramp, 0, sizeof(*newramp));
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
102 cmapTable[numCmaps].ramp = newramp;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
103
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
104 ncolors = cmapTable[numCmaps].visual.map_entries;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
105
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
106 for (i = 0; i < ncolors; i++) {
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
107 newramp[(0 * 256) + i] = ramp[i].red;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
108 newramp[(1 * 256) + i] = ramp[i].green;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
109 newramp[(2 * 256) + i] = ramp[i].blue;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
110 }
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
111
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
112 numCmaps++;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
113 }
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
114
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
115 /* The problem is that you have to have at least one DirectColor
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
116 colormap before you can set the gamma ramps or read the gamma
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
117 ramps. If the application has created a DirectColor window then the
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
118 cmapTable will have at least one colormap in it and everything is
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
119 cool. If not, then we just fail */
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
120
2162
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
121 int
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
122 X11_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
123 {
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
124 Visual *visual;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
125 Display *display;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
126 Colormap colormap;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
127 XColor *colorcells;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
128 int ncolors;
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
129 int rmask, gmask, bmask;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
130 int rshift, gshift, bshift;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
131 int i;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
132 int j;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
133
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
134 for (j = 0; j < numCmaps; j++) {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
135 if (cmapTable[j].visual.class == DirectColor) {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
136 display = cmapTable[j].display;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
137 colormap = cmapTable[j].colormap;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
138 ncolors = cmapTable[j].visual.map_entries;
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
139 visual = &cmapTable[j].visual;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
140
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
141 colorcells = SDL_malloc(ncolors * sizeof(XColor));
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
142 if (NULL == colorcells) {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
143 SDL_SetError("out of memory in X11_SetDisplayGammaRamp");
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
144 return -1;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
145 }
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
146 /* remember the new ramp */
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
147 SDL_memcpy(cmapTable[j].ramp, ramp, sizeof(*cmapTable[j].ramp));
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
148
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
149 rshift = 0;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
150 rmask = visual->red_mask;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
151 while (0 == (rmask & 1)) {
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
152 rshift++;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
153 rmask >>= 1;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
154 }
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
155
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
156 /* printf("rmask = %4x rshift = %4d\n", rmask, rshift); */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
157
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
158 gshift = 0;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
159 gmask = visual->green_mask;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
160 while (0 == (gmask & 1)) {
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
161 gshift++;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
162 gmask >>= 1;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
163 }
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
164
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
165 /* printf("gmask = %4x gshift = %4d\n", gmask, gshift); */
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
166
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
167 bshift = 0;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
168 bmask = visual->blue_mask;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
169 while (0 == (bmask & 1)) {
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
170 bshift++;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
171 bmask >>= 1;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
172 }
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
173
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
174 /* printf("bmask = %4x bshift = %4d\n", bmask, bshift); */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
175
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
176 /* build the color table pixel values */
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
177 for (i = 0; i < ncolors; i++) {
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
178 Uint32 rbits = (rmask * i) / (ncolors - 1);
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
179 Uint32 gbits = (gmask * i) / (ncolors - 1);
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
180 Uint32 bbits = (bmask * i) / (ncolors - 1);
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
181
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
182 Uint32 pix =
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
183 (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
184
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
185 colorcells[i].pixel = pix;
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
186
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
187 colorcells[i].flags = DoRed | DoGreen | DoBlue;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
188
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
189 colorcells[i].red = ramp[(0 * 256) + i];
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
190 colorcells[i].green = ramp[(1 * 256) + i];
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
191 colorcells[i].blue = ramp[(2 * 256) + i];
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
192 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
193
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
194 XStoreColors(display, colormap, colorcells, ncolors);
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
195 XFlush(display);
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
196 SDL_free(colorcells);
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
197 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
198 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
199
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
200 return 0;
2162
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
201 }
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
202
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
203 int
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
204 X11_GetDisplayGammaRamp(_THIS, Uint16 * ramp)
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
205 {
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
206 int i;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
207
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
208 /* find the first DirectColor colormap and use it to get the gamma
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
209 ramp */
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
210
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
211 for (i = 0; i < numCmaps; i++) {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
212 if (cmapTable[i].visual.class == DirectColor) {
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
213 SDL_memcpy(ramp, cmapTable[i].ramp, sizeof(*cmapTable[i].ramp));
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
214 return 0;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
215 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
216 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
217
3010
a6694a812119 Modified and totally untested code to load the color tables for DirectColor and PseudoColor windows.
Bob Pendleton <bob@pendleton.com>
parents: 2859
diff changeset
218 return -1;
2162
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
219 }