Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Gamma support is back!

New API functions:
	SDL_SetWindowBrightness()
	SDL_GetWindowBrightness()
	SDL_SetWindowGammaRamp()
	SDL_GetWindowGammaRamp()
	SDL_CalculateGammaRamp()
  • Loading branch information
slouken committed Mar 11, 2011
1 parent 61a504d commit 3c61e9a7cee3c59a00fad547efb9fa03d28550e9
@@ -103,8 +103,8 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Copy SDL"
CommandLine="copy $(SolutionDir)\SDL\$(ConfigurationName)\SDL.dll $(TargetDir)\SDL.dll"
Description="Copy SDL and data files"
CommandLine="copy $(SolutionDir)\SDL\$(ConfigurationName)\SDL.dll $(TargetDir)\SDL.dll&#x0D;&#x0A;copy $(SolutionDir)\..\test\sample.bmp $(ProjectDir)\sample.bmp"
/>
</Configuration>
<Configuration
@@ -195,8 +195,8 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Copy SDL"
CommandLine="copy $(SolutionDir)\SDL\$(ConfigurationName)\SDL.dll $(TargetDir)\SDL.dll"
Description="Copy SDL and data files"
CommandLine="copy $(SolutionDir)\SDL\$(ConfigurationName)\SDL.dll $(TargetDir)\SDL.dll&#x0D;&#x0A;copy $(SolutionDir)\..\test\sample.bmp $(ProjectDir)\sample.bmp"
/>
</Configuration>
</Configurations>
@@ -82,10 +82,11 @@
<SubSystem>Windows</SubSystem>
</Link>
<PostBuildEvent>
<Command>copy $(SolutionDir)\SDL\$(ConfigurationName)\SDL.dll $(TargetDir)\SDL.dll</Command>
<Command>copy $(SolutionDir)\SDL\$(ConfigurationName)\SDL.dll $(TargetDir)\SDL.dll
copy $(SolutionDir)\..\test\sample.bmp $(ProjectDir)\sample.bmp</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>Copy SDL</Message>
<Message>Copy SDL and data files</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -125,10 +126,11 @@
<SubSystem>Windows</SubSystem>
</Link>
<PostBuildEvent>
<Command>copy $(SolutionDir)\SDL\$(ConfigurationName)\SDL.dll $(TargetDir)\SDL.dll</Command>
<Command>copy $(SolutionDir)\SDL\$(ConfigurationName)\SDL.dll $(TargetDir)\SDL.dll
copy $(SolutionDir)\..\test\sample.bmp $(ProjectDir)\sample.bmp</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>Copy SDL</Message>
<Message>Copy SDL and data files</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
@@ -405,6 +405,12 @@ extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
Uint8 * r, Uint8 * g, Uint8 * b,
Uint8 * a);

/**
* \brief Calculate a 256 entry gamma ramp for a gamma value.
*/
extern DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, Uint16 * ramp);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -604,6 +604,66 @@ extern DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_Window * window,
*/
extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowGrab(SDL_Window * window);

/**
* \brief Set the brightness (gamma correction) for a window.
*
* \return 0 on success, or -1 if setting the brightness isn't supported.
*
* \sa SDL_GetWindowBrightness()
* \sa SDL_SetWindowGammaRamp()
*/
extern DECLSPEC int SDLCALL SDL_SetWindowBrightness(SDL_Window * window, float brightness);

/**
* \brief Get the brightness (gamma correction) for a window.
*
* \return The last brightness value passed to SDL_SetWindowBrightness()
*
* \sa SDL_SetWindowBrightness()
*/
extern DECLSPEC float SDLCALL SDL_GetWindowBrightness(SDL_Window * window);

/**
* \brief Set the gamma ramp for a window.
*
* \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_SetWindowGammaRamp()
*/
extern DECLSPEC int SDLCALL SDL_SetWindowGammaRamp(SDL_Window * window,
const Uint16 * red,
const Uint16 * green,
const Uint16 * blue);

/**
* \brief Get the gamma ramp for a window.
*
* \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_SetWindowGammaRamp()
*/
extern DECLSPEC int SDLCALL SDL_GetWindowGammaRamp(SDL_Window * window,
Uint16 * red,
Uint16 * green,
Uint16 * blue);

/**
* \brief Destroy a window.
*/
@@ -1702,22 +1702,34 @@ SDL_GL_SwapBuffers(void)
int
SDL_SetGamma(float red, float green, float blue)
{
SDL_Unsupported();
return -1;
Uint16 red_ramp[256];
Uint16 green_ramp[256];
Uint16 blue_ramp[256];

SDL_CalculateGammaRamp(red, red_ramp);
if (green == red) {
SDL_memcpy(green_ramp, red_ramp, sizeof(red_ramp));
} else {
SDL_CalculateGammaRamp(green, green_ramp);
}
if (blue == red) {
SDL_memcpy(blue_ramp, red_ramp, sizeof(red_ramp));
} else {
SDL_CalculateGammaRamp(blue, blue_ramp);
}
return SDL_SetWindowGammaRamp(SDL_VideoWindow, red_ramp, green_ramp, blue_ramp);
}

int
SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue)
{
SDL_Unsupported();
return -1;
return SDL_SetWindowGammaRamp(SDL_VideoWindow, red, green, blue);
}

int
SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue)
{
SDL_Unsupported();
return -1;
return SDL_GetWindowGammaRamp(SDL_VideoWindow, red, green, blue);
}

int
@@ -1041,4 +1041,36 @@ SDL_FreeBlitMap(SDL_BlitMap * map)
}
}

void
SDL_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 if (gamma == 1.0f) {
/* 1.0 gamma is identity */
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;
}
}
}

/* vi: set ts=4 sw=4 expandtab: */
@@ -81,6 +81,10 @@ struct SDL_Window

SDL_DisplayMode fullscreen_mode;

float brightness;
Uint16 *gamma;
Uint16 *saved_gamma; /* (just offset into gamma) */

SDL_Surface *surface;
SDL_bool surface_valid;

@@ -184,6 +188,8 @@ struct SDL_VideoDevice
void (*MinimizeWindow) (_THIS, SDL_Window * window);
void (*RestoreWindow) (_THIS, SDL_Window * window);
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
void (*SetWindowGrab) (_THIS, SDL_Window * window);
void (*DestroyWindow) (_THIS, SDL_Window * window);
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);

0 comments on commit 3c61e9a

Please sign in to comment.