From 6690d4cdceb565515b248e169c09abaf756ab3fc Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 7 Aug 2014 22:40:10 +0200 Subject: derp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gamma.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gamma.c b/src/gamma.c index fa57fb4..66f2f38 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -38,7 +38,7 @@ void gamma_analyse(size_t stops, const uint16_t* restrict ramp, double* restrict middle = (double)(ramp[stops / 2]) / (double)0xFFFF; middle = (middle - min) / (max - min); - *gamma = log(middle) / log(2.0); + *gamma = log(2.0) / log(middle); } @@ -55,6 +55,7 @@ void gamma_generate(size_t stops, uint16_t* restrict ramp, double gamma, double contrast, double brightness) { double diff = contrast - brightness; + double gamma_ = 1.0 / gamma; size_t i; int32_t y; double y_; @@ -62,7 +63,7 @@ void gamma_generate(size_t stops, uint16_t* restrict ramp, double gamma, for (i = 0; i < stops; i++) { y_ = (double)i / (double)stops; - y_ = pow(y_, gamma) * diff + brightness; + y_ = pow(y_, gamma_) * diff + brightness; y = (int32_t)(y * 0xFFFF); if (y < 0x0000) y = 0x0000; if (y > 0xFFFF) y = 0xFFFF; -- cgit v1.2.3-70-g09d2