module LCH

Overview

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}

Extended Modules

Defined in:

lch.cr

Instance Method Summary

Instance Method Detail

def lab2lch(l, a, b) #

Returns a CIELCh L, C, H tuple for the given CIELAB color.


[View source]
def lab2srgb(l, a, b) #

Returns an RGB tuple for the given CIELAB color.


[View source]
def lch2lab(l, c, h) #

Returns a CIELAB tuple for the given LCH color.


[View source]
def lch2rgb(l : Number, c : Number, h : Number) : Tuple(Int32, Int32, Int32) #

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}

[View source]
def lch2rgb(lch : Indexable) : Tuple(Int32, Int32, Int32) #

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

[View source]
def rgb2lab(r, g, b) #

Returns a CIELAB L, a, b tuple for the given RGB color.


[View source]
def rgb2lch(r : Int, g : Int, b : Int) : Tuple(Float64, Float64, Float64) #

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}

[View source]
def rgb2lch(rgb : Indexable) : Tuple(Float64, Float64, Float64) #

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

[View source]
def rgb2xyz(r, g, b) #

Returns a CIEXYZ X, Y, Z tuple for the given RGB color.


[View source]