From b2fa10ae5be608722bc86972453354d0391a023d Mon Sep 17 00:00:00 2001 From: siavash Date: Thu, 4 Jul 2013 23:42:18 +0430 Subject: [PATCH] Small tweaks. --- src/gamma.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gamma.c b/src/gamma.c index c538b590..1ec3b0e5 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -81,18 +81,18 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) for (i = 0; i < 256; i++) { - float value; + float inv255, value; // Calculate intensity - value = i / 255.f; + inv255 = 1.f / 255.f; + value = i * inv255; // Apply gamma curve - value = (float) pow(value, 1.f / gamma) * 65535.f + 0.5f; + value = powf(value, 1.f / gamma) * 65535.f + 0.5f; // Clamp to value range - if (value < 0.f) - value = 0.f; - else if (value > 65535.f) - value = 65535.f; + // There isn't any need to check for values smaller than zero. + // It is always positive and bigger than 0.5f. + value = value < 65535.f ? value : 65535.f; values[i] = (unsigned short) value; }