Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to convert XYZ to RGB and back #81

Closed
RobinBol opened this issue Mar 27, 2020 · 2 comments
Closed

Failure to convert XYZ to RGB and back #81

RobinBol opened this issue Mar 27, 2020 · 2 comments
Labels

Comments

@RobinBol
Copy link

RobinBol commented Mar 27, 2020

Hi, first thanks for this great library!

I have an issue converting an XYZ value to RGB and back, it seems that for some values this works, but for others not. I could not find any range for the XYZ values in the readme (as for the other values), maybe it is related to that?.

This conversion matches (after rounding):

const startXYZ = [47.854955042890886, 29.320696241557958, 21.87902240817543]
const _rgb = convert.xyz.rgb(startXYZ);
const endXYZ = convert.rgb.xyz(_rgb) // => [ 48, 29, 22 ]

However, the following conversion is a mismatch (and quite some other value):

const startXYZ = [ 20, 87, 79 ]
const _rgb = convert.xyz.rgb(startXYZ);
const endXYZ = convert.rgb.xyz(_rgb) // => [ 48, 76, 75 ]

I have been fiddling with the color-space library as well, but that seems to have the same result (colorjs/color-space#48). Is this a bug in the conversion algorithm?

@Qix-
Copy link
Owner

Qix- commented Mar 27, 2020

XYZ and RGB do not have direct conversations; I'm not well versed in XYZ theory but if I recall correctly, it's an approximation and won't give you stable results when converting between the two.

@Qix-
Copy link
Owner

Qix- commented Feb 28, 2021

Closing as this conversion is lossy in nature (not all color models can be converted cleanly between one another).

@Qix- Qix- closed this as completed Feb 28, 2021
@Qix- Qix- added the question label Feb 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants