LCH
Methods for LCH to RGB and RGB to LCH conversion.
Implementation mostly copied from chroma.js
D65 standard referent is used during conversion.
CIELCH to sRGB conversion may be lossy. sRGB to CIELCH shouldn't be lossy, but might still fall prey to precision errors.
LCH.rgb2lch(123, 40, 123) # {32.17, 55.27, 327.61}
LCH.lch2rgb(32.17, 55.27, 327.61) # {123, 40, 123}
Instance methods
Returns an R, G, B tuple for the given LCH (CIELCh) color.
The lightness component l is in percents, between 0 (representing black) and 100 (representing white).
The chroma component c (roughly representing the "amount of color") is a number greater than or equal to 0. Note that although chroma is theoretically unbounded, in practice it does not exceed 230.
The hue component h is in degrees.
The resulting R, G, B components are in the range [0; 255].
LCH.lch2rgb(l: 32.17, c: 55.27, h: 327.61) # {123, 40, 123}
Converts the first three items in lch to RGB.
Assumes the indexable to be Number-typed, and contain at
least three values -- for L, C, and H, correspondingly.
LCH.lch2rgb([32.17, 55.27, 327.61]) # {123, 40, 123}
LCH.lch2rgb({32.17, 55.27, 327.61}) # {123, 40, 123}
# ... etc
Returns an L, C, H tuple for the given RGB color.
r, g, and b are clamped between [0; 255].
The resulting lightness component L is in percents, between 0 (representing black) and 100 (representing white), rounded to two digits after the decimal place.
The resulting chroma component C (roughly representing the "amount of color") is a number greater than or equal to 0, rounded to two digits after the decimal place. Note that although chroma is theoretically unbounded, in practice it does not exceed 230.
The resulting hue component H is in degress, between 0 and 360, rounded to two digits after the decimal place.
LCH.rgb2lch(r: 123, g: 40, b: 123) # {32.17, 55.27, 327.61}
Converts the first three items in rgb to LCH.
Assumes the indexable to be Int-typed, and contain at
least three values -- for R, G, and B, correspondingly.
LCH.rgb2lch([123, 40, 123]) # {32.17, 55.27, 327.61}
LCH.rgb2lch({123, 40, 123}) # {32.17, 55.27, 327.61}
# ... etc