This is still a motherfucking website.
And it's more fucking perfect than the last guy's.
Seriously, it takes minimal fucking effort to improve this shit.
//rgb 8 bits
int r = 255, g = 255, b = 255;
//sRGB (r', g' et b')
double rp = 0.0, gp = 0.0, bp = 0.0;
//L
double luma = 0.0;
convertir ici la couleur de fond, peu importe la méthode et la source, et stocker les composantes RGB (valeurs entières sur 8 bits, donc de 0 à 255 pour chaque composante) dans r, g et b.
//Rec.709
//luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
//Rec.601
//luma = 0.299 * r + 0.587 * g + 0.114 * b;
//Relative luminance from sRGB
//https://www.w3.org/TR/WCAG20/relative-luminance.xml
rp = r / 255.0;
gp = g / 255.0;
bp = b / 255.0;
if (rp <= 0.03928) rp = rp / 12.92; else rp = Math.Pow((rp + 0.055) / 1.055, 2.4);
if (gp <= 0.03928) gp = gp / 12.92; else gp = Math.Pow((gp + 0.055) / 1.055, 2.4);
if (bp <= 0.03928) bp = bp / 12.92; else bp = Math.Pow((bp + 0.055) / 1.055, 2.4);
luma = (0.2126 * rp) + (0.7152 * gp) + (0.0722 * bp);
//http://www.w3.org/TR/WCAG20/#contrast-ratiodef
return luma > 0.179 ? "#000000" : "#ffffff";
À noter :
Avec Rec.2020 :
luma = 0.2627 * r + 0.678 * g + 0.0593 * b
À noter aussi :
Pour plus d'infos : https://www.itu.int/rec/R-REC-BT.2020-2-201510-I/en
Code Boxx is all about inspiring your inner programmer. We offer web development tips and have various free tutorials for HTML, CSS, JS, PHP, etc...