Class Index | File Index

Classes


Namespace jamColors


Version 4.5.

Defined in: jamColors.jsxinc.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Global object (used to simulate a namespace in JavaScript) containing a set of color-related functions for scripts written with the JSON Action Manager engine.
Method Summary
Method Attributes Method Name and Description
<static>  
jamColors.colorToRgb(color)
Get a RGB color array [ red, green, blue ] from a color string or a RGB color array.
<static>  
jamColors.defineNamedColorsSet(setName, setData)
Define a custom named colors set.
<static>  
jamColors.enumerateNamedColors(setName, excludeVariants)
Get an array of all color names belonging to a named colors set.
<static>  
jamColors.hclToRgb(hclColor, hclFloatRange, rgbFloatRange)
Convert a HCL color array [ hue, chroma, luminance ] to a RGB color array [ red, green, blue ].
<static>  
jamColors.hexToRgb(hexColorString)
Get a RGB color array [ red, green, blue ] from a RGB color string in HTML/CSS hexadecimal notation.
<static>  
jamColors.hsbToRgb(hsbColor, hsbFloatRange, rgbFloatRange)
Convert a HSB color array [ hue, saturation, brightness ] to a RGB color array [ red, green, blue ].
<static>  
jamColors.hslToRgb(hslColor, hslFloatRange, rgbFloatRange)
Convert a HSL color array [ hue, saturation, lightness ] to a RGB color array [ red, green, blue ].
<static>  
jamColors.labToRgb(labColor, labFloatRange, rgbFloatRange)
Convert a Lab color array [ luminance, a, b ] to a RGB color array [ red, green, blue ].
<static>  
jamColors.nameToColor(setName, colorName, strict)
Get a color in simplified array format [ class, components ] from a color name belonging to a named colors set.
<static>  
jamColors.rgbToHcl(rgbColor, rgbFloatRange, hclFloatRange)
Convert a RGB color array [ red, green, blue ] to a HCL color array [ hue, chroma, luminance ].
<static>  
jamColors.rgbToHex(rgbColor, noSign, lowercase)
Get a RGB color string in HTML/CSS hexadecimal notation from a RGB color array [ red, green, blue ].
<static>  
jamColors.rgbToHsb(rgbColor, rgbFloatRange, hsbFloatRange)
Convert a RGB color array [ red, green, blue ] to a HSB color array [ hue, saturation, brightness ].
<static>  
jamColors.rgbToHsl(rgbColor, rgbFloatRange, hslFloatRange)
Convert a RGB color array [ red, green, blue ] to a HSL color array [ hue, saturation, lightness ].
<static>  
jamColors.rgbToLab(rgbColor, rgbFloatRange, labFloatRange)
Convert a RGB color array [ red, green, blue ] to a Lab color array [ luminance, a, b ].
<static>  
jamColors.rgbToXyz(rgbColor, rgbFloatRange, xyzFloatRange)
Convert a RGB color array [ red, green, blue ] to a XYZ color array [ x, y, z ].
<static>  
jamColors.rgbToYcbcr(rgbColor, rgbFloatRange, ycbcrFloatRange)
Convert a RGB color array [ red, green, blue ] to a YCbCr color array [ y, cb, cr ].
<static>  
jamColors.xyzToRgb(xyzColor, xyzFloatRange, rgbFloatRange)
Convert a XYZ color array [ x, y, z ] to a RGB color array [ red, green, blue ].
<static>  
jamColors.ycbcrToRgb(ycbcrColor, ycbcrFloatRange, rgbFloatRange)
Convert a YCbCr color array [ y, cb, cr ] to a RGB color array [ red, green, blue ].
Namespace Detail
jamColors
Global object (used to simulate a namespace in JavaScript) containing a set of color-related functions for scripts written with the JSON Action Manager engine.
Author: Michel MARIANI.
Method Detail
<static> {Array} jamColors.colorToRgb(color)
Get a RGB color array [ red, green, blue ] from a color string or a RGB color array.
alert (jamJSON.stringify (jamColors.colorToRgb ("green")));         // -> [ 0, 128, 0 ]
alert (jamJSON.stringify (jamColors.colorToRgb ("svg:green")));     // -> [ 0, 128, 0 ]
alert (jamJSON.stringify (jamColors.colorToRgb ("svg/green")));     // -> [ 0, 128, 0 ]
alert (jamJSON.stringify (jamColors.colorToRgb ("x11/green")));     // -> [ 0, 255, 0 ]
alert (jamJSON.stringify (jamColors.colorToRgb ("#00FF00")));       // -> [ 0, 255, 0 ]
alert (jamJSON.stringify (jamColors.colorToRgb ([ 0, 255, 0 ])));   // -> [ 0, 255, 0 ]
Parameters:
{String|Array} color
Color string (HTML/CSS hexadecimal notation, or color name) or RGB color array
Returns:
{Array} rgbColor RGB color array [ red, green, blue ]

<static> jamColors.defineNamedColorsSet(setName, setData)
Define a custom named colors set.
var myNamedColors =
{
    "colorClass": "HSBColorClass",
    "colorNames":
    {
        "casper": [ 0, 0, 100 ],
        "felixthecat": [ 0, 0, 0 ],
        "hulk": [ 80, 80, 70 ],
        "redridinghood": [ 20, 95, 80 ],
        "smurf": [ 197, 80, 94 ],
        "papasmurf": "smurf",
        "smurfette": "smurf",
        "tweety": [ 60, 80, 100 ]
    },
    "fallbackColor": "felixthecat"
};
jamColors.defineNamedColorsSet ("myset", myNamedColors);
var names = jamColors.enumerateNamedColors ("My Set");
alert ("My named colors set:\r" + jamJSON.stringify (names.sort (), 4));
jamEngine.jsonPlay
(
    "set",
    {
        "target": { "<reference>": [ { "color": { "<property>": "backgroundColor" } } ] },
        "to": jamHelpers.nameToColorObject ("My Set", "Red Riding Hood")
    }
);
jamEngine.jsonPlay
(
    "set",
    {
        "target": { "<reference>": [ { "color": { "<property>": "foregroundColor" } } ] },
        "to": jamHelpers.nameToColorObject ("My Set", "Papa Smurf")
    }
);
Parameters:
{String} setName
Named colors set name (case-insensitive, whitespace ignored)
{Object} setData
Named colors set data

The named colors set data structure is defined as a two or three-element JSON object:
{ "colorClass": colorClass, "colorNames": colorNames } or
{ "colorClass": colorClass, "colorNames": colorNames, "fallbackColor": fallbackColor }.

colorClass: string (among "bookColor", "CMYKColorClass", "grayscale", "HSBColorClass", "labColor", "RGBColor")
colorNames: JSON object { } made of key/value pairs: colorName: variantName, or colorName: colorComponents
fallbackColor: string (optional; if defined, must be one existing key in the colorNames object)

colorName: string (strictly lowercase, no whitespace)
variantName: string (must be one existing key in the colorNames object, associated with a colorComponents value)
colorComponents: JSON array [ ] whose length and contents depend on colorClass:

colorClass colorComponents
"bookColor" [ book, name, bookID, bookKey ]
or
[ book, name ]
or
[ bookID, bookKey ]
"CMYKColorClass" [ cyan, magenta, yellowColor, black ]
"grayscale" [ gray ]
or
gray
"HSBColorClass" [ hue, saturation, brightness ]
"labColor" [ luminance, a, b ]
"RGBColor" [ red, green, blue ]

book : string
name : string
bookID : number
bookKey : string
cyan : number (0 to 100)
magenta : number (0 to 100)
yellowColor : number (0 to 100)
black : number (0 to 100)
gray : number (0 to 100)
hue : number (0 to 360)
saturation : number (0 to 100)
brightness : number (0 to 100)
luminance : number (0 to 100)
a : number (-128 to 127)
b : number (-128 to 127)
red : number (0 to 255)
green : number (0 to 255)
blue : number (0 to 255)

See:
jamColors.nameToColor
jamColors.enumerateNamedColors

<static> {Array} jamColors.enumerateNamedColors(setName, excludeVariants)
Get an array of all color names belonging to a named colors set.
var x11Names = jamColors.enumerateNamedColors ("X11", true);
$.writeln (jamJSON.stringify (x11Names, 4));
Parameters:
{String} setName
Named colors set name (case-insensitive, whitespace ignored):
{Boolean} excludeVariants Optional
Exclude color names spelling variants (i.e. gray/grey); false by default
Returns:
{Array} Array of all color names belonging to the named colors set
See:
jamColors.defineNamedColorsSet

<static> {Array} jamColors.hclToRgb(hclColor, hclFloatRange, rgbFloatRange)
Convert a HCL color array [ hue, chroma, luminance ] to a RGB color array [ red, green, blue ].
var hclColor = jamColors.rgbToHcl ([ 0, 0, 255 ], false, true);
alert (jamJSON.stringify (jamColors.hclToRgb (hclColor, true)));
Parameters:
{Array} hclColor
HCL color array [ hue, chroma, luminance ]
{Boolean} hclFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 360], [0, 128], [0, 100]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
Returns:
{Array} RGB color array [ red, green, blue ]
See:
jamColors.rgbToHcl

<static> {Array} jamColors.hexToRgb(hexColorString)
Get a RGB color array [ red, green, blue ] from a RGB color string in HTML/CSS hexadecimal notation.
var rgbColor = jamColors.hexToRgb ("ffdead");
alert (jamJSON.stringify (rgbColor));  // -> [ 255, 222, 173 ]
Parameters:
{String} hexColorString
RGB color string in HTML/CSS hexadecimal notation (3 or 6 digits, starting with an optional # sign)
Returns:
{Array} RGB color array [ red, green, blue ]
See:
jamColors.rgbToHex

<static> {Array} jamColors.hsbToRgb(hsbColor, hsbFloatRange, rgbFloatRange)
Convert a HSB color array [ hue, saturation, brightness ] to a RGB color array [ red, green, blue ].
alert (jamJSON.stringify (jamColors.hsbToRgb ([ 0, 100, 100 ])));    // -> [ 255, 0, 0 ]
Parameters:
{Array} hsbColor
HSB color array [ hue, saturation, brightness ]
{Boolean} hsbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 360], [0, 100], [0, 100]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
Returns:
{Array} RGB color array [ red, green, blue ]
See:
jamColors.rgbToHsb

<static> {Array} jamColors.hslToRgb(hslColor, hslFloatRange, rgbFloatRange)
Convert a HSL color array [ hue, saturation, lightness ] to a RGB color array [ red, green, blue ].
alert (jamJSON.stringify (jamColors.hslToRgb ([ 0, 100, 50 ])));    // -> [ 255, 0, 0 ]
Parameters:
{Array} hslColor
HSL color array [ hue, saturation, lightness ]
{Boolean} hslFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 360], [0, 100], [0, 100]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
Returns:
{Array} RGB color array [ red, green, blue ]
See:
jamColors.rgbToHsl

<static> {Array} jamColors.labToRgb(labColor, labFloatRange, rgbFloatRange)
Convert a Lab color array [ luminance, a, b ] to a RGB color array [ red, green, blue ].
var labColor = jamColors.rgbToLab ([ 0, 0, 255 ], false, true);
alert (jamJSON.stringify (jamColors.labToRgb (labColor, true)));
Parameters:
{Array} labColor
Lab color array [ luminance, a, b ]
{Boolean} labFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 100], [-128, 128], [-128, 128]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
Returns:
{Array} RGB color array [ red, green, blue ]
See:
jamColors.rgbToLab

<static> {Array} jamColors.nameToColor(setName, colorName, strict)
Get a color in simplified array format [ class, components ] from a color name belonging to a named colors set.
alert (jamJSON.stringify (jamColors.nameToColor ("W3C", "Fuchsia"))); // -> [ "RGBColor", [ 255, 0, 255 ] ]
alert (jamJSON.stringify (jamColors.nameToColor ("X11", "Navy Blue"))); // -> [ "RGBColor", [ 0, 0, 128 ] ]
Parameters:
{String} setName
Named colors set name (case-insensitive, whitespace ignored):
{String} colorName
Color name (case-insensitive, whitespace ignored)
{Boolean} strict
Strict mode
Returns:
{Array} Color in simplified array format [ class, components ]
See:
jamColors.defineNamedColorsSet

<static> {Array} jamColors.rgbToHcl(rgbColor, rgbFloatRange, hclFloatRange)
Convert a RGB color array [ red, green, blue ] to a HCL color array [ hue, chroma, luminance ].
var hclColor = jamColors.rgbToHcl ([ 215, 25, 28 ], false, true);
alert (jamJSON.stringify (jamColors.hclToRgb (hclColor, true)));
Parameters:
{Array} rgbColor
RGB color array [ red, green, blue ]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
{Boolean} hclFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 360], [0, 128], [0, 100]
Returns:
{Array} HCL color array [ hue, chroma, luminance ]
See:
jamColors.hclToRgb

<static> {String} jamColors.rgbToHex(rgbColor, noSign, lowercase)
Get a RGB color string in HTML/CSS hexadecimal notation from a RGB color array [ red, green, blue ].
var hexColorString = jamColors.rgbToHex ([ 255, 222, 173 ]);
alert (jamJSON.stringify (hexColorString));  // -> "#FFDEAD"
Parameters:
{Array} rgbColor
RGB color array [ red, green, blue ]
{Boolean} noSign Optional
Do not add a leading # sign (false by default)
{Boolean} lowercase Optional
Use lowercase hexadecimal digits (false by default)
Returns:
{String} RGB color string in HTML/CSS hexadecimal notation (6 digits, starting with a # sign)
See:
jamColors.hexToRgb

<static> {Array} jamColors.rgbToHsb(rgbColor, rgbFloatRange, hsbFloatRange)
Convert a RGB color array [ red, green, blue ] to a HSB color array [ hue, saturation, brightness ].
alert (jamJSON.stringify (jamColors.rgbToHsb ([ 255, 255, 0 ])));    // -> [ 60, 100, 100 ]
Parameters:
{Array} rgbColor
RGB color array [ red, green, blue ]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
{Boolean} hsbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 360], [0, 100], [0, 100]
Returns:
{Array} HSB color array [ hue, saturation, brightness ]
See:
jamColors.hsbToRgb

