comparison src/video/SDL_gamma.c @ 3500:4b594623401b

Work in progress on multi-display support: * Added display parameter to many internal functions so video modes can be set on displays that aren't the public current one. * The fullscreen mode is associated with fullscreen windows - not displays, so different windows more naturally have a mode associated with them based on their width and height. It's no longer necessary to specify a fullscreen mode, a default one will be picked automatically for fullscreen windows.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Dec 2009 05:57:15 +0000
parents 62d4992e5a92
children 64ce267332c6
comparison
equal deleted inserted replaced
3499:4cf8a1423d57 3500:4b594623401b
111 CalculateGammaFromRamp(blue, ramp[2]); 111 CalculateGammaFromRamp(blue, ramp[2]);
112 } 112 }
113 return succeeded; 113 return succeeded;
114 } 114 }
115 115
116 int 116 static void
117 SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, 117 SDL_UninitializedVideo()
118 const Uint16 * blue) 118 {
119 SDL_SetError("Video subsystem has not been initialized");
120 }
121
122 int
123 SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue)
119 { 124 {
120 SDL_VideoDevice *_this = SDL_GetVideoDevice(); 125 SDL_VideoDevice *_this = SDL_GetVideoDevice();
121 int succeeded; 126 int succeeded;
122 127
128 if (!_this) {
129 SDL_UninitializedVideo();
130 return -1;
131 }
132
123 /* Lazily allocate the gamma tables */ 133 /* Lazily allocate the gamma tables */
124 if (!SDL_CurrentDisplay.gamma) { 134 if (!display->gamma) {
125 SDL_GetGammaRamp(NULL, NULL, NULL); 135 if (SDL_GetGammaRampForDisplay(display, NULL, NULL, NULL) < 0) {
136 return -1;
137 }
126 } 138 }
127 139
128 /* Fill the gamma table with the new values */ 140 /* Fill the gamma table with the new values */
129 if (red) { 141 if (red) {
130 SDL_memcpy(&SDL_CurrentDisplay.gamma[0 * 256], red, 142 SDL_memcpy(&display->gamma[0 * 256], red, 256 * sizeof(*display->gamma));
131 256 * sizeof(*SDL_CurrentDisplay.gamma));
132 } 143 }
133 if (green) { 144 if (green) {
134 SDL_memcpy(&SDL_CurrentDisplay.gamma[1 * 256], green, 145 SDL_memcpy(&display->gamma[1 * 256], green, 256 * sizeof(*display->gamma));
135 256 * sizeof(*SDL_CurrentDisplay.gamma));
136 } 146 }
137 if (blue) { 147 if (blue) {
138 SDL_memcpy(&SDL_CurrentDisplay.gamma[2 * 256], blue, 148 SDL_memcpy(&display->gamma[2 * 256], blue, 256 * sizeof(*display->gamma));
139 256 * sizeof(*SDL_CurrentDisplay.gamma));
140 } 149 }
141 150
142 /* Try to set the gamma ramp in the driver */ 151 /* Try to set the gamma ramp in the driver */
143 succeeded = -1; 152 succeeded = -1;
144 if (_this && _this->SetDisplayGammaRamp) { 153 if (_this && _this->SetDisplayGammaRamp) {
145 if (SDL_GetFocusWindow()) { 154 if (SDL_GetFocusWindow()) {
146 succeeded = 155 succeeded =
147 _this->SetDisplayGammaRamp(_this, SDL_CurrentDisplay.gamma); 156 _this->SetDisplayGammaRamp(_this, display, display->gamma);
148 } else { 157 } else {
149 succeeded = 0; 158 succeeded = 0;
150 } 159 }
151 } else { 160 } else {
152 SDL_SetError("Gamma ramp manipulation not supported"); 161 SDL_SetError("Gamma ramp manipulation not supported");
153 } 162 }
154 return succeeded; 163 return succeeded;
155 } 164 }
156 165
157 int 166 int
158 SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue) 167 SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue)
159 { 168 {
160 SDL_VideoDevice *_this = SDL_GetVideoDevice(); 169 SDL_VideoDevice *_this = SDL_GetVideoDevice();
170 if (!_this) {
171 SDL_UninitializedVideo();
172 return -1;
173 }
174 return SDL_SetGammaRampForDisplay(&SDL_CurrentDisplay, red, green, blue);
175 }
176
177 int
178 SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue)
179 {
180 SDL_VideoDevice *_this = SDL_GetVideoDevice();
181
182 if (!_this) {
183 SDL_UninitializedVideo();
184 return -1;
185 }
161 186
162 /* Lazily allocate the gamma table */ 187 /* Lazily allocate the gamma table */
163 if (!SDL_CurrentDisplay.gamma) { 188 if (!display->gamma) {
164 size_t rampsize = (3 * 256 * sizeof(*SDL_CurrentDisplay.gamma)); 189 size_t rampsize = (3 * 256 * sizeof(*display->gamma));
165 190
166 SDL_CurrentDisplay.gamma = SDL_malloc(rampsize * 2); 191 display->gamma = SDL_malloc(rampsize * 2);
167 if (!SDL_CurrentDisplay.gamma) { 192 if (!display->gamma) {
168 SDL_OutOfMemory(); 193 SDL_OutOfMemory();
169 return -1; 194 return -1;
170 } 195 }
171 if (_this && _this->GetDisplayGammaRamp) { 196 if (_this && _this->GetDisplayGammaRamp) {
172 /* Get the real hardware gamma */ 197 /* Get the real hardware gamma */
173 _this->GetDisplayGammaRamp(_this, SDL_CurrentDisplay.gamma); 198 _this->GetDisplayGammaRamp(_this, display, display->gamma);
174 } else { 199 } else {
175 /* Assume an identity gamma */ 200 /* Assume an identity gamma */
176 int i; 201 int i;
177 for (i = 0; i < 256; ++i) { 202 for (i = 0; i < 256; ++i) {
178 SDL_CurrentDisplay.gamma[0 * 256 + i] = (i << 8) | i; 203 display->gamma[0 * 256 + i] = (i << 8) | i;
179 SDL_CurrentDisplay.gamma[1 * 256 + i] = (i << 8) | i; 204 display->gamma[1 * 256 + i] = (i << 8) | i;
180 SDL_CurrentDisplay.gamma[2 * 256 + i] = (i << 8) | i; 205 display->gamma[2 * 256 + i] = (i << 8) | i;
181 } 206 }
182 } 207 }
183 SDL_CurrentDisplay.saved_gamma = SDL_CurrentDisplay.gamma + (3 * 256); 208 display->saved_gamma = display->gamma + (3 * 256);
184 SDL_memcpy(SDL_CurrentDisplay.saved_gamma, SDL_CurrentDisplay.gamma, 209 SDL_memcpy(display->saved_gamma, display->gamma, rampsize);
185 rampsize);
186 } 210 }
187 211
188 /* Just copy from our internal table */ 212 /* Just copy from our internal table */
189 if (red) { 213 if (red) {
190 SDL_memcpy(red, &SDL_CurrentDisplay.gamma[0 * 256], 214 SDL_memcpy(red, &display->gamma[0 * 256], 256 * sizeof(*red));
191 256 * sizeof(*red));
192 } 215 }
193 if (green) { 216 if (green) {
194 SDL_memcpy(green, &SDL_CurrentDisplay.gamma[1 * 256], 217 SDL_memcpy(green, &display->gamma[1 * 256], 256 * sizeof(*green));
195 256 * sizeof(*green));
196 } 218 }
197 if (blue) { 219 if (blue) {
198 SDL_memcpy(blue, &SDL_CurrentDisplay.gamma[2 * 256], 220 SDL_memcpy(blue, &display->gamma[2 * 256], 256 * sizeof(*blue));
199 256 * sizeof(*blue));
200 } 221 }
201 return 0; 222 return 0;
202 } 223 }
203 224
225 int
226 SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue)
227 {
228 SDL_VideoDevice *_this = SDL_GetVideoDevice();
229 if (!_this) {
230 SDL_UninitializedVideo();
231 return -1;
232 }
233 return SDL_GetGammaRampForDisplay(&SDL_CurrentDisplay, red, green, blue);
234 }
235
204 /* vi: set ts=4 sw=4 expandtab: */ 236 /* vi: set ts=4 sw=4 expandtab: */