From ae76d79b400a53705e2b4d5bb167a85dde1f3d55 Mon Sep 17 00:00:00 2001 From: Jeff Teunissen Date: Tue, 24 Oct 2000 01:43:35 +0000 Subject: [PATCH] Corrected algorithm, optimized code, and reversed the order of brightness/contrast operations... brightness is applied first, then contrast. A contrast of 0 is now /always/ solid medium grey. --- source/sw_view.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/source/sw_view.c b/source/sw_view.c index e29a498..96308a6 100644 --- a/source/sw_view.c +++ b/source/sw_view.c @@ -108,8 +108,7 @@ void V_UpdatePalette (void) void BuildGammaTable (float b, float c) { - int i, j; - int inf = 0; + int i, inf; if ((b == 1.0) && (c == 1.0)) { for (i = 0; i < 256; i++) @@ -117,19 +116,10 @@ BuildGammaTable (float b, float c) return; } - for (i=0 ; i<256 ; i++) { - if (!(i == 128)) { - if (i < 128) { - j = i + (int) ((128 - i) * (1 - c)); - } else { - j = i + (int) ((i - 128) * (1 - c)); - } - } else { - j = i; - } - inf = (j * b); // gamma is brightness now, and positive - inf = bound(0, inf, 255); - gammatable[i] = inf; + for (i=0 ; i<256 ; i++) { // weighted average toward the median, 127 + inf = (i * b); // gamma is brightness now, and positive + inf = bound (0, inf, 255); + gammatable[i] = inf + (int) ((127 - inf) * (1 - c)); } }