Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gamma.c @ 410:365f57b7c4ac
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Jun 2002 12:00:34 +0000 |
parents | f6ffac90895c |
children | 98d778ed4abf |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
292
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 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 | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
232
diff
changeset
|
20 slouken@libsdl.org |
0 | 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 | |
100
a1c973c35fef
Fixed using the video mode extension on older servers
Sam Lantinga <slouken@lokigames.com>
parents:
90
diff
changeset
|
40 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
41 SDL_NAME(XF86VidModeGamma) gamma; |
0 | 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 ) { | |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
70 succeeded = SDL_NAME(XF86VidModeSetGamma)(SDL_Display, SDL_Screen, &gamma); |
0 | 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) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
102 SDL_NAME(XF86VidModeGamma) gamma; |
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
103 if (SDL_NAME(XF86VidModeGetGamma)(SDL_Display, SDL_Screen, &gamma)) { |
0 | 104 *red = gamma.red; |
105 *green = gamma.green; | |
106 *blue = gamma.blue; | |
107 return 0; | |
108 } | |
109 return -1; | |
110 } | |
111 #endif | |
112 return -1; | |
113 } | |
114 int X11_GetVidModeGamma(_THIS, float *red, float *green, float *blue) | |
115 { | |
116 int result; | |
117 | |
118 SDL_Lock_EventThread(); | |
119 result = X11_GetGammaNoLock(this, red, green, blue); | |
120 SDL_Unlock_EventThread(); | |
121 | |
122 return(result); | |
123 } | |
124 | |
125 void X11_SaveVidModeGamma(_THIS) | |
126 { | |
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 ) { | |
130 this->SetGamma = 0; | |
131 this->GetGamma = 0; | |
132 } | |
133 gamma_changed = 0; | |
134 } | |
135 void X11_SwapVidModeGamma(_THIS) | |
136 { | |
137 float new_gamma[3]; | |
138 | |
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]); | |
145 } | |
146 } |