2023年4月11日 星期二

RGB to XYZ code example by delphi

procedure XYZToLab(X, Y, Z: Double; out L, a, b: Double);

const

  Xn = 95.047;

  Yn = 100.000;

  Zn = 108.883;

var

  fx, fy, fz: Double;

begin

  // calculate the relative luminance

  fy := Power(Y/Yn, 1/3);

  if Y/Yn <= 0.008856 then

    fy := 7.787 * Y/Yn + 16/116;


  // calculate a and b

  fx := Power(X/Xn, 1/3);

  if X/Xn <= 0.008856 then

    fx := 7.787 * X/Xn + 16/116;


  fz := Power(Z/Zn, 1/3);

  if Z/Zn <= 0.008856 then

    fz := 7.787 * Z/Zn + 16/116;


  L := 116 * fy - 16;

  a := 500 * (fx - fy);

  b := 200 * (fy - fz);

end;





 var

  X, Y, Z, L, a, b: Double;

begin

  // set the XYZ color values

  X := 45.242;

  Y := 52.876;

  Z := 73.215;


  // convert the XYZ color to CIELAB

  XYZToLab(X, Y, Z, L, a, b);


  // output the CIELAB color values

  ShowMessage(Format('L* = %f, a* = %f, b* = %f', [L, a, b]));

end;


沒有留言: