1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Fix glfwSetGamma generating ramps of invalid sizes

This makes glfwSetGamma generate a gamma ramp of the same size as the
monitor's current ramp, which will avoid failure on non-256 entry
monitors on X11 and avoid ramp interpolation on macOS.

Closes #1387.
Fixes #1388.
This commit is contained in:
Camilla Löwy 2018-12-17 17:40:18 +01:00
parent 52c7a4fc7f
commit 3531c320af
3 changed files with 20 additions and 10 deletions

View File

@ -197,6 +197,8 @@ information on what to include when reporting a bug.
- Bugfix: Invalid library paths were used in test and example CMake files (#930) - Bugfix: Invalid library paths were used in test and example CMake files (#930)
- Bugfix: The scancode for synthetic key release events was always zero - Bugfix: The scancode for synthetic key release events was always zero
- Bugfix: The generated Doxyfile did not handle paths with spaces (#1081) - Bugfix: The generated Doxyfile did not handle paths with spaces (#1081)
- Bugfix: The gamma ramp generated by `glfwSetGamma` did not use the monitor
ramp size (#1387,#1388)
- [Win32] Added system error strings to relevant GLFW error descriptions (#733) - [Win32] Added system error strings to relevant GLFW error descriptions (#733)
- [Win32] Moved to `WM_INPUT` for disabled cursor mode motion input (#125) - [Win32] Moved to `WM_INPUT` for disabled cursor mode motion input (#125)
- [Win32] Removed XInput circular deadzone from joystick axis data (#1045) - [Win32] Removed XInput circular deadzone from joystick axis data (#1045)

View File

@ -2156,9 +2156,9 @@ GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor);
/*! @brief Generates a gamma ramp and sets it for the specified monitor. /*! @brief Generates a gamma ramp and sets it for the specified monitor.
* *
* This function generates a 256-element gamma ramp from the specified exponent * This function generates an appropriately sized gamma ramp from the specified
* and then calls @ref glfwSetGammaRamp with it. The value must be a finite * exponent and then calls @ref glfwSetGammaRamp with it. The value must be
* number greater than zero. * a finite number greater than zero.
* *
* The software controlled gamma ramp is applied _in addition_ to the hardware * The software controlled gamma ramp is applied _in addition_ to the hardware
* gamma correction, which today is usually an approximation of sRGB gamma. * gamma correction, which today is usually an approximation of sRGB gamma.
@ -2237,8 +2237,8 @@ GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR. * GLFW_PLATFORM_ERROR.
* *
* @remark Gamma ramp sizes other than 256 are not supported by all platforms * @remark The size of the specified gamma ramp should match the size of the
* or graphics hardware. * current ramp for that monitor.
* *
* @remark @win32 The gamma ramp size must be 256. * @remark @win32 The gamma ramp size must be 256.
* *

View File

@ -427,9 +427,10 @@ GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* handle)
GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
{ {
int i; unsigned int i;
unsigned short values[256]; unsigned short* values;
GLFWgammaramp ramp; GLFWgammaramp ramp;
const GLFWgammaramp* original;
assert(handle != NULL); assert(handle != NULL);
assert(gamma > 0.f); assert(gamma > 0.f);
assert(gamma <= FLT_MAX); assert(gamma <= FLT_MAX);
@ -442,12 +443,18 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
return; return;
} }
for (i = 0; i < 256; i++) original = glfwGetGammaRamp(handle);
if (!original)
return;
values = calloc(original->size, sizeof(unsigned short));
for (i = 0; i < original->size; i++)
{ {
float value; float value;
// Calculate intensity // Calculate intensity
value = i / 255.f; value = i / (float) (original->size - 1);
// Apply gamma curve // Apply gamma curve
value = powf(value, 1.f / gamma) * 65535.f + 0.5f; value = powf(value, 1.f / gamma) * 65535.f + 0.5f;
// Clamp to value range // Clamp to value range
@ -459,9 +466,10 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
ramp.red = values; ramp.red = values;
ramp.green = values; ramp.green = values;
ramp.blue = values; ramp.blue = values;
ramp.size = 256; ramp.size = original->size;
glfwSetGammaRamp(handle, &ramp); glfwSetGammaRamp(handle, &ramp);
free(values);
} }
GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* handle) GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* handle)