ThePacielloGroup / CCAe

The Colour Contrast Analyser (CCA) helps you determine the legibility of text and the contrast of visual elements, such as graphical controls and visual indicators.
http://www.paciellogroup.com/resources/contrastanalyser/
GNU General Public License v3.0
468 stars 105 forks source link

Wrong number when calculating luminosity? #318

Closed eric-g-97477 closed 7 months ago

eric-g-97477 commented 8 months ago

Looking at color.js, I see the following function:

    luminosity: function () {
        // http://www.w3.org/TR/WCAG20/#relativeluminancedef
        var rgb = this.rgb().color;

        var lum = [];
        for (var i = 0; i < rgb.length; i++) {
            var chan = rgb[i] / 255;
            lum[i] = (chan <= 0.04045) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4);
        }

        return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
    },

Focusing on (chan <= 0.04045), I looked at http://www.w3.org/TR/WCAG20/#relativeluminancedef and saw if RsRGB <= 0.03928 then R = RsRGB/12.92 else R = ((RsRGB+0.055)/1.055) ^ 2.4

Shouldn't 0.04045 be 0.03928? Or, what is the reason for the discrepancy? I have not understood something?

ferllings commented 8 months ago

The link is outdated, it should refer to WCAG 2.1. The value as been adjusted in WCAG 2.1: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance