下面算法 摘自:http://www.cnblogs.com/dishuostec/archive/2011/09/07/2170148.html
(返回值范围:0~100)
function getLight(rgbHex)
{
var color = parseInt(rgbHex, 16);
var y = (0.2973769 * ((color & 0xff0000) >> 16) + 0.6273491 * ((color & 0xff00) >> 8) + 0.0752741 * (color & 0xff)) / 255;
if (y > 0.008856)
{
return 116 * Math.pow(y, 1/3) - 16;
}
else
{
return 903.29629629 * y;
}
}
{
var color = parseInt(rgbHex, 16);
var y = (0.2973769 * ((color & 0xff0000) >> 16) + 0.6273491 * ((color & 0xff00) >> 8) + 0.0752741 * (color & 0xff)) / 255;
if (y > 0.008856)
{
return 116 * Math.pow(y, 1/3) - 16;
}
else
{
return 903.29629629 * y;
}
}
参考资料:Lab色彩空间