value colorRecode(color, transform, alpha)
Returns color transcoded according transform, optionally with alpha.
Used for converting between color models, decoding (unpack) a single color value into an array of color components, encoding (pack) an array of components into a single color value, or any combination thereof.
Conversion between every color model is currently not supported and may fail, e.g. RGB and CMYK since that can’t be done accurately without device dependent color profiles, etc..
Transform “stages”, names are case-insensitive:
cmyk
—
CMYK color model, where 4 components represent
Cyan [0,1], Magenta [0,1], Yellow [0,1] and Black [0,1].
Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.grayscale
—
Grayscale color model, where a single component represent
lightness [0,1].
Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.rgb
—
RGB color model, where 3 components represent
Red [0,1], Green [0,1] and Blue [0,1].
Used as first “stage” to specify or decode the initial color into components as/of this model, otherwise for converting to this model.
Can be followed by pack
or hex
for encoding into a single color value.hsv
—
HSV color model, where 3 components represent
Hue [0,1], Saturation [0,1] and (lightness) Value [0,1].
Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.ycbcr
—
YCbCr color space, where 3 components represent
luminance (Y) [0,1], blue-difference chroma (CB) [-0.5,+0.5] and red-difference chroma (CR) [-0.5,+0.5].
Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.ycck
—
YCCK color model, used to encode CMYK in YCbCr, where 4 components represent
luminance (Y) [0,1], blue-difference chroma (CB) [-0.5,+0.5], red-difference chroma (CR) [-0.5,+0.5] and Black [0,1]
Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.pack
—
Encode components into a single number.
Currently only allowed after a RGB color model,
for encoding it into a 32-bit ARGB color number.hex
—
Encode components into a single hexadecimal text.
Only allowed after a RGB color model,
for encoding it into a hexadecimal text, i.e. a hexEncode of its 32-bit ARGB color number.hex-argb8
—
Encode components into a single hexadecimal text in the format AARRGGBB.
Only allowed after a RGB color model,
for encoding its packed 32-bit ARGB color number into a zero-padded hexadecimal.hex-rgba8
—
Encode components into a single hexadecimal text in the format RRGGBBAA.
Only allowed after a RGB color model,
for encoding its components into a zero-padded hexadecimal, compatible with HTML/CSS by prepending an #.hex-rgb6
—
Encode components into a single hexadecimal text in the format RRGGBB.
Only allowed after a RGB color model,
for encoding its components into a zero-padded hexadecimal, compatible with HTML/CSS by prepending an #.colorRecode([0.299,-0.1688,0.5], "ycbcr rgb")
returns [1,0,0]
colorRecode(0xFFFF0000, "rgb")
returns [1,0,0]
colorRecode(0xFFFF0000, "rgb hsv")
returns [0,1,1]
colorRecode([0,1,1], "hsv rgb pack")
returns 0xFFFFFF00
colorRecode([1,0,0], "rgb hex-argb8", 0.5)
returns "80ff0000"
"#"++colorRecode([1,0,0], "rgb hex-rgb6")
returns "#ff0000"