Question about sRGB --> XYZ and back lazarus / 39-Graphics ---------------------------------------------------------------------- stab · 2022-02-11 21:53 Have tried the equations given by EasyRGB to convert from sRGB to XYZ and back again. From sRGB to XYZ gave exactly the same result as EasyRGBs' Color Calculator, but when converting back again gave wrong result. Start with sR:64, sG:128, sB:255 gave                X:27.877, Y:23.745, Z:97.702 back gave sR:64, sG:176, sB:249 Procedure for XYZ --> sRGB conversion: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure XYZTosRGB(X, Y, Z : double; var sR, sG, sB : byte);var  var_X, var_Y, var_Z : double;   function Adjust(s : double) : double;  begin    if s > 0.0031308 then      Result := 1.055 * Power(s, 1.0 / 2.4) - 0.055  else      Result := 12.92 * s;  end; begin  //X, Y and Z input refer to a D65/standard illuminant.  //sR, sG and sB (standard RGB) output2°  range := 0 ÷ 255   var_X := X / 100;  var_Y := Y / 100;  var_Z := Z / 100;   var_X := var_X *  3.2406 + var_Y * -1.5372 + var_Z * -0.4986;  var_Y := var_X * -0.9689 + var_Y *  1.8758 + var_Z *  0.0415;  var_Z := var_X *  0.0557 + var_Y * -0.2040 + var_Z *  1.0570;   var_X := Adjust(var_X);  var_Y := Adjust(var_Y);  var_Z := Adjust(var_Z);   sR := Round(var_X * 255);  sG := Round(var_Y * 255);  sB := Round(var_Z * 255);end;   Thankful for any suggestions to what I'm doing wrong ---------------------------------------------------------------------- winni · 2022-02-12 00:53 Hi! Don't reinvent the wheel. Use BGRAbitmap. Read https://wiki.freepascal.org/BGRABitmap And look for: ConvertToLinearRGB : to convert from sRGB to RGB. ConvertFromLinearRGB : viceversa Winni ---------------------------------------------------------------------- stab · 2022-02-12 14:00 Thanks for your response. Noticed in Circulars response about  New version of BGRABitmap in August 20, 2018 that it is possible to convert to many color spaces with BGRABitmap. I'll try to read his colorspace demoapp carefully