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
This commit is contained in:
Yves Rizoud 2010-08-24 18:27:39 +00:00
parent cf417c9bb9
commit 03a813baec

View File

@ -2834,6 +2834,22 @@ void Compute_optimal_menu_colors(T_Components * palette)
MC_Black = i; 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 // Find color nearest to min+2(max-min)/3
// but at the same time we try to minimize the saturation so that the menu // 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++) 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; MC_Light = i;
} }
} }
// Target "Dark color" is halfway between Light and Black // Target "Dark color" is 2/3 between Light and Black
low_l = ((int)l[MC_Light]+l[MC_Black])/2; low_l = ((int)l[MC_Light]*2+l[MC_Black])/3;
for (i = 0; i < 256; i++) 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; MC_Dark = i;
} }
} }