chroma.js
chroma.js copied to clipboard
rgb2hcg produces out of range values
I've been trying to implement this library in C# (because it's a lovely library) and while doing my unit tests I found that I wasn't able to round trip most RGB values to HCG and back to RGB.
At first I thought it was my translated code that was wrong so I went to test it in the JavaScript version using the interactive documentation but it appears that I'm getting the same weirdness even in JavaScript.
Below you'll find a screenshot where I was trying to confirm values.
I suppose it's also possible the fault lies in rgb2hcg but I don't know enough about HCG to tell but wanted to report the issue nonetheless.
At first I thought it was scaling each component of RGB up by 100 but that only holds true for two components non-zero. If all three components are non-zero the results get weird.
Ok, so more testing, it's definitely rgb2hcg that is the problem. I found that the values being produced in rgb2hcg look like they are meant to generate c from 0 to 100 instead of 0.0 to 1.0 (like shown in the tests) and when I scaled the RGB values to 0.0 to 1.0 instead of 0 to 255, and get rid of the 255 and 100 parts, it actually passes the tests.
I'll see if I can write a pull request for this.