Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Implemented gamma correction on Windows.
Added general code to restore the video mode and gamma when windows lose focus.
  • Loading branch information
slouken committed Jul 9, 2006
1 parent e5f5634 commit d8b35a1
Show file tree
Hide file tree
Showing 16 changed files with 429 additions and 190 deletions.
127 changes: 82 additions & 45 deletions include/SDL_video.h
Expand Up @@ -98,6 +98,7 @@ typedef struct
* \sa SDL_RaiseWindow()
* \sa SDL_RestoreWindow()
* \sa SDL_SetWindowData()
* \sa SDL_SetWindowFullscreen()
* \sa SDL_SetWindowGrab()
* \sa SDL_SetWindowIcon()
* \sa SDL_SetWindowPosition()
Expand Down Expand Up @@ -474,15 +475,28 @@ extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode(const
* closest);

/**
* \fn int SDL_SetDisplayMode(const SDL_DisplayMode *mode)
* \fn int SDL_SetFullscreenDisplayMode(const SDL_DisplayMode *mode)
*
* \brief Set up the closest available mode on the current display.
* \brief Set the display mode used when a fullscreen window is visible
* on the currently selected display.
*
* \param mode The desired display mode, or NULL to set the desktop mode.
* \param mode The mode to use, or NULL for the desktop mode.
*
* \return 0 on success, or -1 if setting the display mode failed.
*
* \sa SDL_SetWindowFullscreen()
*/
extern DECLSPEC int SDLCALL SDL_SetDisplayMode(const SDL_DisplayMode * mode);
extern DECLSPEC int SDLCALL SDL_SetFullscreenDisplayMode(const SDL_DisplayMode
* mode);

/**
* \fn const SDL_DisplayMode *SDL_GetFullscreenDisplayMode(void)
*
* \brief Query the display mode used when a fullscreen window is visible
* on the currently selected display.
*/
extern DECLSPEC const SDL_DisplayMode *SDLCALL
SDL_GetFullscreenDisplayMode(void);

/**
* \fn int SDL_SetDisplayPalette(const SDL_Color *colors, int firstcolor, int ncolors)
Expand All @@ -506,6 +520,57 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayPalette(SDL_Color * colors,
int firstcolor,
int ncolors);

/**
* \fn int SDL_SetGamma(float red, float green, float blue)
*
* \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);

/**
* \fn int SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * 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);

/**
* \fn int SDL_GetGammaRamp(Uint16 * red, Uint16 * green, 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);


/**
* \fn SDL_WindowID SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
*
Expand All @@ -516,7 +581,7 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayPalette(SDL_Color * colors,
* \param y The y position of the window
* \param w The width of the window
* \param h The height of the window
* \param flags The flags for the window
* \param flags The flags for the window, a mask of any of the following: SDL_WINDOW_FULLSCREEN, SDL_WINDOW_OPENGL, SDL_WINDOW_SHOWN, SDL_WINDOW_BORDERLESS, SDL_WINDOW_RESIZABLE, SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MINIMIZED, SDL_WINDOW_INPUT_GRABBED
*
* \return The id of the window created, or zero if window creation failed.
*
Expand Down Expand Up @@ -701,14 +766,25 @@ extern DECLSPEC void SDLCALL SDL_MinimizeWindow(SDL_WindowID windowID);
*/
extern DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_WindowID windowID);

/**
* \fn int SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen)
*
* \brief Set the window's fullscreen state.
*
* \return 0 on success, or -1 if setting the display mode failed.
*
* \sa SDL_SetFullscreenDisplayMode()
*/
extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_WindowID windowID,
int fullscreen);

/**
* \fn void SDL_SetWindowGrab(SDL_WindowID windowID, int mode)
*
* \brief Set the window's input grab mode.
*
* \param mode This is 1 to grab input, and 0 to release input.
*
* \sa SDL_GrabMode
* \sa SDL_GetWindowGrab()
*/
extern DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_WindowID windowID,
Expand All @@ -721,7 +797,6 @@ extern DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_WindowID windowID,
*
* \return This returns 1 if input is grabbed, and 0 otherwise.
*
* \sa SDL_GrabMode
* \sa SDL_SetWindowGrab()
*/
extern DECLSPEC int SDLCALL SDL_GetWindowGrab(SDL_WindowID windowID);
Expand Down Expand Up @@ -1069,44 +1144,6 @@ extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_TextureID textureID);
*/
extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_WindowID windowID);

