From 9fff17787b195e53ff0d9ef97b8579b57fc10c85 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 17 Feb 2022 14:29:12 +0200 Subject: Fixed mismatched banner and background There was an issue with loss of color precision. Saturation dropped to zero when converting to 8-bit RGB. --- src/gmdocument.c | 6 +++--- src/ui/color.c | 4 ++-- src/ui/color.h | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/gmdocument.c b/src/gmdocument.c index bc0cc073..79deb861 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c @@ -1569,7 +1569,7 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *paletteSeed, const iB if (theme == colorfulDark_GmDocumentTheme) { iHSLColor base = { hues[primIndex], - 0.8f * (d->themeSeed >> 24) / 255.0f, + 0.8f * (d->themeSeed >> 24) / 255.0f + minSat_HSLColor, 0.06f + 0.09f * ((d->themeSeed >> 5) & 0x7) / 7.0f, 1.0f }; iHSLColor altBase = { altHue, base.sat, base.lum, 1 }; @@ -1579,13 +1579,13 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *paletteSeed, const iB setHsl_Color(tmBannerBackground_ColorId, addSatLum_HSLColor(base, 0.1f, 0.04f * (isBannerLighter ? 1 : -1))); setHsl_Color(tmBannerTitle_ColorId, setLum_HSLColor(addSatLum_HSLColor(base, 0.1f, 0), 0.55f)); setHsl_Color(tmBannerIcon_ColorId, setLum_HSLColor(addSatLum_HSLColor(base, 0.35f, 0), 0.65f)); - + // printf("primHue: %zu alts: %d %d isDarkBgSat: %d\n", // primIndex, // altHues[primIndex].index[altIndex[0]], // altHues[primIndex].index[altIndex[1]], // isDarkBgSat); - + const float titleLum = 0.2f * ((d->themeSeed >> 17) & 0x7) / 7.0f; setHsl_Color(tmHeading1_ColorId, setLum_HSLColor(altBase, titleLum + 0.80f)); setHsl_Color(tmHeading2_ColorId, setLum_HSLColor(altBase, titleLum + 0.70f)); diff --git a/src/ui/color.c b/src/ui/color.c index 824342ae..9cba322d 100644 --- a/src/ui/color.c +++ b/src/ui/color.c @@ -522,8 +522,8 @@ iHSLColor setLum_HSLColor(iHSLColor d, float lum) { } iHSLColor addSatLum_HSLColor(iHSLColor d, float sat, float lum) { - d.sat = iClamp(d.sat + sat, 0, 1); - d.lum = iClamp(d.lum + lum, 0, 1); + d.sat = iClamp(d.sat + sat, minSat_HSLColor, 1); + d.lum = iClamp(d.lum + lum, minSat_HSLColor, 1); return d; } diff --git a/src/ui/color.h b/src/ui/color.h index 24f9e713..f46976d7 100644 --- a/src/ui/color.h +++ b/src/ui/color.h @@ -231,6 +231,8 @@ struct Impl_HSLColor { float hue, sat, lum, a; }; +#define minSat_HSLColor 0.013f /* Conversion to 8-bit RGB may result in saturation dropping to zero. */ + iHSLColor hsl_Color (iColor); iColor rgb_HSLColor (iHSLColor); float luma_Color (iColor); -- cgit v1.2.3