From 5301512a4755d23c353c0f80b3748eea1a22e30c Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Tue, 20 Aug 2024 15:40:50 -0500 Subject: [PATCH 1/3] Improve the color selection for selection foreground --- src/renderer/atlas/AtlasEngine.api.cpp | 4 ++-- src/renderer/atlas/AtlasEngine.cpp | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/renderer/atlas/AtlasEngine.api.cpp b/src/renderer/atlas/AtlasEngine.api.cpp index f5ddc5a000d..876fc558326 100644 --- a/src/renderer/atlas/AtlasEngine.api.cpp +++ b/src/renderer/atlas/AtlasEngine.api.cpp @@ -432,8 +432,8 @@ void AtlasEngine::SetSelectionBackground(const COLORREF color) noexcept { auto misc = _api.s.write()->misc.write(); misc->selectionColor = selectionColor; - // Selection Foreground is based on the default foreground; it is also updated in UpdateDrawingBrushes - misc->selectionForeground = 0xff000000 | ColorFix::GetPerceivableColor(misc->foregroundColor, color, 0.5f * 0.5f); + // Selection foreground is based on pushing the selection background as far as possible towards white or black, whichever results in more contrast. + misc->selectionForeground = 0xff000000 | ColorFix::GetPerceivableColor(selectionColor, 0x7f7f7f, 10.f); } } diff --git a/src/renderer/atlas/AtlasEngine.cpp b/src/renderer/atlas/AtlasEngine.cpp index 6aa8bff265a..18e415a5996 100644 --- a/src/renderer/atlas/AtlasEngine.cpp +++ b/src/renderer/atlas/AtlasEngine.cpp @@ -658,10 +658,7 @@ try if (textAttributes.GetForeground().IsDefault() && fg != _api.s->misc->foregroundColor) { - auto misc = _api.s.write()->misc.write(); - misc->foregroundColor = fg; - // Selection Foreground is based on the default foreground; it is also updated in SetSelectionColor - misc->selectionForeground = 0xff000000 | ColorFix::GetPerceivableColor(fg, misc->selectionColor, 0.5f * 0.5f); + _api.s.write()->misc.write()->foregroundColor = fg; } } From c0549cd44a05fd2cd1a6f50d3eec643f5026e68b Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Tue, 20 Aug 2024 16:02:27 -0500 Subject: [PATCH 2/3] Improve it more --- src/renderer/atlas/AtlasEngine.api.cpp | 4 ++-- src/types/ColorFix.cpp | 5 +++++ src/types/inc/ColorFix.hpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/renderer/atlas/AtlasEngine.api.cpp b/src/renderer/atlas/AtlasEngine.api.cpp index 876fc558326..1a065358bb1 100644 --- a/src/renderer/atlas/AtlasEngine.api.cpp +++ b/src/renderer/atlas/AtlasEngine.api.cpp @@ -432,8 +432,8 @@ void AtlasEngine::SetSelectionBackground(const COLORREF color) noexcept { auto misc = _api.s.write()->misc.write(); misc->selectionColor = selectionColor; - // Selection foreground is based on pushing the selection background as far as possible towards white or black, whichever results in more contrast. - misc->selectionForeground = 0xff000000 | ColorFix::GetPerceivableColor(selectionColor, 0x7f7f7f, 10.f); + // Select a black or white foreground based on the perceptual lightness of the background. + misc->selectionForeground = ColorFix::GetLuminosity(selectionColor) <= 0.5f ? 0xffffffff : 0xff000000; } } diff --git a/src/types/ColorFix.cpp b/src/types/ColorFix.cpp index eda47d396a2..7648de22622 100644 --- a/src/types/ColorFix.cpp +++ b/src/types/ColorFix.cpp @@ -209,4 +209,9 @@ COLORREF ColorFix::GetPerceivableColor(COLORREF color, COLORREF reference, float return linearToColorref(oklab::oklab_to_linear_srgb(colorOklab)) | (color & 0xff000000); } +float ColorFix::GetLuminosity(COLORREF color) noexcept +{ + return oklab::linear_srgb_to_oklab(colorrefToLinear(color)).l; +} + TIL_FAST_MATH_END diff --git a/src/types/inc/ColorFix.hpp b/src/types/inc/ColorFix.hpp index 02bdc0631b3..24c4cf79f3f 100644 --- a/src/types/inc/ColorFix.hpp +++ b/src/types/inc/ColorFix.hpp @@ -10,4 +10,5 @@ namespace ColorFix { COLORREF GetPerceivableColor(COLORREF color, COLORREF reference, float minSquaredDistance) noexcept; + float GetLuminosity(COLORREF color) noexcept; } From 2522716dc9515387da8d5842050267ba184eb921 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Tue, 20 Aug 2024 19:22:25 -0700 Subject: [PATCH 3/3] Update src/renderer/atlas/AtlasEngine.api.cpp --- src/renderer/atlas/AtlasEngine.api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/atlas/AtlasEngine.api.cpp b/src/renderer/atlas/AtlasEngine.api.cpp index 1a065358bb1..6481d5b9059 100644 --- a/src/renderer/atlas/AtlasEngine.api.cpp +++ b/src/renderer/atlas/AtlasEngine.api.cpp @@ -433,7 +433,7 @@ void AtlasEngine::SetSelectionBackground(const COLORREF color) noexcept auto misc = _api.s.write()->misc.write(); misc->selectionColor = selectionColor; // Select a black or white foreground based on the perceptual lightness of the background. - misc->selectionForeground = ColorFix::GetLuminosity(selectionColor) <= 0.5f ? 0xffffffff : 0xff000000; + misc->selectionForeground = ColorFix::GetLuminosity(selectionColor) < 0.5f ? 0xffffffff : 0xff000000; } }