Class: Caman.Convert

Defined in: src/core/convert.coffee

Overview

Tons of color conversion utility functions.

Class Method Summary

Class Method Details

+ (Array) hexToRGB(hex)

Converts the hex representation of a color to RGB values. Hex value can optionally start with the hash (#).

Parameters:

  • hex (String) The colors hex value

Returns:

  • (Array) — The RGB representation

+ (Array) rgbToHSL(r, g, b)
+ (Array) rgbToHSL(rgb)

Converts an RGB color to HSL. Assumes r, g, and b are in the set [0, 255] and returns h, s, and l in the set [0, 1].

Returns:

  • (Array) — The HSL representation

Overloads:

+ (Array) rgbToHSL(r, g, b)

Parameters:

  • r (Number) Red channel
  • g (Number) Green channel
  • b (Number) Blue channel

+ (Array) rgbToHSL(rgb)

Parameters:

  • rgb (Object) The RGB object.

Options Hash: (rgb):

  • r (Number) The red channel.
  • g (Number) The green channel.
  • b (Number) The blue channel.

+ (Array) hslToRGB(h, s, l)
+ (Array) hslToRGB(hsl)

Converts an HSL color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSL_color_space. Assumes h, s, and l are contained in the set [0, 1] and returns r, g, and b in the set [0, 255].

Returns:

  • (Array) — The RGB representation

Overloads:

+ (Array) hslToRGB(h, s, l)

Parameters:

  • h (Number) The hue
  • s (Number) The saturation
  • l (Number) The lightness

+ (Array) hslToRGB(hsl)

Parameters:

  • hsl (Object) The HSL object.

Options Hash: (hsl):

  • h (Number) The hue.
  • s (Number) The saturation.
  • l (Number) The lightness.

+ (Number) hueToRGB(p, q, t)

Converts from the hue color space back to RGB.

Parameters:

  • p (Number)
  • q (Number)
  • t (Number)

Returns:

  • (Number) — RGB value

+ (Array) rgbToHSV(r, g, b)

Converts an RGB color value to HSV. Conversion formula adapted from {http://en.wikipedia.org/wiki/HSV_color_space}. Assumes r, g, and b are contained in the set [0, 255] and returns h, s, and v in the set [0, 1].

Parameters:

  • r (Number) The red color value
  • g (Number) The green color value
  • b (Number) The blue color value

Returns:

  • (Array) — The HSV representation

+ (Array) hsvToRGB(h, s, v)

Converts an HSV color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes h, s, and v are contained in the set [0, 1] and returns r, g, and b in the set [0, 255].

Parameters:

  • h (Number) The hue
  • s (Number) The saturation
  • v (Number) The value

Returns:

  • (Array) — The RGB representation

+ (Array) rgbToXYZ(r, g, b)

Converts a RGB color value to the XYZ color space. Formulas are based on http://en.wikipedia.org/wiki/SRGB assuming that RGB values are sRGB.

Assumes r, g, and b are contained in the set [0, 255] and returns x, y, and z.

Parameters:

  • r (Number) The red color value
  • g (Number) The green color value
  • b (Number) The blue color value

Returns:

  • (Array) — The XYZ representation

+ (Array) xyzToRGB(x, y, z)

Converts a XYZ color value to the sRGB color space. Formulas are based on http://en.wikipedia.org/wiki/SRGB and the resulting RGB value will be in the sRGB color space. Assumes x, y and z values are whatever they are and returns r, g and b in the set [0, 255].

Parameters:

  • x (Number) The X value
  • y (Number) The Y value
  • z (Number) The Z value

Returns:

  • (Array) — The RGB representation

+ (Array) xyzToLab(x, y, z)
+ (Array) xyzToLab(xyz)

Converts a XYZ color value to the CIELAB color space. Formulas are based on http://en.wikipedia.org/wiki/Lab_color_space The reference white point used in the conversion is D65. Assumes x, y and z values are whatever they are and returns L, a and b* values

Returns:

  • (Array) — The Lab representation

Overloads:

+ (Array) xyzToLab(x, y, z)

Parameters:

  • x (Number) The X value
  • y (Number) The Y value
  • z (Number) The Z value

+ (Array) xyzToLab(xyz)

Parameters:

  • xyz (Object) The XYZ object.

Options Hash: (xyz):

  • x (Number) The X value.
  • y (Number) The Y value.
  • z (Number) The z value.

+ (Array) labToXYZ(l, a, b)
+ (Array) labToXYZ(lab)

Converts a L, a, b* color values from the CIELAB color space to the XYZ color space. Formulas are based on http://en.wikipedia.org/wiki/Lab_color_space

The reference white point used in the conversion is D65. Assumes L, a and b* values are whatever they are and returns x, y and z values.

Returns:

  • (Array) — The XYZ representation

Overloads:

+ (Array) labToXYZ(l, a, b)

Parameters:

  • l (Number) The L* value
  • a (Number) The a* value
  • b (Number) The b* value

+ (Array) labToXYZ(lab)

Parameters:

  • lab (Object) The LAB values

Options Hash: (lab):

  • l (Number) The L* value.
  • a (Number) The a* value.
  • b (Number) The b* value.

+ (void) rgbToLab(r, g, b)

Converts L, a, b* back to RGB values.

See also:

  • Convert.rgbToXYZ
  • Convert.xyzToLab

+ (void) labToRGB(l, a, b)