First color must be text, second color must be the background.
APCAcontrast()
requires Ys (display luminance)
sRGBtoY()
requires an sRGB color array 0-255
displayP3toY()
requires a displayP3 RGB color array 0.0-1.0
adobeRGBtoY()
requires an Adobe98 RGB color array 0-255
colorParsley()
parses string to an RGB color array 0-255
alphaBlend()
blends FG color with alpha to BG, returns array
calcAPCA(textString,bgString)
shortcut, takes strings, text allows alpha
Lc = APCAcontrast(sRGBtoY( alphaBlend(colorParsley(color8),colorParsley(color2)) ), sRGBtoY(colorParsley(color2)));
If you've implemented the code and want a quick sanity check, Here are some keystone checks with no rounding. The first color is TEXT and the second color is BACKGROUND:
Test Values for the 0.1.0 G constants, normal and reverse float values for each color pair.
First number is TEXT second number is BACKGROUND.
#888 vs #fff • 63.056469930209424
#fff vs #888 • -68.54146436644962
#000 vs #aaa • 58.146262578561334
#aaa vs #000 • -56.24113336839742
#123 vs #def • 91.66830811481631
#def vs #123 • -93.06770049484275
#123 vs #444 • 8.32326136957393
#234 vs #444 • -7.526878460278154
These exercise all the important constants.