File: C:/xampp/htdocs/PSASID/xyz2lab01.php
<?php
# ------- The graph values in the form of associative array
function xyz2lab01($v,$x,$y,$z) {
//116*(IF($y>0.885645,($y/100)^(1/3),7.787037*N4/100+0.137931))-16
//=500*((IF(M4>0.853957,(M4/96.422)^(1/3),(7.787037*(M4/96.422))+0.137931)-(IF(N4>0.885645,(N4/100)^(1/3),(7.787037*(N4/100))+0.137931))))
//Xr=SUMPRODUCT(xObs2,Illuminant_D)/SUMPRODUCT(yObs2,Illuminant_D)
$xObs2=array(0.00000000,0.00000000,0.00012990,0.00041490,0.00136800,0.00424300,0.01431000,0.04351000,0.13438000,0.28390000,0.34828000,0.33620000,0.29080000,0.19536000,0.09564000,0.03201000,0.00490000,0.00930000,0.06327000,0.16550000,0.29040000,0.43344990,0.59450000,0.76210000,0.91630000,1.02630000,1.06220000,1.00260000,0.85444990,0.64240000,0.44790000,0.28350000,0.16490000,0.08740000,0.04677000,0.02270000,0.01135916,0.00579035,0.00289933,0.00143997,0.00069008,0.00033230,0.00016615,0.00008308,0.00004151,0.00002067,0.00001025,0.00000509,0.00000252,0.00000125);
$yObs2=array(0.00000000,0.00000000,0.00000392,0.00001239,0.00003900,0.00012000,0.00039600,0.00121000,0.00400000,0.01160000,0.02300000,0.03800000,0.06000000,0.09098000,0.13902000,0.20802000,0.32300000,0.50300000,0.71000000,0.86200000,0.95400000,0.99495010,0.99500000,0.95200000,0.87000000,0.75700000,0.63100000,0.50300000,0.38100000,0.26500000,0.17500000,0.10700000,0.06100000,0.03200000,0.01700000,0.00821000,0.00410200,0.00209100,0.00104700,0.00052000,0.00024920,0.00012000,0.00006000,0.00003000,0.00001499,0.00000747,0.00000370,0.00000184,0.00000091,0.00000045);
$zObs2=array(0.00000000,0.00000000,0.00060610,0.00194600,0.00645000,0.02005001,0.06785001,0.20740000,0.64560000,1.38560000,1.74706000,1.77211000,1.66920000,1.28764000,0.81295010,0.46518000,0.27200000,0.15820000,0.07824999,0.04216000,0.02030000,0.00875000,0.00390000,0.00210000,0.00165000,0.00110000,0.00080000,0.00034000,0.00019000,0.00005000,0.00002000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000);
$Illuminant_D50=array(17.92359251,20.97984690,23.91155525,25.88721873,24.44787131,29.82884783,49.24662432,56.44974161,59.97316328,57.76397462,74.76665430,87.18888670,90.55862245,91.32148318,95.06664045,91.92938998,95.69666845,96.59098269,97.11313634,102.08728985,100.74727524,102.31336445,100.00000000,97.73786419,98.92449973,93.51129849,97.70746200,99.29398635,99.07048594,95.75347494,98.89672375,95.70870899,98.23790088,103.05864288,99.18921398,87.42787612,91.65706801,92.93751528,76.89465208,86.55502308,92.62591564,78.26849873,57.72160338,82.96554465,78.31323794,79.59465208,73.43831323,63.95178888,70.81215987,74.47902029);
//Zr==SUMPRODUCT(zObs2,Illuminant_D)/SUMPRODUCT(yObs2,Illuminant_D)
$sPSum=0;
$sPSum2=0;
$sProduct=0;
$sProduct2=0;
for ( $i = 34; $i <= 83; $i += 1) {
$sProduct=$xObs2[$i-34]*$Illuminant_D50[$i-34];
$sPSum=$sProduct+$sPSum;
$sProduct2=$yObs2[$i-34]*$Illuminant_D50[$i-34];
$sPSum2=$sProduct2+$sPSum2;
}
$Xr=$sPSum/$sPSum2;
$sPSum=0;
$sPSum2=0;
$sProduct=0;
$sProduct2=0;
for ( $i = 34; $i <= 83; $i += 1) {
$sProduct=$zObs2[$i-34]*$Illuminant_D50[$i-34];
$sPSum=$sProduct+$sPSum;
$sProduct2=$yObs2[$i-34]*$Illuminant_D50[$i-34];
$sPSum2=$sProduct2+$sPSum2;
}
$Zr=$sPSum/$sPSum2;
if ($v=="l") {
if ($y>0.00885645) {
$l=116*(pow(($y/1),(1/3)))-16;}
else {
$l=116*(((903.3*$y)+16)/116)-16;
}
return round($l,2);
}
if ($v=="a") {
if ($x/$Xr>0.00853957) {
if ($y>0.00885645) {
$a=500*((pow(($x/$Xr),1/3))-pow(($y/1),(1/3)));}
else {
$a=500*((pow(($x/$Xr),1/3))-(((903.3*$y)+16)/116));}
}
else {
if ($y>0.00885645) {
$a=500*((((903.3*$x/$Xr)+16)/116)-pow(($y/1),(1/3)));}
else {
$a=500*((((903.3*$x/$Xr)+16)/116)-(((903.3*$y)+16)/116));}
}
return round($a,2);
}
if ($v=="b") {
if ($y>0.00885645) {
if ($z/$Zr>0.00885645) {
$b=200*((pow(($y/1),1/3))-pow(($z/$Zr),(1/3)));}
else {
$b=200*((pow(($y/1),1/3))-(((903.3*$z/$Zr)+16)/116));}
}
else {
if ($z/$Zr>0.00885645) {
$b=200*((((903.3*$y)+16)/116)-pow(($z/$Zr),(1/3)));}
else {
$b=200*((((903.3*$y)+16)/116)-(((903.3*$z/$Zr)+16)/116));}
}
return round($b,2);
}
}
?>