Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gamma.c @ 90:ee1f71c10889
Fix to allow SDL compiled under XFree v4 to work with XFree v3 xservers.
Contributed by Jarek Sobieszek
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Sat, 07 Jul 2001 08:08:42 +0000 |
parents | 74212992fb08 |
children | a1c973c35fef |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
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. | |
9 | |
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. | |
14 | |
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 | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include "SDL.h" | |
29 #include "SDL_events.h" | |
30 #include "SDL_events_c.h" | |
31 #include "SDL_x11video.h" | |
32 | |
33 /* From the X server sources... */ | |
34 #define MAX_GAMMA 10.0 | |
35 #define MIN_GAMMA (1.0/MAX_GAMMA) | |
36 | |
37 static int X11_SetGammaNoLock(_THIS, float red, float green, float blue) | |
38 { | |
39 #ifdef XFREE86_VMGAMMA | |
90
ee1f71c10889
Fix to allow SDL compiled under XFree v4 to work with XFree v3 xservers.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
40 if (use_vidmode >= 2) { |
0 | 41 XF86VidModeGamma gamma; |
42 Bool succeeded; | |
43 | |
44 /* Clamp the gamma values */ | |
45 if ( red < MIN_GAMMA ) { | |
46 gamma.red = MIN_GAMMA; | |
47 } else | |
48 if ( red > MAX_GAMMA ) { | |
49 gamma.red = MAX_GAMMA; | |
50 } else { | |
51 gamma.red = red; | |
52 } | |
53 if ( green < MIN_GAMMA ) { | |
54 gamma.green = MIN_GAMMA; | |
55 } else | |
56 if ( green > MAX_GAMMA ) { | |
57 gamma.green = MAX_GAMMA; | |
58 } else { | |
59 gamma.green = green; | |
60 } | |
61 if ( blue < MIN_GAMMA ) { | |
62 gamma.blue = MIN_GAMMA; | |
63 } else | |
64 if ( blue > MAX_GAMMA ) { | |
65 gamma.blue = MAX_GAMMA; | |
66 } else { | |
67 gamma.blue = blue; | |
68 } | |
69 if ( SDL_GetAppState() & SDL_APPACTIVE ) { | |
70 succeeded = XVidMode(SetGamma, (SDL_Display, SDL_Screen, &gamma)); | |
71 XSync(SDL_Display, False); | |
72 } else { | |
73 gamma_saved[0] = gamma.red; | |
74 gamma_saved[1] = gamma.green; | |
75 gamma_saved[2] = gamma.blue; | |
76 succeeded = True; | |
77 } | |
78 if ( succeeded ) { | |
79 ++gamma_changed; | |
80 } | |
81 return succeeded ? 0 : -1; | |
82 } | |
83 #endif | |
84 SDL_SetError("Gamma correction not supported"); | |
85 return -1; | |
86 } | |
87 int X11_SetVidModeGamma(_THIS, float red, float green, float blue) | |
88 { | |
89 int result; | |
90 | |
91 SDL_Lock_EventThread(); | |
92 result = X11_SetGammaNoLock(this, red, green, blue); | |
93 SDL_Unlock_EventThread(); | |
94 | |
95 return(result); | |
96 } | |
97 | |
98 static int X11_GetGammaNoLock(_THIS, float *red, float *green, float *blue) | |
99 { | |
100 #ifdef XFREE86_VMGAMMA | |
90
ee1f71c10889
Fix to allow SDL compiled under XFree v4 to work with XFree v3 xservers.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
101 if (use_vidmode >= 2) { |
0 | 102 XF86VidModeGamma gamma; |
103 if (XVidMode(GetGamma, (SDL_Display, SDL_Screen, &gamma))) { | |
104 *red = gamma.red; | |
105 *green = gamma.green; | |
106 *blue = gamma.blue; | |
107 return 0; | |
108 } | |
109 return -1; | |
110 } | |
111 #endif | |
112 SDL_SetError("Gamma correction not supported"); | |
113 return -1; | |
114 } | |
115 int X11_GetVidModeGamma(_THIS, float *red, float *green, float *blue) | |
116 { | |
117 int result; | |
118 | |
119 SDL_Lock_EventThread(); | |
120 result = X11_GetGammaNoLock(this, red, green, blue); | |
121 SDL_Unlock_EventThread(); | |
122 | |
123 return(result); | |
124 } | |
125 | |
126 void X11_SaveVidModeGamma(_THIS) | |
127 { | |
128 /* Try to save the current gamma, otherwise disable gamma control */ | |
129 if ( X11_GetGammaNoLock(this, | |
130 &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]) < 0 ) { | |
131 this->SetGamma = 0; | |
132 this->GetGamma = 0; | |
133 } | |
134 gamma_changed = 0; | |
135 } | |
136 void X11_SwapVidModeGamma(_THIS) | |
137 { | |
138 float new_gamma[3]; | |
139 | |
140 if ( gamma_changed ) { | |
141 new_gamma[0] = gamma_saved[0]; | |
142 new_gamma[1] = gamma_saved[1]; | |
143 new_gamma[2] = gamma_saved[2]; | |
144 X11_GetGammaNoLock(this, &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]); | |
145 X11_SetGammaNoLock(this, new_gamma[0], new_gamma[1], new_gamma[2]); | |
146 } | |
147 } |