Skip to content

Commit

Permalink
fix: better precision on xyz/srgb conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignigena authored and Qix- committed Jan 9, 2020
1 parent 7b106c4 commit 3f0e0d4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ convert.rgb.xyz = function (rgb) {
g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92);
b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92);

const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
const x = (r * 0.4124564) + (g * 0.3575761) + (b * 0.1804375);
const y = (r * 0.2126729) + (g * 0.7151522) + (b * 0.072175);
const z = (r * 0.0193339) + (g * 0.119192) + (b * 0.9503041);

return [x * 100, y * 100, z * 100];
};
Expand Down Expand Up @@ -415,9 +415,9 @@ convert.xyz.rgb = function (xyz) {
let g;
let b;

r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
r = (x * 3.2404542) + (y * -1.5371385) + (z * -0.4985314);
g = (x * -0.969266) + (y * 1.8760108) + (z * 0.041556);
b = (x * 0.0556434) + (y * -0.2040259) + (z * 1.0572252);

// Assume sRGB
r = r > 0.0031308
Expand Down

0 comments on commit 3f0e0d4

Please sign in to comment.