Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gamma.c @ 1922:4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 22 Jul 2006 19:03:31 +0000 |
parents | c121d94672cb |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 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 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 #include "SDL.h" | |
25 #include "SDL_events.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
26 #include "../../events/SDL_events_c.h" |
0 | 27 #include "SDL_x11video.h" |
28 | |
29 /* From the X server sources... */ | |
30 #define MAX_GAMMA 10.0 | |
31 #define MIN_GAMMA (1.0/MAX_GAMMA) | |
32 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
33 static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
34 X11_SetGammaNoLock(_THIS, float red, float green, float blue) |
0 | 35 { |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
36 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
100
a1c973c35fef
Fixed using the video mode extension on older servers
Sam Lantinga <slouken@lokigames.com>
parents:
90
diff
changeset
|
37 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
38 SDL_NAME(XF86VidModeGamma) gamma; |
0 | 39 Bool succeeded; |
40 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
41 /* Clamp the gamma values */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
42 if (red < MIN_GAMMA) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
43 gamma.red = MIN_GAMMA; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
44 } else if (red > MAX_GAMMA) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
45 gamma.red = MAX_GAMMA; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
46 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
47 gamma.red = red; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
48 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
49 if (green < MIN_GAMMA) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
50 gamma.green = MIN_GAMMA; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
51 } else if (green > MAX_GAMMA) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
52 gamma.green = MAX_GAMMA; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
53 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
54 gamma.green = green; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
55 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
56 if (blue < MIN_GAMMA) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
57 gamma.blue = MIN_GAMMA; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
58 } else if (blue > MAX_GAMMA) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
59 gamma.blue = MAX_GAMMA; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
60 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
61 gamma.blue = blue; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
62 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
63 if (SDL_GetAppState() & SDL_APPACTIVE) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
64 succeeded = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
65 SDL_NAME(XF86VidModeSetGamma) (SDL_Display, SDL_Screen, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
66 &gamma); |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
67 XSync(SDL_Display, False); |
0 | 68 } else { |
69 gamma_saved[0] = gamma.red; | |
70 gamma_saved[1] = gamma.green; | |
71 gamma_saved[2] = gamma.blue; | |
72 succeeded = True; | |
73 } | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
74 if (succeeded) { |
0 | 75 ++gamma_changed; |
76 } | |
77 return succeeded ? 0 : -1; | |
78 } | |
79 #endif | |
80 SDL_SetError("Gamma correction not supported"); | |
81 return -1; | |
82 } | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
83 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
84 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
85 X11_SetVidModeGamma(_THIS, float red, float green, float blue) |
0 | 86 { |
87 int result; | |
88 | |
89 SDL_Lock_EventThread(); | |
90 result = X11_SetGammaNoLock(this, red, green, blue); | |
91 SDL_Unlock_EventThread(); | |
92 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
93 return (result); |
0 | 94 } |
95 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
96 static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
97 X11_GetGammaNoLock(_THIS, float *red, float *green, float *blue) |
0 | 98 { |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
99 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
445
98d778ed4abf
Fixed video crash on older XFree86 servers
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
100 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
101 SDL_NAME(XF86VidModeGamma) gamma; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
102 if (SDL_NAME(XF86VidModeGetGamma) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
103 (SDL_Display, SDL_Screen, &gamma)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
104 *red = gamma.red; |
0 | 105 *green = gamma.green; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
106 *blue = gamma.blue; |
0 | 107 return 0; |
108 } | |
109 return -1; | |
110 } | |
111 #endif | |
112 return -1; | |
113 } | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
114 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
115 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
116 X11_GetVidModeGamma(_THIS, float *red, float *green, float *blue) |
0 | 117 { |
118 int result; | |
119 | |
120 SDL_Lock_EventThread(); | |
121 result = X11_GetGammaNoLock(this, red, green, blue); | |
122 SDL_Unlock_EventThread(); | |
123 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
124 return (result); |
0 | 125 } |
126 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
127 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
128 X11_SaveVidModeGamma(_THIS) |
0 | 129 { |
130 /* Try to save the current gamma, otherwise disable gamma control */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
131 if (X11_GetGammaNoLock(this, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
132 &gamma_saved[0], &gamma_saved[1], |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
133 &gamma_saved[2]) < 0) { |
0 | 134 this->SetGamma = 0; |
135 this->GetGamma = 0; | |
136 } | |
137 gamma_changed = 0; | |
138 } | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
139 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
140 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
141 X11_SwapVidModeGamma(_THIS) |
0 | 142 { |
143 float new_gamma[3]; | |
144 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
145 if (gamma_changed) { |
0 | 146 new_gamma[0] = gamma_saved[0]; |
147 new_gamma[1] = gamma_saved[1]; | |
148 new_gamma[2] = gamma_saved[2]; | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
149 X11_GetGammaNoLock(this, &gamma_saved[0], &gamma_saved[1], |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
150 &gamma_saved[2]); |
0 | 151 X11_SetGammaNoLock(this, new_gamma[0], new_gamma[1], new_gamma[2]); |
152 } | |
153 } | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
154 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1575
diff
changeset
|
155 /* vi: set ts=4 sw=4 expandtab: */ |