2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "SDL_events.h"
30 #include "SDL_events_c.h"
31 #include "SDL_x11video.h"
33 /* From the X server sources... */
34 #define MAX_GAMMA 10.0
35 #define MIN_GAMMA (1.0/MAX_GAMMA)
37 static int X11_SetGammaNoLock(_THIS, float red, float green, float blue)
39 #ifdef XFREE86_VMGAMMA
40 if (use_vidmode >= 200) {
41 SDL_NAME(XF86VidModeGamma) gamma;
44 /* Clamp the gamma values */
45 if ( red < MIN_GAMMA ) {
46 gamma.red = MIN_GAMMA;
48 if ( red > MAX_GAMMA ) {
49 gamma.red = MAX_GAMMA;
53 if ( green < MIN_GAMMA ) {
54 gamma.green = MIN_GAMMA;
56 if ( green > MAX_GAMMA ) {
57 gamma.green = MAX_GAMMA;
61 if ( blue < MIN_GAMMA ) {
62 gamma.blue = MIN_GAMMA;
64 if ( blue > MAX_GAMMA ) {
65 gamma.blue = MAX_GAMMA;
69 if ( SDL_GetAppState() & SDL_APPACTIVE ) {
70 succeeded = SDL_NAME(XF86VidModeSetGamma)(SDL_Display, SDL_Screen, &gamma);
71 XSync(SDL_Display, False);
73 gamma_saved[0] = gamma.red;
74 gamma_saved[1] = gamma.green;
75 gamma_saved[2] = gamma.blue;
81 return succeeded ? 0 : -1;
84 SDL_SetError("Gamma correction not supported");
87 int X11_SetVidModeGamma(_THIS, float red, float green, float blue)
91 SDL_Lock_EventThread();
92 result = X11_SetGammaNoLock(this, red, green, blue);
93 SDL_Unlock_EventThread();
98 static int X11_GetGammaNoLock(_THIS, float *red, float *green, float *blue)
100 #ifdef XFREE86_VMGAMMA
101 if (use_vidmode >= 2) {
102 SDL_NAME(XF86VidModeGamma) gamma;
103 if (SDL_NAME(XF86VidModeGetGamma)(SDL_Display, SDL_Screen, &gamma)) {
105 *green = gamma.green;
114 int X11_GetVidModeGamma(_THIS, float *red, float *green, float *blue)
118 SDL_Lock_EventThread();
119 result = X11_GetGammaNoLock(this, red, green, blue);
120 SDL_Unlock_EventThread();
125 void X11_SaveVidModeGamma(_THIS)
127 /* Try to save the current gamma, otherwise disable gamma control */
128 if ( X11_GetGammaNoLock(this,
129 &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]) < 0 ) {
135 void X11_SwapVidModeGamma(_THIS)
139 if ( gamma_changed ) {
140 new_gamma[0] = gamma_saved[0];
141 new_gamma[1] = gamma_saved[1];
142 new_gamma[2] = gamma_saved[2];
143 X11_GetGammaNoLock(this, &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]);
144 X11_SetGammaNoLock(this, new_gamma[0], new_gamma[1], new_gamma[2]);