Hsluv

hsluv.Hsluv (Class)

Human-friendly HSL conversion utility class.

The math for most of this module was taken from:

http://www.easyrgb.com http://www.brucelindbloom.com Wikipedia

All numbers below taken from math/bounds.wxm wxMaxima file. We use 17 digits of decimal precision to export the numbers, effectively exporting them as double precision IEEE 754 floats.

"If an IEEE 754 double precision is converted to a decimal string with at least 17 significant digits and then converted back to double, then the final number must match the original"

Source: https://en.wikipedia.org/wiki/Double-precision_floating-point_format

Static Members

getBounds(L: Float): Array<Line>

For a given lightness, return a list of 6 lines in slope-intercept form that represent the bounds in CIELUV, stepping over which will push a value out of the RGB gamut

Name Type
L Float
Returns
Array<Line>

maxSafeChromaForL(L: Float): Float

For given lightness, returns the maximum chroma. Keeping the chroma value below this number will ensure that for any hue, the color is within the RGB gamut.

Name Type
L Float
Returns
Float

maxChromaForLH(L: Float, H: Float): Float
Name Type
L Float
H Float
Returns
Float

xyzToRgb(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

XYZ coordinates are ranging in [0;1] and RGB coordinates in [0;1] range.

Name Type Default Description
tuple Array<Float> An array containing the color's X,Y and Z values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's red, green and blue.

rgbToXyz(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

RGB coordinates are ranging in [0;1] and XYZ coordinates in [0;1].

Name Type Default Description
tuple Array<Float> An array containing the color's R,G,B values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's XYZ coordinates.

yToL(Y: Float): Float
Name Type
Y Float
Returns
Float

lToY(L: Float): Float
Name Type
L Float
Returns
Float

xyzToLuv(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

XYZ coordinates are ranging in [0;1].

Name Type Default Description
tuple Array<Float> An array containing the color's X,Y,Z values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's LUV coordinates.

luvToXyz(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

XYZ coordinates are ranging in [0;1].

Name Type Default Description
tuple Array<Float> An array containing the color's L,U,V values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's XYZ coordinates.

luvToLch(tuple: Array<Float>, ?result: Array<Float>): Array<Float>
Name Type Default Description
tuple Array<Float> An array containing the color's L,U,V values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's LCH coordinates.

lchToLuv(tuple: Array<Float>, ?result: Array<Float>): Array<Float>
Name Type Default Description
tuple Array<Float> An array containing the color's L,C,H values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's LUV coordinates.

hsluvToLch(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100].

Name Type Default Description
tuple Array<Float> An array containing the color's H,S,L values in HSLuv color space.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's LCH coordinates.

lchToHsluv(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100].

Name Type Default Description
tuple Array<Float> An array containing the color's LCH values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's HSL coordinates in HSLuv color space.

hpluvToLch(tuple: Array<Float>): Array<Float>

HSLuv values are in [0;360], [0;100] and [0;100].

Name Type Description
tuple Array<Float> An array containing the color's H,S,L values in HPLuv (pastel variant) color space.
Returns Description
Array<Float> An array containing the resulting color's LCH coordinates.

lchToHpluv(tuple: Array<Float>): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100].

Name Type Description
tuple Array<Float> An array containing the color's LCH values.
Returns Description
Array<Float> An array containing the resulting color's HSL coordinates in HPLuv (pastel variant) color space.

rgbToHex(tuple: Array<Float>): String

RGB values are ranging in [0;1].

Name Type Description
tuple Array<Float> An array containing the color's RGB values.
Returns Description
String A string containing a #RRGGBB representation of given color.

hexToRgb(hex: String): Array<Float>

RGB values are ranging in [0;1].

Name Type Description
hex String A #RRGGBB representation of a color.
Returns Description
Array<Float> An array containing the color's RGB values.

lchToRgb(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

RGB values are ranging in [0;1].

Name Type Default Description
tuple Array<Float> An array containing the color's LCH values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's RGB coordinates.

rgbToLch(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

RGB values are ranging in [0;1].

Name Type Default Description
tuple Array<Float> An array containing the color's RGB values.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's LCH coordinates.

hsluvToRgb(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100] and RGB in [0;1].

Name Type Default Description
tuple Array<Float> An array containing the color's HSL values in HSLuv color space.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's RGB coordinates.

rgbToHsluv(tuple: Array<Float>, ?result: Array<Float>): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100] and RGB in [0;1].

Name Type Default Description
tuple Array<Float> An array containing the color's RGB coordinates.
result Array<Float> (optional) A pre-allocated array to store the result into.
Returns Description
Array<Float> An array containing the resulting color's HSL coordinates in HSLuv color space.

hpluvToRgb(tuple: Array<Float>): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100] and RGB in [0;1].

Name Type Description
tuple Array<Float> An array containing the color's HSL values in HPLuv (pastel variant) color space.
Returns Description
Array<Float> An array containing the resulting color's RGB coordinates.

rgbToHpluv(tuple: Array<Float>): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100] and RGB in [0;1].

Name Type Description
tuple Array<Float> An array containing the color's RGB coordinates.
Returns Description
Array<Float> An array containing the resulting color's HSL coordinates in HPLuv (pastel variant) color space.

hsluvToHex(tuple: Array<Float>): String

HSLuv values are ranging in [0;360], [0;100] and [0;100] and RGB in [0;1].

Name Type Description
tuple Array<Float> An array containing the color's HSL values in HSLuv color space.
Returns Description
String A string containing a #RRGGBB representation of given color.

hpluvToHex(tuple: Array<Float>): String
Name Type
tuple Array<Float>
Returns
String

hexToHsluv(s: String): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100] and RGB in [0;1].

Name Type
s String
Returns Description
Array<Float> An array containing the color's HSL values in HSLuv color space.

hexToHpluv(s: String): Array<Float>

HSLuv values are ranging in [0;360], [0;100] and [0;100] and RGB in [0;1].

Name Type
s String
Returns Description
Array<Float> An array containing the color's HSL values in HPLuv (pastel variant) color space.

Private Members



refY: Float

refU: Float

refV: Float

kappa: Float

epsilon: Float

hexChars: String

dotProduct(a: Array<Float>, b: Array<Float>): Float
Name Type
a Array<Float>
b Array<Float>
Returns
Float

fromLinear(c: Float): Float
Name Type
c Float
Returns
Float

toLinear(c: Float): Float
Name Type
c Float
Returns
Float