# HG changeset patch # User Sam Lantinga # Date 1297366748 28800 # Node ID 3a8a452b49f054d97b8808a1a5567de3bb1a2ced # Parent 78ce7bfd0faf26871d32b0520e90927bba620182 Removed gamma support since it wasn't widely used and not well supported. diff -r 78ce7bfd0faf -r 3a8a452b49f0 include/SDL_compat.h --- a/include/SDL_compat.h Thu Feb 10 10:37:35 2011 -0800 +++ b/include/SDL_compat.h Thu Feb 10 11:39:08 2011 -0800 @@ -328,6 +328,12 @@ SDL_Rect * dstrect); extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay); extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void); +extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue); +extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 * red, + const Uint16 * green, + const Uint16 * blue); +extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 * red, Uint16 * green, + Uint16 * blue); extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); diff -r 78ce7bfd0faf -r 3a8a452b49f0 include/SDL_video.h --- a/include/SDL_video.h Thu Feb 10 10:37:35 2011 -0800 +++ b/include/SDL_video.h Thu Feb 10 11:39:08 2011 -0800 @@ -361,55 +361,6 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window * window); /** - * \brief Set the gamma correction for each of the color channels on the - * currently selected display. - * - * \return 0 on success, or -1 if setting the gamma isn't supported. - * - * \sa SDL_SetGammaRamp() - */ -extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue); - -/** - * \brief Set the gamma ramp for the currently selected display. - * - * \param red The translation table for the red channel, or NULL. - * \param green The translation table for the green channel, or NULL. - * \param blue The translation table for the blue channel, or NULL. - * - * \return 0 on success, or -1 if gamma ramps are unsupported. - * - * Set the gamma translation table for the red, green, and blue channels - * of the video hardware. Each table is an array of 256 16-bit quantities, - * representing a mapping between the input and output for that channel. - * The input is the index into the array, and the output is the 16-bit - * gamma value at that index, scaled to the output color precision. - * - * \sa SDL_GetGammaRamp() - */ -extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 * red, - const Uint16 * green, - const Uint16 * blue); - -/** - * \brief Get the gamma ramp for the currently selected display. - * - * \param red A pointer to a 256 element array of 16-bit quantities to hold - * the translation table for the red channel, or NULL. - * \param green A pointer to a 256 element array of 16-bit quantities to hold - * the translation table for the green channel, or NULL. - * \param blue A pointer to a 256 element array of 16-bit quantities to hold - * the translation table for the blue channel, or NULL. - * - * \return 0 on success, or -1 if gamma ramps are unsupported. - * - * \sa SDL_SetGammaRamp() - */ -extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 * red, Uint16 * green, - Uint16 * blue); - - -/** * \brief Create a window with the specified position, dimensions, and flags. * * \param title The title of the window, in UTF-8 encoding. diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/SDL_compat.c --- a/src/SDL_compat.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/SDL_compat.c Thu Feb 10 11:39:08 2011 -0800 @@ -1526,6 +1526,26 @@ SDL_GL_SwapWindow(SDL_VideoWindow); } +int +SDL_SetGamma(float red, float green, float blue) +{ + SDL_Unsupported(); + return -1; +} + +int +SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue) +{ + SDL_Unsupported(); + return -1; +} + +int +SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue) +{ + SDL_Unsupported(); + return -1; +} int SDL_EnableKeyRepeat(int delay, int interval) diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/SDL_gamma.c --- a/src/video/SDL_gamma.c Thu Feb 10 10:37:35 2011 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,236 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* Gamma correction support */ - -#include "SDL_sysvideo.h" - - -static void -CalculateGammaRamp(float gamma, Uint16 * ramp) -{ - int i; - - /* 0.0 gamma is all black */ - if (gamma <= 0.0f) { - for (i = 0; i < 256; ++i) { - ramp[i] = 0; - } - return; - } else - /* 1.0 gamma is identity */ - if (gamma == 1.0f) { - for (i = 0; i < 256; ++i) { - ramp[i] = (i << 8) | i; - } - return; - } else - /* Calculate a real gamma ramp */ - { - int value; - gamma = 1.0f / gamma; - for (i = 0; i < 256; ++i) { - value = - (int) (SDL_pow((double) i / 256.0, gamma) * 65535.0 + 0.5); - if (value > 65535) { - value = 65535; - } - ramp[i] = (Uint16) value; - } - } -} - -static void -CalculateGammaFromRamp(float *gamma, Uint16 * ramp) -{ - /* The following is adapted from a post by Garrett Bass on OpenGL - Gamedev list, March 4, 2000. - */ - float sum = 0.0f; - int i, count = 0; - - *gamma = 1.0; - for (i = 1; i < 256; ++i) { - if ((ramp[i] != 0) && (ramp[i] != 65535)) { - double B = (double) i / 256.0; - double A = ramp[i] / 65535.0; - sum += (float) (SDL_log(A) / SDL_log(B)); - count++; - } - } - if (count && sum > 0.0f) { - *gamma = 1.0f / (sum / count); - } -} - -int -SDL_SetGamma(float red, float green, float blue) -{ - Uint16 ramp[3][256]; - - CalculateGammaRamp(red, ramp[0]); - CalculateGammaRamp(green, ramp[1]); - CalculateGammaRamp(blue, ramp[2]); - - return SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]); -} - -/* Calculating the gamma by integrating the gamma ramps isn't exact, - so this function isn't officially supported. -*/ -int -SDL_GetGamma(float *red, float *green, float *blue) -{ - int succeeded; - Uint16 ramp[3][256]; - - succeeded = SDL_GetGammaRamp(ramp[0], ramp[1], ramp[2]); - if (succeeded >= 0) { - CalculateGammaFromRamp(red, ramp[0]); - CalculateGammaFromRamp(green, ramp[1]); - CalculateGammaFromRamp(blue, ramp[2]); - } - return succeeded; -} - -static void -SDL_UninitializedVideo() -{ - SDL_SetError("Video subsystem has not been initialized"); -} - -int -SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - int succeeded; - - if (!_this) { - SDL_UninitializedVideo(); - return -1; - } - - /* Lazily allocate the gamma tables */ - if (!display->gamma) { - if (SDL_GetGammaRampForDisplay(display, NULL, NULL, NULL) < 0) { - return -1; - } - } - - /* Fill the gamma table with the new values */ - if (red) { - SDL_memcpy(&display->gamma[0 * 256], red, 256 * sizeof(*display->gamma)); - } - if (green) { - SDL_memcpy(&display->gamma[1 * 256], green, 256 * sizeof(*display->gamma)); - } - if (blue) { - SDL_memcpy(&display->gamma[2 * 256], blue, 256 * sizeof(*display->gamma)); - } - - /* Try to set the gamma ramp in the driver */ - succeeded = -1; - if (_this && _this->SetDisplayGammaRamp) { - if (SDL_GetFocusWindow()) { - succeeded = - _this->SetDisplayGammaRamp(_this, display, display->gamma); - } else { - succeeded = 0; - } - } else { - SDL_SetError("Gamma ramp manipulation not supported"); - } - return succeeded; -} - -int -SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { - SDL_UninitializedVideo(); - return -1; - } - return SDL_SetGammaRampForDisplay(SDL_CurrentDisplay, red, green, blue); -} - -int -SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - - if (!_this) { - SDL_UninitializedVideo(); - return -1; - } - - /* Lazily allocate the gamma table */ - if (!display->gamma) { - size_t rampsize = (3 * 256 * sizeof(*display->gamma)); - - display->gamma = SDL_malloc(rampsize * 2); - if (!display->gamma) { - SDL_OutOfMemory(); - return -1; - } - if (_this && _this->GetDisplayGammaRamp) { - /* Get the real hardware gamma */ - _this->GetDisplayGammaRamp(_this, display, display->gamma); - } else { - /* Assume an identity gamma */ - int i; - for (i = 0; i < 256; ++i) { - display->gamma[0 * 256 + i] = (i << 8) | i; - display->gamma[1 * 256 + i] = (i << 8) | i; - display->gamma[2 * 256 + i] = (i << 8) | i; - } - } - display->saved_gamma = display->gamma + (3 * 256); - SDL_memcpy(display->saved_gamma, display->gamma, rampsize); - } - - /* Just copy from our internal table */ - if (red) { - SDL_memcpy(red, &display->gamma[0 * 256], 256 * sizeof(*red)); - } - if (green) { - SDL_memcpy(green, &display->gamma[1 * 256], 256 * sizeof(*green)); - } - if (blue) { - SDL_memcpy(blue, &display->gamma[2 * 256], 256 * sizeof(*blue)); - } - return 0; -} - -int -SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { - SDL_UninitializedVideo(); - return -1; - } - return SDL_GetGammaRampForDisplay(SDL_CurrentDisplay, red, green, blue); -} - -/* vi: set ts=4 sw=4 expandtab: */ diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/SDL_pixels.c --- a/src/video/SDL_pixels.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/SDL_pixels.c Thu Feb 10 11:39:08 2011 -0800 @@ -764,20 +764,6 @@ } } -/* Apply gamma to a set of colors - this is easy. :) */ -void -SDL_ApplyGamma(Uint16 * gamma, SDL_Color * colors, SDL_Color * output, - int ncolors) -{ - int i; - - for (i = 0; i < ncolors; ++i) { - output[i].r = gamma[0 * 256 + colors[i].r] >> 8; - output[i].g = gamma[1 * 256 + colors[i].g] >> 8; - output[i].b = gamma[2 * 256 + colors[i].b] >> 8; - } -} - /* Map from Palette to Palette */ static Uint8 * Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/SDL_pixels_c.h --- a/src/video/SDL_pixels_c.h Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/SDL_pixels_c.h Thu Feb 10 11:39:08 2011 -0800 @@ -45,7 +45,5 @@ extern int SDL_CalculatePitch(SDL_Surface * surface); extern void SDL_DitherColors(SDL_Color * colors, int bpp); extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b); -extern void SDL_ApplyGamma(Uint16 * gamma, SDL_Color * colors, - SDL_Color * output, int ncolors); /* vi: set ts=4 sw=4 expandtab: */ diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/SDL_sysvideo.h --- a/src/video/SDL_sysvideo.h Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/SDL_sysvideo.h Thu Feb 10 11:39:08 2011 -0800 @@ -110,9 +110,6 @@ SDL_DisplayMode current_mode; SDL_bool updating_fullscreen; - Uint16 *gamma; - Uint16 *saved_gamma; /* (just offset into gamma) */ - SDL_Window *windows; SDL_Window *fullscreen_window; @@ -169,12 +166,6 @@ */ int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); - /* Set the gamma ramp */ - int (*SetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp); - - /* Get the gamma ramp */ - int (*GetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp); - /* * * */ /* * Window functions @@ -343,8 +334,6 @@ extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode); extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest); extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode); -extern int SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue); -extern int SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue); extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/SDL_video.c --- a/src/video/SDL_video.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/SDL_video.c Thu Feb 10 11:39:08 2011 -0800 @@ -1644,9 +1644,6 @@ { SDL_VideoDisplay *display = window->display; - if (display->gamma && _this->SetDisplayGammaRamp) { - _this->SetDisplayGammaRamp(_this, display, display->gamma); - } if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) && _this->SetWindowGrab) { _this->SetWindowGrab(_this, window); @@ -1664,9 +1661,6 @@ SDL_MinimizeWindow(window); } - if (display->gamma && _this->SetDisplayGammaRamp) { - _this->SetDisplayGammaRamp(_this, display, display->saved_gamma); - } if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) && _this->SetWindowGrab) { _this->SetWindowGrab(_this, window); @@ -1825,10 +1819,6 @@ SDL_free(display->desktop_mode.driverdata); display->desktop_mode.driverdata = NULL; } - if (display->gamma) { - SDL_free(display->gamma); - display->gamma = NULL; - } if (display->driverdata) { SDL_free(display->driverdata); display->driverdata = NULL; diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/bwindow/SDL_sysvideo.cc --- a/src/video/bwindow/SDL_sysvideo.cc Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/bwindow/SDL_sysvideo.cc Thu Feb 10 11:39:08 2011 -0800 @@ -129,7 +129,6 @@ device->UnlockHWSurface = BE_UnlockHWSurface; device->FlipHWSurface = NULL; device->FreeHWSurface = BE_FreeHWSurface; - /* Gamma support */ #if SDL_VIDEO_OPENGL /* OpenGL support */ device->GL_LoadLibrary = BE_GL_LoadLibrary; diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/directfb/SDL_DirectFB_video.c --- a/src/video/directfb/SDL_DirectFB_video.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/directfb/SDL_DirectFB_video.c Thu Feb 10 11:39:08 2011 -0800 @@ -27,7 +27,6 @@ #include "SDL_DirectFB_events.h" /* - * #include "SDL_DirectFB_gamma.h" * #include "SDL_DirectFB_keyboard.h" */ #include "SDL_DirectFB_modes.h" diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/pandora/SDL_pandora.h --- a/src/video/pandora/SDL_pandora.h Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/pandora/SDL_pandora.h Thu Feb 10 11:39:08 2011 -0800 @@ -70,8 +70,6 @@ void PND_videoquit(_THIS); void PND_getdisplaymodes(_THIS, SDL_VideoDisplay * display); int PND_setdisplaymode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); -int PND_setdisplaygammaramp(_THIS, Uint16 * ramp); -int PND_getdisplaygammaramp(_THIS, Uint16 * ramp); int PND_createwindow(_THIS, SDL_Window * window); int PND_createwindowfrom(_THIS, SDL_Window * window, const void *data); void PND_setwindowtitle(_THIS, SDL_Window * window); diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/windows/SDL_windowsgamma.c --- a/src/video/windows/SDL_windowsgamma.c Thu Feb 10 10:37:35 2011 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_windowsvideo.h" - - -int -WIN_SetDisplayGammaRamp(_THIS, SDL_VideoDisplay * display, Uint16 * ramp) -{ -#ifdef _WIN32_WCE - return -1; -#else - SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; - HDC hdc; - BOOL succeeded = FALSE; - - hdc = CreateDC(data->DeviceName, NULL, NULL, NULL); - if (hdc) { - succeeded = SetDeviceGammaRamp(hdc, ramp); - if (!succeeded) { - WIN_SetError("SetDeviceGammaRamp()"); - } - DeleteDC(hdc); - } - return succeeded ? 0 : -1; -#endif -} - -int -WIN_GetDisplayGammaRamp(_THIS, SDL_VideoDisplay * display, Uint16 * ramp) -{ -#ifdef _WIN32_WCE - return -1; -#else - SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; - HDC hdc; - BOOL succeeded = FALSE; - - hdc = CreateDC(data->DeviceName, NULL, NULL, NULL); - if (hdc) { - succeeded = GetDeviceGammaRamp(hdc, ramp); - if (!succeeded) { - WIN_SetError("GetDeviceGammaRamp()"); - } - DeleteDC(hdc); - } - return succeeded ? 0 : -1; -#endif -} - -/* vi: set ts=4 sw=4 expandtab: */ diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/windows/SDL_windowsgamma.h --- a/src/video/windows/SDL_windowsgamma.h Thu Feb 10 10:37:35 2011 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifndef _SDL_windowsgamma_h -#define _SDL_windowsgamma_h - -extern int WIN_SetDisplayGammaRamp(_THIS, SDL_VideoDisplay * display, Uint16 * ramp); -extern int WIN_GetDisplayGammaRamp(_THIS, SDL_VideoDisplay * display, Uint16 * ramp); - -#endif /* _SDL_windowsgamma_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/windows/SDL_windowsvideo.c --- a/src/video/windows/SDL_windowsvideo.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/windows/SDL_windowsvideo.c Thu Feb 10 11:39:08 2011 -0800 @@ -109,8 +109,6 @@ device->GetDisplayBounds = WIN_GetDisplayBounds; device->GetDisplayModes = WIN_GetDisplayModes; device->SetDisplayMode = WIN_SetDisplayMode; - device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp; - device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp; device->PumpEvents = WIN_PumpEvents; #undef CreateWindow diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/windows/SDL_windowsvideo.h --- a/src/video/windows/SDL_windowsvideo.h Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/windows/SDL_windowsvideo.h Thu Feb 10 11:39:08 2011 -0800 @@ -41,7 +41,6 @@ #include "SDL_windowsclipboard.h" #include "SDL_windowsevents.h" -#include "SDL_windowsgamma.h" #include "SDL_windowskeyboard.h" #include "SDL_windowsmodes.h" #include "SDL_windowsmouse.h" diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/x11/SDL_x11gamma.c --- a/src/video/x11/SDL_x11gamma.c Thu Feb 10 10:37:35 2011 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,232 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" -#include "../SDL_sysvideo.h" -#include "SDL_x11video.h" - - /* The size of *all* SDL gamma ramps */ -#define SDL_GammaRampSize (3 * 256 * sizeof(Uint16)) - -static int numCmaps = 0; - -typedef struct -{ - Display *display; - int scrNum; - Colormap colormap; - Visual visual; - Uint16 *ramp; -} cmapTableEntry; - -cmapTableEntry *cmapTable = NULL; - -/* To reduce the overhead as much as possible lets do as little as - possible. When we do have to create a colormap keep track of it and - reuse it. We're going to do this for both DirectColor and - PseudoColor colormaps. */ - -Colormap -X11_LookupColormap(Display * display, int scrNum, VisualID vid) -{ - int i; - - for (i = 0; i < numCmaps; i++) { - if (cmapTable[i].display == display && - cmapTable[i].scrNum == scrNum && - cmapTable[i].visual.visualid == vid) { - return cmapTable[i].colormap; - } - } - - return 0; -} - - -void -X11_TrackColormap(Display * display, int scrNum, Colormap colormap, - Visual * visual, XColor * ramp) -{ - int i; - Uint16 *newramp; - int ncolors; - - /* search the table to find out if we already have this one. We - only want one entry for each display, screen number, visualid, - and colormap combination */ - for (i = 0; i < numCmaps; i++) { - if (cmapTable[i].display == display && - cmapTable[i].scrNum == scrNum && - cmapTable[i].visual.visualid == visual->visualid && - cmapTable[i].colormap == colormap) { - return; - } - } - - /* increase the table by one entry. If the table is NULL create the - first entrty */ - cmapTable = - SDL_realloc(cmapTable, (numCmaps + 1) * sizeof(cmapTableEntry)); - if (NULL == cmapTable) { - SDL_SetError("Out of memory in X11_TrackColormap()"); - return; - } - - cmapTable[numCmaps].display = display; - cmapTable[numCmaps].scrNum = scrNum; - cmapTable[numCmaps].colormap = colormap; - SDL_memcpy(&cmapTable[numCmaps].visual, visual, sizeof(Visual)); - cmapTable[numCmaps].ramp = NULL; - - if (ramp != NULL) { - newramp = SDL_malloc(SDL_GammaRampSize); - if (NULL == newramp) { - SDL_SetError("Out of memory in X11_TrackColormap()"); - return; - } - SDL_memset(newramp, 0, SDL_GammaRampSize); - cmapTable[numCmaps].ramp = newramp; - - ncolors = cmapTable[numCmaps].visual.map_entries; - - for (i = 0; i < ncolors; i++) { - newramp[(0 * 256) + i] = ramp[i].red; - newramp[(1 * 256) + i] = ramp[i].green; - newramp[(2 * 256) + i] = ramp[i].blue; - } - } - - numCmaps++; -} - -/* The problem is that you have to have at least one DirectColor - colormap before you can set the gamma ramps or read the gamma - ramps. If the application has created a DirectColor window then the - cmapTable will have at least one colormap in it and everything is - cool. If not, then we just fail */ - -int -X11_SetDisplayGammaRamp(_THIS, SDL_VideoDisplay * sdl_display, Uint16 * ramp) -{ - Visual *visual; - Display *display; - Colormap colormap; - XColor *colorcells; - int ncolors; - int rmask, gmask, bmask; - int rshift, gshift, bshift; - int i; - int j; - - for (j = 0; j < numCmaps; j++) { - if (cmapTable[j].visual.class == DirectColor) { - display = cmapTable[j].display; - colormap = cmapTable[j].colormap; - ncolors = cmapTable[j].visual.map_entries; - visual = &cmapTable[j].visual; - - colorcells = SDL_malloc(ncolors * sizeof(XColor)); - if (NULL == colorcells) { - SDL_SetError("out of memory in X11_SetDisplayGammaRamp"); - return -1; - } - /* remember the new ramp */ - if (cmapTable[j].ramp == NULL) { - Uint16 *newramp = SDL_malloc(SDL_GammaRampSize); - if (NULL == newramp) { - SDL_SetError("Out of memory in X11_TrackColormap()"); - return -1; - } - cmapTable[j].ramp = newramp; - } - SDL_memcpy(cmapTable[j].ramp, ramp, SDL_GammaRampSize); - - rshift = 0; - rmask = visual->red_mask; - while (0 == (rmask & 1)) { - rshift++; - rmask >>= 1; - } - -/* printf("rmask = %4x rshift = %4d\n", rmask, rshift); */ - - gshift = 0; - gmask = visual->green_mask; - while (0 == (gmask & 1)) { - gshift++; - gmask >>= 1; - } - -/* printf("gmask = %4x gshift = %4d\n", gmask, gshift); */ - - bshift = 0; - bmask = visual->blue_mask; - while (0 == (bmask & 1)) { - bshift++; - bmask >>= 1; - } - -/* printf("bmask = %4x bshift = %4d\n", bmask, bshift); */ - - /* build the color table pixel values */ - for (i = 0; i < ncolors; i++) { - Uint32 rbits = (rmask * i) / (ncolors - 1); - Uint32 gbits = (gmask * i) / (ncolors - 1); - Uint32 bbits = (bmask * i) / (ncolors - 1); - - Uint32 pix = - (rbits << rshift) | (gbits << gshift) | (bbits << bshift); - - colorcells[i].pixel = pix; - - colorcells[i].flags = DoRed | DoGreen | DoBlue; - - colorcells[i].red = ramp[(0 * 256) + i]; - colorcells[i].green = ramp[(1 * 256) + i]; - colorcells[i].blue = ramp[(2 * 256) + i]; - } - - XStoreColors(display, colormap, colorcells, ncolors); - XFlush(display); - SDL_free(colorcells); - } - } - - return 0; -} - -int -X11_GetDisplayGammaRamp(_THIS, SDL_VideoDisplay * display, Uint16 * ramp) -{ - int i; - - /* find the first DirectColor colormap and use it to get the gamma - ramp */ - - for (i = 0; i < numCmaps; i++) { - if (cmapTable[i].visual.class == DirectColor) { - SDL_memcpy(ramp, cmapTable[i].ramp, SDL_GammaRampSize); - return 0; - } - } - - return -1; -} diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/x11/SDL_x11gamma.h --- a/src/video/x11/SDL_x11gamma.h Thu Feb 10 10:37:35 2011 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifndef _SDL_x11gamma_h -#define _SDL_x11gamma_h - -extern Colormap X11_LookupColormap(Display * display, int scrNum, - VisualID vid); -extern void X11_TrackColormap(Display * display, int scrNum, - Colormap colormap, - Visual * visual, XColor * ramp); - -extern int X11_SetDisplayGammaRamp(_THIS, SDL_VideoDisplay * display, Uint16 * ramp); -extern int X11_GetDisplayGammaRamp(_THIS, SDL_VideoDisplay * display, Uint16 * ramp); - -#endif diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/x11/SDL_x11modes.c --- a/src/video/x11/SDL_x11modes.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/x11/SDL_x11modes.c Thu Feb 10 11:39:08 2011 -0800 @@ -47,9 +47,7 @@ } depth = DefaultDepth(display, screen); - if ((X11_UseDirectColorVisuals() && - XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) || - XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) || + if (XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) || XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) || XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) { return 0; diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/x11/SDL_x11opengl.c --- a/src/video/x11/SDL_x11opengl.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/x11/SDL_x11opengl.c Thu Feb 10 11:39:08 2011 -0800 @@ -365,22 +365,9 @@ GLX_SLOW_VISUAL_EXT; } -#ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ - if (X11_UseDirectColorVisuals()) { - attribs[i++] = GLX_X_VISUAL_TYPE; - attribs[i++] = GLX_DIRECT_COLOR; - } -#endif - attribs[i++] = None; vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs); -#ifdef GLX_DIRECT_COLOR - if (!vinfo && X11_UseDirectColorVisuals()) { /* No DirectColor visual? Try again.. */ - attribs[i - 3] = None; - vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs); - } -#endif if (!vinfo) { SDL_SetError("Couldn't find matching GLX visual"); } diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/x11/SDL_x11video.c --- a/src/video/x11/SDL_x11video.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/x11/SDL_x11video.c Thu Feb 10 11:39:08 2011 -0800 @@ -186,8 +186,6 @@ device->VideoQuit = X11_VideoQuit; device->GetDisplayModes = X11_GetDisplayModes; device->SetDisplayMode = X11_SetDisplayMode; - device->SetDisplayGammaRamp = X11_SetDisplayGammaRamp; - device->GetDisplayGammaRamp = X11_GetDisplayGammaRamp; device->SuspendScreenSaver = X11_SuspendScreenSaver; device->PumpEvents = X11_PumpEvents; @@ -384,13 +382,4 @@ X11_QuitTouch(_this); } -SDL_bool -X11_UseDirectColorVisuals(void) -{ - /* Once we implement DirectColor colormaps and gamma ramp support... - return SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ? SDL_FALSE : SDL_TRUE; - */ - return SDL_FALSE; -} - /* vim: set ts=4 sw=4 expandtab: */ diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/x11/SDL_x11video.h --- a/src/video/x11/SDL_x11video.h Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/x11/SDL_x11video.h Thu Feb 10 11:39:08 2011 -0800 @@ -55,7 +55,6 @@ #include "SDL_x11clipboard.h" #include "SDL_x11events.h" -#include "SDL_x11gamma.h" #include "SDL_x11keyboard.h" #include "SDL_x11modes.h" #include "SDL_x11mouse.h" @@ -93,8 +92,6 @@ SDL_bool selection_waiting; } SDL_VideoData; -extern SDL_bool X11_UseDirectColorVisuals(void); - #endif /* _SDL_x11video_h */ /* vi: set ts=4 sw=4 expandtab: */ diff -r 78ce7bfd0faf -r 3a8a452b49f0 src/video/x11/SDL_x11window.c --- a/src/video/x11/SDL_x11window.c Thu Feb 10 10:37:35 2011 -0800 +++ b/src/video/x11/SDL_x11window.c Thu Feb 10 11:39:08 2011 -0800 @@ -28,7 +28,6 @@ #include "SDL_x11video.h" #include "SDL_x11mouse.h" -#include "SDL_x11gamma.h" #include "SDL_x11shape.h" #ifdef SDL_VIDEO_DRIVER_PANDORA @@ -326,217 +325,7 @@ } xattr.background_pixel = 0; xattr.border_pixel = 0; - - if (visual->class == PseudoColor) { - printf("asking for PseudoColor\n"); - -/* Status status; */ - XColor *colorcells; - Colormap colormap; - Sint32 pix; - Sint32 ncolors; - Sint32 nbits; - Sint32 rmax, gmax, bmax; - Sint32 rwidth, gwidth, bwidth; - Sint32 rmask, gmask, bmask; - Sint32 rshift, gshift, bshift; - Sint32 r, g, b; - - /* Is the colormap we need already registered in SDL? */ - if ((colormap = - X11_LookupColormap(display, screen, visual->visualid))) { - xattr.colormap = colormap; -/* printf("found existing colormap\n"); */ - } else { - /* The colormap is not known to SDL so we will create it */ - colormap = XCreateColormap(display, RootWindow(display, screen), - visual, AllocAll); -/* printf("colormap = %x\n", colormap); */ - - /* If we can't create a colormap, then we must die */ - if (!colormap) { - SDL_SetError - ("Couldn't create window: Could not create writable colormap"); - return -1; - } - - /* OK, we got a colormap, now fill it in as best as we can */ - - colorcells = SDL_malloc(visual->map_entries * sizeof(XColor)); - if (NULL == colorcells) { - SDL_SetError("out of memory in X11_CreateWindow"); - return -1; - } - - ncolors = visual->map_entries; - nbits = visual->bits_per_rgb; - -/* printf("ncolors = %d nbits = %d\n", ncolors, nbits); */ - - /* what if ncolors != (1 << nbits)? That can happen on a - true PseudoColor display. I'm assuming that we will - always have ncolors == (1 << nbits) */ - - /* I'm making a lot of assumptions here. */ - - /* Compute the width of each field. If there is one extra - bit, give it to green. If there are two extra bits give - them to red and greed. We can get extra bits when the - number of bits per pixel is not a multiple of 3. For - example when we have 16 bits per pixel and need a 5/6/5 - layout for the RGB fields */ - - rwidth = (nbits / 3) + (((nbits % 3) == 2) ? 1 : 0); - gwidth = (nbits / 3) + (((nbits % 3) >= 1) ? 1 : 0); - bwidth = (nbits / 3); - - rshift = gwidth + bwidth; - gshift = bwidth; - bshift = 0; - - rmax = 1 << rwidth; - gmax = 1 << gwidth; - bmax = 1 << bwidth; - - rmask = rmax - 1; - gmask = gmax - 1; - bmask = bmax - 1; - -/* printf("red mask = %4x shift = %4d width = %d\n", rmask, rshift, rwidth); */ -/* printf("green mask = %4x shift = %4d width = %d\n", gmask, gshift, gwidth); */ -/* printf("blue mask = %4x shift = %4d width = %d\n", bmask, bshift, bwidth); */ - - /* build the color table pixel values */ - pix = 0; - for (r = 0; r < rmax; r++) { - for (g = 0; g < gmax; g++) { - for (b = 0; b < bmax; b++) { - colorcells[pix].pixel = - (r << rshift) | (g << gshift) | (b << bshift); - colorcells[pix].red = (0xffff * r) / rmask; - colorcells[pix].green = (0xffff * g) / gmask; - colorcells[pix].blue = (0xffff * b) / bmask; -/* printf("%4x:%4x [%4x %4x %4x]\n", */ -/* pix, */ -/* colorcells[pix].pixel, */ -/* colorcells[pix].red, */ -/* colorcells[pix].green, */ -/* colorcells[pix].blue); */ - pix++; - } - } - } - -/* status = */ -/* XStoreColors(display, colormap, colorcells, ncolors); */ - - xattr.colormap = colormap; - X11_TrackColormap(display, screen, colormap, visual, NULL); - - SDL_free(colorcells); - } - } else if (visual->class == DirectColor) { - Status status; - XColor *colorcells; - Colormap colormap; - int i; - int ncolors; - int rmax, gmax, bmax; - int rmask, gmask, bmask; - int rshift, gshift, bshift; - - /* Is the colormap we need already registered in SDL? */ - if ((colormap = - X11_LookupColormap(display, screen, visual->visualid))) { - xattr.colormap = colormap; -/* printf("found existing colormap\n"); */ - } else { - /* The colormap is not known to SDL so we will create it */ - colormap = XCreateColormap(display, RootWindow(display, screen), - visual, AllocAll); -/* printf("colormap = %x\n", colormap); */ - - /* If we can't create a colormap, then we must die */ - if (!colormap) { - SDL_SetError - ("Couldn't create window: Could not create writable colormap"); - return -1; - } - - /* OK, we got a colormap, now fill it in as best as we can */ - colorcells = SDL_malloc(visual->map_entries * sizeof(XColor)); - if (NULL == colorcells) { - SDL_SetError("out of memory in X11_CreateWindow"); - return -1; - } - ncolors = visual->map_entries; - rmax = 0xffff; - gmax = 0xffff; - bmax = 0xffff; - - rshift = 0; - rmask = visual->red_mask; - while (0 == (rmask & 1)) { - rshift++; - rmask >>= 1; - } - -/* printf("rmask = %4x rshift = %4d\n", rmask, rshift); */ - - gshift = 0; - gmask = visual->green_mask; - while (0 == (gmask & 1)) { - gshift++; - gmask >>= 1; - } - -/* printf("gmask = %4x gshift = %4d\n", gmask, gshift); */ - - bshift = 0; - bmask = visual->blue_mask; - while (0 == (bmask & 1)) { - bshift++; - bmask >>= 1; - } - -/* printf("bmask = %4x bshift = %4d\n", bmask, bshift); */ - - /* build the color table pixel values */ - for (i = 0; i < ncolors; i++) { - Uint32 red = (rmax * i) / (ncolors - 1); - Uint32 green = (gmax * i) / (ncolors - 1); - Uint32 blue = (bmax * i) / (ncolors - 1); - - Uint32 rbits = (rmask * i) / (ncolors - 1); - Uint32 gbits = (gmask * i) / (ncolors - 1); - Uint32 bbits = (bmask * i) / (ncolors - 1); - - Uint32 pix = - (rbits << rshift) | (gbits << gshift) | (bbits << bshift); - - colorcells[i].pixel = pix; - - colorcells[i].red = red; - colorcells[i].green = green; - colorcells[i].blue = blue; - - colorcells[i].flags = DoRed | DoGreen | DoBlue; -/* printf("%2d:%4x [%4x %4x %4x]\n", i, pix, red, green, blue); */ - } - - status = - XStoreColors(display, colormap, colorcells, ncolors); - - xattr.colormap = colormap; - X11_TrackColormap(display, screen, colormap, visual, colorcells); - - SDL_free(colorcells); - } - } else { - xattr.colormap = - XCreateColormap(display, RootWindow(display, screen), - visual, AllocNone); - } + xattr.colormap = XCreateColormap(display, RootWindow(display, screen), visual, AllocNone); if (oldstyle_fullscreen || window->x == SDL_WINDOWPOS_CENTERED) { diff -r 78ce7bfd0faf -r 3a8a452b49f0 test/Makefile.in --- a/test/Makefile.in Thu Feb 10 10:37:35 2011 -0800 +++ b/test/Makefile.in Thu Feb 10 11:39:08 2011 -0800 @@ -23,7 +23,6 @@ testerror$(EXE) \ testfile$(EXE) \ testfill$(EXE) \ - testgamma$(EXE) \ testgesture$(EXE) \ testgl$(EXE) \ testgl2$(EXE) \ diff -r 78ce7bfd0faf -r 3a8a452b49f0 test/testgamma.c --- a/test/testgamma.c Thu Feb 10 10:37:35 2011 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,194 +0,0 @@ - -/* Bring up a window and manipulate the gamma on it */ - -#include -#include -#include -#include - -#include "SDL.h" - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -/* Turn a normal gamma value into an appropriate gamma ramp */ -void -CalculateGamma(double gamma, Uint16 * ramp) -{ - int i, value; - - gamma = 1.0 / gamma; - for (i = 0; i < 256; ++i) { - value = (int) (pow((double) i / 256.0, gamma) * 65535.0 + 0.5); - if (value > 65535) { - value = 65535; - } - ramp[i] = (Uint16) value; - } -} - -/* This can be used as a general routine for all of the test programs */ -int -get_video_args(char *argv[], int *w, int *h, int *bpp, Uint32 * flags) -{ - int i; - - *w = 640; - *h = 480; - *bpp = 0; - *flags = SDL_SWSURFACE; - - for (i = 1; argv[i]; ++i) { - if (strcmp(argv[i], "-width") == 0) { - if (argv[i + 1]) { - *w = atoi(argv[++i]); - } - } else if (strcmp(argv[i], "-height") == 0) { - if (argv[i + 1]) { - *h = atoi(argv[++i]); - } - } else if (strcmp(argv[i], "-bpp") == 0) { - if (argv[i + 1]) { - *bpp = atoi(argv[++i]); - } - } else if (strcmp(argv[i], "-fullscreen") == 0) { - *flags |= SDL_FULLSCREEN; - } else if (strcmp(argv[i], "-hw") == 0) { - *flags |= SDL_HWSURFACE; - } else if (strcmp(argv[i], "-hwpalette") == 0) { - *flags |= SDL_HWPALETTE; - } else - break; - } - return i; -} - -int -main(int argc, char *argv[]) -{ - SDL_Surface *screen; - SDL_Surface *image; - float gamma; - int i; - int w, h, bpp; - Uint32 flags; - Uint16 ramp[256]; - Uint16 red_ramp[256]; - Uint32 then, timeout; - - /* Check command line arguments */ - argv += get_video_args(argv, &w, &h, &bpp, &flags); - - /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); - } - - /* Initialize the display, always use hardware palette */ - screen = SDL_SetVideoMode(w, h, bpp, flags | SDL_HWPALETTE); - if (screen == NULL) { - fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", - w, h, SDL_GetError()); - quit(1); - } - - /* Set the window manager title bar */ - SDL_WM_SetCaption("SDL gamma test", "testgamma"); - - /* Set the desired gamma, if any */ - gamma = 1.0f; - if (*argv) { - gamma = (float) atof(*argv); - } - if (SDL_SetGamma(gamma, gamma, gamma) < 0) { - fprintf(stderr, "Unable to set gamma: %s\n", SDL_GetError()); - quit(1); - } -#if 0 /* This isn't supported. Integrating the gamma ramps isn't exact */ - /* See what gamma was actually set */ - float real[3]; - if (SDL_GetGamma(&real[0], &real[1], &real[2]) < 0) { - printf("Couldn't get gamma: %s\n", SDL_GetError()); - } else { - printf("Set gamma values: R=%2.2f, G=%2.2f, B=%2.2f\n", - real[0], real[1], real[2]); - } -#endif - - /* Do all the drawing work */ - image = SDL_LoadBMP("sample.bmp"); - if (image) { - SDL_Rect dst; - - dst.x = (screen->w - image->w) / 2; - dst.y = (screen->h - image->h) / 2; - dst.w = image->w; - dst.h = image->h; - SDL_BlitSurface(image, NULL, screen, &dst); - SDL_UpdateRects(screen, 1, &dst); - } - - /* Wait a bit, handling events */ - then = SDL_GetTicks(); - timeout = (5 * 1000); - while ((SDL_GetTicks() - then) < timeout) { - SDL_Event event; - - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: /* Quit now */ - timeout = 0; - break; - case SDL_KEYDOWN: - switch (event.key.keysym.sym) { - case SDLK_SPACE: /* Go longer.. */ - timeout += (5 * 1000); - break; - case SDLK_UP: - gamma += 0.2f; - SDL_SetGamma(gamma, gamma, gamma); - break; - case SDLK_DOWN: - gamma -= 0.2f; - SDL_SetGamma(gamma, gamma, gamma); - break; - case SDLK_ESCAPE: - timeout = 0; - break; - default: - break; - } - break; - } - } - } - - /* Perform a gamma flash to red using color ramps */ - while (gamma < 10.0) { - /* Increase the red gamma and decrease everything else... */ - gamma += 0.1f; - CalculateGamma(gamma, red_ramp); - CalculateGamma(1.0 / gamma, ramp); - SDL_SetGammaRamp(red_ramp, ramp, ramp); - } - /* Finish completely red */ - memset(red_ramp, 255, sizeof(red_ramp)); - memset(ramp, 0, sizeof(ramp)); - SDL_SetGammaRamp(red_ramp, ramp, ramp); - - /* Now fade out to black */ - for (i = (red_ramp[0] >> 8); i >= 0; --i) { - memset(red_ramp, i, sizeof(red_ramp)); - SDL_SetGammaRamp(red_ramp, NULL, NULL); - } - SDL_Delay(1 * 1000); - - SDL_Quit(); - return (0); -}