garex / nodejs-color-model

Operate colors in popular color models: RGB, HSL, Lab and others. Convert from each other.
0 stars 0 forks source link

Running into LAB limits #13

Closed meyer closed 9 years ago

meyer commented 10 years ago

I’m running into an issue using color-difference.

cd.compare("00FF7F", "BADA55") seems to cause issues. Apparently #00FF7F’s value for a is not between -52 and 100—it’s -76.9009. I’d propose a fix if I knew more about colour math. Seems like this is the source of the issue. Can a go below -52?

garex commented 10 years ago

Can you show correct limits for this model? At http://en.wikipedia.org/wiki/Lab_color_space or another places.

I dont' remember where I found those -52.

Fix should be applied here https://github.com/garex/nodejs-color-model/blob/master/lib/lab.js#L18

Also if you will add test for this case — it will be good.

meyer commented 10 years ago

According to colourphil.co.uk there is no theoretical min/max for a and b but -128 to +127 seems to be a standard range. I’m still digging though.

lab_colourspace_2

garex commented 10 years ago

@meyer What if we then set those min/max to real min/max that we will get by translating from other color models?

garex commented 10 years ago

Another options is to remove min/max if it can be any and just throw exceptions when translating to another models, thta can't receive translated values.

According to http://en.wikipedia.org/wiki/Lab_color_space LAB include sRGB.

garex commented 10 years ago

3rd option will be to try to find nearest value of target color model. What do you think?

meyer commented 10 years ago

Hmm. Well LAB allows for colours that can’t be represented with either RGB or CMYK. Throwing an error seems to be a reasonable solution. It’s definitely an edge case. It’d be nice if there was a config option that allowed colour approximation on error.

I might be wrong, but I think the a and b range of -128 to +127 is directly related to the limitations of RGB, so locking those down might not be a terrible idea.

meyer commented 10 years ago

Colormine’s CMYK-to-LAB and RGB-to-LAB converters lock a and b down to a range of -128 to +128. I think 127 is more correct, though.

garex commented 10 years ago

Ok, let's then lock it in -127 +127. Can you create pull request with some test? Let's test 1st create Lab and convert to RGB. Another case should create LaB that will throw error during conversion.

Regarding config option. I dont' see it anywhere in current implementation — we dont' have here any CI or similar stuff.

garex commented 10 years ago

In our case range inclusive:

https://github.com/garex/nodejs-color-model/blob/master/lib/component.js#L36

garex commented 10 years ago

Stop, I dont' understand.. What range do we need?

[-127, +128] ? So -127 and +128 will be min/max allowed?

meyer commented 10 years ago

-128 to +127, and that range is inclusive. I’ll start the PR now and finish tomorrow.