gtaylor / python-colormath

A python module that abstracts common color math operations. For example, converting from CIE L*a*b to XYZ, or from RGB to CMYK
python-colormath.readthedocs.org
BSD 3-Clause "New" or "Revised" License
456 stars 82 forks source link

Bug while converting from LAB to sRGBColor.get_rgb_hex() and AdobeRGBColor.get_rgb_hex() #72

Closed jnko closed 7 years ago

jnko commented 7 years ago

Trying to convert from two LAB colors to hex sRGB and AdobeRGB

to sRGB:

lab=LabColor(62.26, 87.83, 94.26)
>>> print(lab)
LabColor (lab_l:62.2600 lab_a:87.8300 lab_b:94.2600)
>>> sRGB = convert_color(lab, sRGBColor)
>>> print(sRGB)
sRGBColor (rgb_r:1.1435 rgb_g:0.0891 rgb_b:0.0000)
>>> sRGB.get_rgb_hex()
'#1241700'

But what is HEX "#1241700" ? The documentation tells : Converts the RGB value to a hex value in the form of: #RRGGBB

to AdobeRGB:

>>> AdobeRGB = convert_color(lab, AdobeRGBColor)
>>> print(AdobeRGB)
AdobeRGBColor (rgb_r:0.9879 rgb_g:0.1139 rgb_b:0.0000)
>>> AdobeRGB.get_rgb_hex()
'#fc1d00'

and "#fc1d00"

Interestingly with L:56.89 a:50.34 b:49.81 everything works as expected.

Is this a bug or am I doing anything wrong?

jnko commented 7 years ago

Uuups, sorry, my fault. Should have read the docs to the end.

I need to use the clampedrgb values instead of rgb_.

Just as the documentation describes. http://python-colormath.readthedocs.io/en/master/conversions.html#rgb-conversions-and-out-of-gamut-coordinates