Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

RGB clamped to zero when converting from La*b* #87

Open
@pnorman

Description

@pnorman

Lab has a gamut that exceeds sRGB. A La*b* colour may require primary values which no only exceed 1.0, but also are under 1.0. The documentation states

RGB spaces tend to have a smaller gamut than some of the CIE color spaces. When converting to RGB, this can cause some of the coordinates to end up being out of the acceptable range (0.0-1.0 or 1-255, depending on whether your RGB color is upscaled).

In at least one case, the values reported are clamped, even though unclamed values are requested.

As an example,

>>> convert_color(LCHabColor(lch_l=45,lch_c=40,lch_h=230), sRGBColor)
sRGBColor(rgb_r=0.0,rgb_g=0.4690,rgb_b=0.6157)
>>> convert_color(sRGBColor(rgb_r=0.0,rgb_g=0.4690,rgb_b=0.6157), LCHabColor)
LCHabColor(lch_l=46.6732,lch_c=31.3686,lch_h=243.1561)

A bit of trial and error finds the right value for the sRGB r primary is -0.9

>>> convert_color(sRGBColor(rgb_r=-0.9,rgb_g=0.4690,rgb_b=0.6157), LCHabColor)
LCHabColor(lch_l=44.6461,lch_c=40.8891,lch_h=229.9607)

The number of significant figures has been reduced for readability in the text above.

It's also worth noting that clamping is different than a proper handling of out of gamut colours

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions