From c4fe911d197d14b318456012ba4e495ea3c8bca4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 29 Jul 2026 19:36:29 +0200 Subject: [PATCH] Link to the current WCAG21 instead of the old 2008 version Also update the coefficient in wxGetSRGB() to use the correct value, quoting the linked document: Note 2 Before May 2021 the value of 0.04045 in the definition was different (0.03928). It was taken from an older version of the specification and has been updated. It has no practical effect on the calculations in the context of these guidelines. --- include/wx/private/colour.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/wx/private/colour.h b/include/wx/private/colour.h index dc63c934a6..61f13a38ab 100644 --- a/include/wx/private/colour.h +++ b/include/wx/private/colour.h @@ -18,13 +18,14 @@ namespace wxPrivate { -inline float wxGetSRGB(float r) { - return r <= 0.03928f ? r / 12.92f : std::pow((r + 0.055f) / 1.055f, 2.4f); +inline float wxGetSRGB(float r) +{ + return r <= 0.04045f ? r / 12.92f : std::pow((r + 0.055f) / 1.055f, 2.4f); } inline float wxGetRelativeLuminance(const wxColour& c) { - // based on https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef + // See https://www.w3.org/TR/WCAG21/#dfn-relative-luminance return 0.2126f * wxGetSRGB(c.Red() / 255.0f) + 0.7152f * wxGetSRGB(c.Green() / 255.0f) + @@ -33,7 +34,7 @@ inline float wxGetRelativeLuminance(const wxColour& c) inline float wxComputeContrast(const wxColour& c1, const wxColour& c2) { - // based on https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast7.html + // See https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio float L1 = wxGetRelativeLuminance(c1); float L2 = wxGetRelativeLuminance(c2); return L1 > L2 ? (L1 + 0.05f) / (L2 + 0.05f) : (L2 + 0.05f) / (L1 + 0.05f); @@ -43,7 +44,7 @@ inline float wxComputeContrast(const wxColour& c1, const wxColour& c2) // Return the colour if it has sufficient contrast ratio (4.5 recommended) // with the background or return either white or black if it doesn't. -// (based on https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast7.html) +// (see https://www.w3.org/TR/WCAG21/#contrast-minimum) inline wxColour wxGetContrastingFgColour(const wxColour& fg, const wxColour& bg) {