/*
* Set the gamma correction for each of the color channels.
* The gamma values range (approximately) between 0.1 and 10.0
*
* If this function isn't supported directly by the hardware, it will
* be emulated using gamma ramps, if available. If successful, this
* function returns 0, otherwise it returns -1.
*/
extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue);

/*
* 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.
*
* You may pass NULL for any of the channels to leave it unchanged.
* If the call succeeds, it will return 0. If the display driver or
* hardware does not support gamma translation, or otherwise fails,
* this function will return -1.
*/
extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 * red,
const Uint16 * green,
const Uint16 * blue);

/*
* Retrieve the current values of the gamma translation tables.
*
* You must pass in valid pointers to arrays of 256 16-bit quantities.
* Any of the pointers may be NULL to ignore that channel.
* If the call succeeds, it will return 0. If the display driver or
* hardware does not support gamma translation, or otherwise fails,
* this function will return -1.
*/
extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 * red, Uint16 * green,
Uint16 * blue);

/*
* Maps an RGB triple to an opaque pixel value for a given pixel format
*/
Expand Down
17 changes: 2 additions & 15 deletions src/SDL_compat.c
Expand Up @@ -360,9 +360,8 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
if (flags & SDL_NOFRAME) {
window_flags |= SDL_WINDOW_BORDERLESS;
}
if (SDL_getenv("SDL_WINDOW_POS")) {
}
GetEnvironmentWindowPosition(width, height, &window_x, &window_y);
SDL_SetFullscreenDisplayMode(NULL);
SDL_VideoWindow =
SDL_CreateWindow(wm_title, window_x, window_y, width, height,
window_flags);
Expand Down Expand Up @@ -427,21 +426,9 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)

/* Set the desired display mode */
if (flags & SDL_FULLSCREEN) {
if (!SDL_GetClosestDisplayMode(&mode, &mode)) {
if (SDL_SetFullscreenDisplayMode(&mode) < 0) {
return NULL;
}
} else {
if (desktop_format) {
mode.format = desktop_format;
}
if (desktop_mode->w && desktop_mode->h) {
mode.w = desktop_mode->w;
mode.h = desktop_mode->h;
}
mode.refresh_rate = desktop_mode->refresh_rate;
}
if (SDL_SetDisplayMode(&mode) < 0) {
return NULL;
}

/* If we're in OpenGL mode, just create a stub surface and we're done! */
Expand Down
10 changes: 10 additions & 0 deletions src/events/SDL_windowevents.c
Expand Up @@ -44,19 +44,27 @@ SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
return 0;
}
window->flags |= SDL_WINDOW_SHOWN;
SDL_OnWindowShown(window);
break;
case SDL_WINDOWEVENT_HIDDEN:
if (!(window->flags & SDL_WINDOW_SHOWN)) {
return 0;
}
window->flags &= ~SDL_WINDOW_SHOWN;
SDL_OnWindowHidden(window);
break;
case SDL_WINDOWEVENT_MOVED:
if (window->flags & SDL_WINDOW_FULLSCREEN) {
return 0;
}
if (data1 == window->x && data2 == window->y) {
return 0;
}
break;
case SDL_WINDOWEVENT_RESIZED:
if (window->flags & SDL_WINDOW_FULLSCREEN) {
return 0;
}
if (data1 == window->w && data2 == window->h) {
return 0;
}
Expand Down Expand Up @@ -96,12 +104,14 @@ SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
return 0;
}
window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
SDL_OnWindowFocusGained(window);
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
if (!(window->flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
return 0;
}
window->flags &= ~SDL_WINDOW_KEYBOARD_FOCUS;
SDL_OnWindowFocusLost(window);
break;
}

Expand Down

0 comments on commit d8b35a1

Please sign in to comment.