mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-08-17 17:02:51 +08:00
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.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user