From 716eacfc7c2301fa20fdc71d473d4def8f790adb Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 15 Feb 2015 19:36:02 +0100 Subject: Use floating point color values in [0,1] Internal color representation is [0,1] now for every channel. --- palettes.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'palettes.c') diff --git a/palettes.c b/palettes.c index eb5700b..9251e93 100644 --- a/palettes.c +++ b/palettes.c @@ -58,9 +58,9 @@ static void parse_palettes(xmlNode *node) { while (isspace( (int)val[c_idx])) c_idx++; - pal->colors[col_count][0] = r; - pal->colors[col_count][1] = g; - pal->colors[col_count][2] = b; + pal->colors[col_count][0] = (double)r/255.0; + pal->colors[col_count][1] = (double)g/255.0; + pal->colors[col_count][2] = (double)b/255.0; col_count++; } while (col_countmaxa) { maxa = a; - maxc = cbuf[rgbi]/PREFILTER_WHITE; + maxc = cbuf[rgbi]; } } /* If a channel is saturated and we have a non-negative highlight power */ /* modify the color to prevent hue shift */ - if (maxa>255 && highpow>=0.0) { - newls = 255.0/maxc; + if (maxa > 1.0 && highpow>=0.0) { + newls = 1.0/maxc; lsratio = pow(newls/ls,highpow); /* Calculate the max-value color (ranged 0 - 1) */ - double4 newrgb = newls*(cbuf/PREFILTER_WHITE)/255.0; + double4 newrgb = newls*(cbuf); /* Reduce saturation by the lsratio */ double4 newhsv = rgb2hsv(newrgb); newhsv[1] *= lsratio; - return hsv2rgb(newhsv) * 255.0; + return hsv2rgb(newhsv); } else { - newls = 255.0/maxc; + newls = 1.0/maxc; adjhlp = -highpow; if (adjhlp>1) adjhlp=1; - if (maxa<=255) + if (maxa<=1.0) adjhlp=1.0; /* Calculate the max-value color (ranged 0 - 1) interpolated with the old * behaviour */ - return ((1.0-adjhlp)*newls + adjhlp*ls)*(cbuf/PREFILTER_WHITE); + return ((1.0-adjhlp)*newls + adjhlp*ls)*(cbuf); } } -- cgit v1.2.3