From 03a813baec15752424c576142690d4498137652e Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Tue, 24 Aug 2010 18:27:39 +0000 Subject: [PATCH] More work on auto-detcting GUI colors. Fixes the cases like the 16-color ramp black->yellow reported by DawnBringer. Seems to work better with many 4-color cpc palettes git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1590 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/windows.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/windows.c b/src/windows.c index 4f1b4c29..35c8b67c 100644 --- a/src/windows.c +++ b/src/windows.c @@ -2834,6 +2834,22 @@ void Compute_optimal_menu_colors(T_Components * palette) MC_Black = i; } } + // Alter the S values according to the L range - this is for the future + // comparisons, so that highly variable saturation doesn't weigh + // too heavily when the the lightness is in a narrow range. + for(i = 0; i < 256; i++) + { + s[i]=s[i]*(max_l-min_l)/255; + } + // Adjust (reduce) perceived saturation at both ends of L spectrum + for(i = 0; i < 256; i++) + { + if (l[i]>192) + s[i]=s[i]*(255-l[i])/64; + else if (l[i]<64) + s[i]=s[i]*l[i]/64; + } + // Find color nearest to min+2(max-min)/3 // but at the same time we try to minimize the saturation so that the menu @@ -2842,20 +2858,20 @@ void Compute_optimal_menu_colors(T_Components * palette) for (i = 0; i < 256; i++) { - if ( abs(l[i] - hi_l) + s[i]/4 < delta_high && i!=MC_White && i!=MC_Black) + if ( abs(l[i] - hi_l) + s[i]/6 < delta_high && i!=MC_White && i!=MC_Black) { - delta_high = abs(l[i] - hi_l) + s[i]/4; + delta_high = abs(l[i] - hi_l) + s[i]/6; MC_Light = i; } } - // Target "Dark color" is halfway between Light and Black - low_l = ((int)l[MC_Light]+l[MC_Black])/2; + // Target "Dark color" is 2/3 between Light and Black + low_l = ((int)l[MC_Light]*2+l[MC_Black])/3; for (i = 0; i < 256; i++) { - if ( abs((int)l[i] - low_l) + s[i]/4 < delta_low && i!=MC_White && i!=MC_Black && i!=MC_Light) + if ( abs((int)l[i] - low_l) + s[i]/6 < delta_low && i!=MC_White && i!=MC_Black && i!=MC_Light) { - delta_low = abs((int)l[i] - low_l)+ s[i]/4; + delta_low = abs((int)l[i] - low_l)+ s[i]/6; MC_Dark = i; } }