<static> {Array} jamColors.rgbToHsl(rgbColor, rgbFloatRange, hslFloatRange)
Convert a RGB color array [ red, green, blue ] to a HSL color array [ hue, saturation, lightness ].
alert (jamJSON.stringify (jamColors.rgbToHsl ([ 255, 255, 0 ])));    // -> [ 60, 100, 50 ]
Parameters:
{Array} rgbColor
RGB color array [ red, green, blue ]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
{Boolean} hslFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 360], [0, 100], [0, 100]
Returns:
{Array} HSL color array [ hue, saturation, lightness ]
See:
jamColors.hslToRgb

<static> {Array} jamColors.rgbToLab(rgbColor, rgbFloatRange, labFloatRange)
Convert a RGB color array [ red, green, blue ] to a Lab color array [ luminance, a, b ].
var labColor = jamColors.rgbToLab ([ 215, 25, 28 ], false, true);
alert (jamJSON.stringify (jamColors.labToRgb (labColor, true)));
Parameters:
{Array} rgbColor
RGB color array [ red, green, blue ]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
{Boolean} labFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 100], [-128, 128], [-128, 128]
Returns:
{Array} Lab color array [ luminance, a, b ]
See:
jamColors.labToRgb

<static> {Array} jamColors.rgbToXyz(rgbColor, rgbFloatRange, xyzFloatRange)
Convert a RGB color array [ red, green, blue ] to a XYZ color array [ x, y, z ].
alert (jamJSON.stringify (jamColors.rgbToXyz ([ 255, 0, 255 ])));
Parameters:
{Array} rgbColor
RGB color array [ red, green, blue ]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
{Boolean} xyzFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 100], [0, 100], [0, 100]
Returns:
{Array} XYZ color array [ x, y, z ]
See:
jamColors.xyzToRgb

<static> {Array} jamColors.rgbToYcbcr(rgbColor, rgbFloatRange, ycbcrFloatRange)
Convert a RGB color array [ red, green, blue ] to a YCbCr color array [ y, cb, cr ].
var ycbcrColor = jamColors.rgbToYcbcr ([ 128, 128, 128 ], false, true);
alert (jamJSON.stringify (jamColors.ycbcrToRgb (ycbcrColor, true))); // -> [ 128, 128, 128 ]
Parameters:
{Array} rgbColor
RGB color array [ red, green, blue ]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
{Boolean} ycbcrFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
Returns:
{Array} YCbCr color array [ y, cb, cr ]
See:
jamColors.ycbcrToRgb

<static> {Array} jamColors.xyzToRgb(xyzColor, xyzFloatRange, rgbFloatRange)
Convert a XYZ color array [ x, y, z ] to a RGB color array [ red, green, blue ].
alert (jamJSON.stringify (jamColors.xyzToRgb ([ 59, 28, 97 ])));
Parameters:
{Array} xyzColor
XYZ color array [ x, y, z ]
{Boolean} xyzFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 100], [0, 100], [0, 100]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
Returns:
{Array} RGB color array [ red, green, blue ]
See:
jamColors.rgbToXyz

<static> {Array} jamColors.ycbcrToRgb(ycbcrColor, ycbcrFloatRange, rgbFloatRange)
Convert a YCbCr color array [ y, cb, cr ] to a RGB color array [ red, green, blue ].
var ycbcrColor = jamColors.rgbToYcbcr ([ 128, 128, 128 ]);
alert (jamJSON.stringify (jamColors.ycbcrToRgb (ycbcrColor))); // -> [ 128, 128, 128 ]
Parameters:
{Array} ycbcrColor
YCbCr color array [ y, cb, cr ]
{Boolean} ycbcrFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
{Boolean} rgbFloatRange Optional
Use float range [0.0, 1.0] instead of [0, 255]
Returns:
{Array} RGB color array [ red, green, blue ]
See:
jamColors.rgbToYcbcr

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 12 2016 23:32:44 GMT+0200 (CEST)