annotate src/video/x11/SDL_x11gamma.c @ 3235:d35b649858e0

David Carre to Sam Hello sam, me again. I'v fixed another bug in the pandora code, it's on the no-X videodriver, i forgot to add some code to destroy the window so it was impossible to reload SDL inside the same application (eglTerminate). You'll find the svn diff attached. See you, David.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 11 Aug 2009 13:45:01 +0000
parents b7197d7e8566
children 4b594623401b
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
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3010
diff changeset
26 /* The size of *all* SDL gamma ramps */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3010
diff changeset
27 #define SDL_GammaRampSize (3 * 256 * sizeof(Uint16))
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3010
diff changeset
28
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
29 static int numCmaps = 0;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
30
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
31 typedef struct
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
32 {
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
33 Display *display;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
34 int scrNum;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
35 Colormap colormap;
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
36 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
37 Uint16 *ramp;
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
38 } cmapTableEntry;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
39
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
40 cmapTableEntry *cmapTable = NULL;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
41
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
42 /* 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
43 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
44 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
45 PseudoColor colormaps. */
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 Colormap
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
48 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
49 {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
50 int i;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
51
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
52 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
53 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
54 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
55 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
56 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
57 }
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 return 0;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
61 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
62
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
63
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
64 void
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
65 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
66 Visual * visual, XColor * ramp)
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
67 {
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
68 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
69 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
70 int ncolors;
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
71
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
72 /* 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
73 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
74 and colormap combination */
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
75 for (i = 0; i < numCmaps; i++) {
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
76 if (cmapTable[i].display == display &&
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
77 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
78 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
79 cmapTable[i].colormap == colormap) {
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
80 return;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
81 }
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
82 }
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
83
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
84 /* 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
85 first entrty */
2221
Sam Lantinga <slouken@libsdl.org>
parents: 2216
diff changeset
86 cmapTable =
Sam Lantinga <slouken@libsdl.org>
parents: 2216
diff changeset
87 SDL_realloc(cmapTable, (numCmaps + 1) * sizeof(cmapTableEntry));
2216
82a133b784c9 changed to use SDL_realloc()
Bob Pendleton <bob@pendleton.com>
parents: 2214
diff changeset
88 if (NULL == cmapTable) {
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
89 SDL_SetError("Out of memory in X11_TrackColormap()");
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
90 return;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
91 }
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
92
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
93 cmapTable[numCmaps].display = display;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
94 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
95 cmapTable[numCmaps].colormap = colormap;
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
96 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
97 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
98
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3010
diff changeset
99 if (ramp != NULL) {
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
100 newramp = SDL_malloc(SDL_GammaRampSize);
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
101 if (NULL == newramp) {
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
102 SDL_SetError("Out of memory in X11_TrackColormap()");
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
103 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
104 }
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
105 SDL_memset(newramp, 0, SDL_GammaRampSize);
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
106 cmapTable[numCmaps].ramp = newramp;
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
107
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
108 ncolors = cmapTable[numCmaps].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
109
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
110 for (i = 0; i < ncolors; i++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
111 newramp[(0 * 256) + i] = ramp[i].red;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
112 newramp[(1 * 256) + i] = ramp[i].green;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
113 newramp[(2 * 256) + i] = ramp[i].blue;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
114 }
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
115 }
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
116
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
117 numCmaps++;
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
118 }
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
119
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
120 /* 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
121 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
122 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
123 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
124 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
125
2162
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
126 int
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
127 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
128 {
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 Visual *visual;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
130 Display *display;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
131 Colormap colormap;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
132 XColor *colorcells;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
133 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
134 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
135 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
136 int i;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
137 int j;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
138
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
139 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
140 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
141 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
142 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
143 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
144 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
145
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
146 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
147 if (NULL == colorcells) {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
148 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
149 return -1;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
150 }
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
151 /* remember the new ramp */
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
152 if (cmapTable[j].ramp == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
153 Uint16 *newramp = SDL_malloc(SDL_GammaRampSize);
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
154 if (NULL == newramp) {
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
155 SDL_SetError("Out of memory in X11_TrackColormap()");
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
156 return -1;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
157 }
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
158 cmapTable[j].ramp = newramp;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
159 }
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3010
diff changeset
160 SDL_memcpy(cmapTable[j].ramp, ramp, SDL_GammaRampSize);
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
161
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
162 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
163 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
164 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
165 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
166 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
167 }
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
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 /* 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
170
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
171 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
172 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
173 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
174 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
175 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
176 }
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
177
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 /* 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
179
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 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
181 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
182 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
183 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 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
185 }
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
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
187 /* 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
188
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
189 /* 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
190 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
191 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
192 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
193 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
194
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
195 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
196 (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
197
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
198 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
199
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
200 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
201
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
202 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
203 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
204 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
205 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
206
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
207 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
208 XFlush(display);
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
209 SDL_free(colorcells);
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 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
212
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
213 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
214 }
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
215
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
216 int
1d23870d8c49 Added stubs for x11 gamma functions and enabled them in SDL_x11video.c
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
217 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
218 {
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
219 int i;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
220
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
221 /* 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
222 ramp */
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
223
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
224 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
225 if (cmapTable[i].visual.class == DirectColor) {
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3010
diff changeset
226 SDL_memcpy(ramp, cmapTable[i].ramp, SDL_GammaRampSize);
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
227 return 0;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
228 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
229 }
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
230
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
231 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
232 }