Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Color

Color class that allows for specification and conversion of colors in various color spaces. Please not that most of the color conversion math is based on https://www.easyrgb.com/en/math.php. The internal color representation is a 4-tuple of GLclampf components in RGB color space and additional alpha. All color conversion, e.g., getters is computed on the fly, not cached, and is not optimized for, e.g., massive pixel processing.

Hierarchy

  • Color

Index

Constructors

constructor

  • Creates an instance of color (a 4-tuple in RGBA space).

    Parameters

    • Optional rgba: GLclampf3 | GLclampf4

      Either RGB tuple or RGBA tuple. If none is provided, default will be kept.

    • Optional alpha: number

      If RGB tuple is provided an additional alpha value can be specified.

    Returns Color

Properties

Protected _altered

_altered: boolean = false
see

altered

Protected _rgba

_rgba: GLclampf4 = ...

Static Protected Readonly DEFAULT_ALPHA

DEFAULT_ALPHA: number = 1.0

Static Protected Readonly HEX_FORMAT_REGEX

HEX_FORMAT_REGEX: RegExp = ...

Accessors

a

  • get a(): number
  • Read access to the Alpha component as float value in range [0.0, 1.0].

    Returns number

altered

  • get altered(): boolean
  • set altered(status: boolean): void
  • Whether or not color value has changed.

    Returns boolean

  • Intended for resetting alteration status.

    Parameters

    • status: boolean

    Returns void

b

  • get b(): number
  • Read access to the Blue component as float value in range [0.0, 1.0].

    Returns number

cmyk

  • Read access to the CMYK components as floating point 4-tuple, each value in range [0.0, 1.0].

    Returns GLclampf4

cmyka

  • Read access to the CMYKA components as floating point 5-tuple, each value in range [0.0, 1.0].

    Returns GLclampf5

g

  • get g(): number
  • Read access to the Green component as float value in range [0.0, 1.0].

    Returns number

hexRGB

  • get hexRGB(): string
  • Read access to the RGB components as hexadecimal string.

    Returns string

hexRGBA

  • get hexRGBA(): string
  • Read access to the RGBA components as hexadecimal string.

    Returns string

hsl

  • Read access to the HSL components as floating point 3-tuple, each value in range [0.0, 1.0].

    Returns GLclampf3

hsla

  • Read access to the HSLA components as floating point 4-tuple, each value in range [0.0, 1.0].

    Returns GLclampf4

lab

  • Read access to the LAB components as floating point 3-tuple, each value in range [0.0, 1.0].

    Returns GLclampf3

laba

  • Read access to the LABA components as floating point 4-tuple, each value in range [0.0, 1.0].

    Returns GLclampf4

r

  • get r(): number
  • Read access to the Red component as float value in range [0.0, 1.0].

    Returns number

rgb

  • Read access to the RGB components as floating point 3-tuple, each value in range [0.0, 1.0].

    Returns GLclampf3

rgbF32

  • get rgbF32(): Float32Array
  • Read access to the RGB components as array of three 32bit floats, each in range [0.0, 1.0].

    Returns Float32Array

rgbUI8

  • get rgbUI8(): Uint8Array
  • Read access to the RGB components as array of three bytes (8bit unsigned int), each in range [0, 255].

    Returns Uint8Array

rgba

  • Read access to the RGBA components as floating point 4-tuple, each value in range [0.0, 1.0].

    Returns GLclampf4

rgbaF32

  • get rgbaF32(): Float32Array
  • Read access to the RGBA components as array of four 32bit floats, each in range [0.0, 1.0].

    Returns Float32Array

rgbaUI8

  • get rgbaUI8(): Uint8Array
  • Read access to the RGBA components as array of four bytes (8bit unsigned int), each in range [0, 255].

    Returns Uint8Array

Methods

equals

  • equals(other: Color): boolean
  • Checks whether or not this color matches a second color (based on internal rgba floating representation).

    Parameters

    • other: Color

      Color to compare color values to.

    Returns boolean

    • True iff both colors have the exact same rgba floating point values.

fromCMYK

  • fromCMYK(cyan: number, magenta: number, yellow: number, key: number, alpha?: number): Color
  • Specifies the internal rgba store using a color in CMYK color space.

    Parameters

    • cyan: number

      Cyan color component in [0.0, 1.0]

    • magenta: number

      Magenta color component in [0.0, 1.0]

    • yellow: number

      Yellow color component in [0.0, 1.0]

    • key: number

      Key/Black color component in [0.0, 1.0]

    • alpha: number = ...

      Alpha color component in [0.0, 1.0]

    Returns Color

    • The color instance (this).

fromF32

  • fromF32(red: number, green: number, blue: number, alpha?: number): Color
  • Specifies the internal rgba store using a color in float (32bit) RGBA colors.

    Parameters

    • red: number

      Red color component in [0.0, 1.0]

    • green: number

      Green color component in [0.0, 1.0]

    • blue: number

      Blue color component in [0.0, 1.0]

    • alpha: number = ...

      Alpha color component in [0.0, 1.0]

    Returns Color

    • The color instance (this).

fromHSL

  • fromHSL(hue: number, saturation: number, lightness: number, alpha?: number): Color
  • Specifies the internal rgba store using a color in HSL color space.

    Parameters

    • hue: number

      Hue color component in [0.0, 1.0]

    • saturation: number

      Saturation color component in [0.0, 1.0]

    • lightness: number

      Lightness color component in [0.0, 1.0]

    • alpha: number = ...

      Alpha color component in [0.0, 1.0]

    Returns Color

    • The color instance (this).

fromHex

  • fromHex(hex: string): Color
  • Specifies the internal rgba store using a hexadecimal color string.

    Parameters

    • hex: string

      Hexadecimal color string: red, green, blue, and alpha (optional) each in ['00', 'ff'].

    Returns Color

    • The color instance (this).

fromLAB

  • fromLAB(lightness: number, greenRed: number, blueYellow: number, alpha?: number): Color
  • Specifies the internal rgba store using a color in CIE-Lab color space.

    Parameters

    • lightness: number

      Lightness color component in [0.0, 1.0]

    • greenRed: number

      Green-Red/a color component in [0.0, 1.0]

    • blueYellow: number

      Blue-Yellow/b color component in [0.0, 1.0]

    • alpha: number = ...

      Alpha color component in [0.0, 1.0]

    Returns Color

    • The color instance (this).

fromRGB

  • fromRGB(red: number, green: number, blue: number, alpha?: number): Color
  • Specifies the internal rgba store using a color in RGB color space.

    Parameters

    • red: number

      Red color component in [0.0, 1.0]

    • green: number

      Green color component in [0.0, 1.0]

    • blue: number

      Blue color component in [0.0, 1.0]

    • alpha: number = ...

      Alpha color component in [0.0, 1.0]

    Returns Color

    • The color instance (this).

fromUI8

  • fromUI8(red: number, green: number, blue: number, alpha?: number): Color
  • Specifies the internal rgba store using a color in unsigned int (8bit) RGBA colors.

    Parameters

    • red: number

      Red color component in [0, 255]

    • green: number

      Green color component in [0, 255]

    • blue: number

      Blue color component in [0, 255]

    • alpha: number = ...

      Alpha color component in [0, 255]

    Returns Color

    • The color instance (this).

gray

  • Converts the color to a gray value using the specified algorithm.

    Parameters

    Returns number

tuple

  • Enables generic color access within a specified color space.

    Parameters

    • space: Space

      Expected color space of the requested color values.

    • alpha: boolean = true

      Whether or not alpha channel should be provided as well.

    Returns GLclampf3 | GLclampf4 | GLclampf5

Static cmyk2rgb

  • Converts a color from CMYK space to RGB space.

    Parameters

    • cmyk: GLclampf4

      CMYK color tuple: cyan, magenta, yellow, and key, each in [0.0, 1.0].

    Returns GLclampf3

    • RGB color tuple: red, green, and blue, each in [0.0, 1.0]

Static hex2rgba

  • Converts a color from HEX string to RGBA space. The hex string can start with '#' or '0x' or neither of these.

    Parameters

    • hex: string

      Hexadecimal color string: red, green, and blue, each in ['00', 'ff'].

    Returns GLclampf4

    • RGBA color tuple: red, green, blue, and alpha, each in [0.0, 1.0]. On error [0, 0, 0, 0] is returned.

Static hsl2rgb

  • Converts a color from HSL space to RGB space.

    Parameters

    • hsl: GLclampf3

      HSL color tuple: hue, saturation, and lightness, each in [0.0, 1.0].

    Returns GLclampf3

    • RGB color tuple: red, green, and blue, each in [0.0, 1.0].

Static Protected hue2rgb

  • hue2rgb(p: number, q: number, t: number): number
  • Converts a hue value into an rgb value.

    Parameters

    • p: number
    • q: number
    • t: number

    Returns number

Static lab2rgb

  • Converts a color from LAB space to RGB space.

    Parameters

    • lab: GLclampf3

      LAB color tuple: lightness, greenRed, and blueYellow, each in [0.0, 1.0].

    Returns GLclampf3

    • RGB color tuple: red, green, and blue, each in [0.0, 1.0]

Static lab2xyz

  • Converts a color from LAB space to XYZ space (D65/2° illuminant)

    Parameters

    • lab: GLclampf3

      LAB color tuple: lightness, greenRed, and blueYellow, each in [0.0, 1.0].

    Returns GLclampf3

    • XYZ color tuple: x, y, and z, each in [0.0, 1.0].

Static lerp

  • Performs a linear interpolation between x and y using a to weight between them within the specified color space.

    Parameters

    • x: Color

      First color stop for lerp/linear interpolation.

    • y: Color

      Second color stop for lerp/linear interpolation.

    • a: number

      Specify the value to use to interpolate between x and y.

    • space: Space = ...

      The color space that is to be used for linear interpolation of two colors.

    Returns Color

Static rgb2cmyk

  • Converts a color from RGB space to CMYK space.

    Parameters

    • rgb: GLclampf3

      RGB color tuple: red, green, and blue, each in [0.0, 1.0]

    Returns GLclampf4

    • CMYK color tuple: cyan, magenta, yellow, and key, each in [0.0, 1.0].

Static rgb2hex

  • Converts a color from RGB space to HEX string.

    Parameters

    • rgb: GLclampf3

      RGB color tuple: red, green, and blue, each in [0.0, 1.0]

    Returns string

    • Hexadecimal color string: red, green, and blue, each in ['00', 'ff'], with '#' prefix

Static rgb2hsl

  • Converts a color from HSL space to RGB space.

    Parameters

    • rgb: GLclampf3

      RGB color tuple: red, green, and blue, each in [0.0, 1.0].

    Returns GLclampf3

    • HSL color tuple: hue, saturation, and lightness, each in [0.0, 1.0].

Static rgb2lab

Static rgb2xyz

  • Converts a color from Adobe-RGB space to XYZ space.

    Parameters

    • rgb: GLclampf3

      RGB color tuple: red, green, and blue, each in [0.0, 1.0]

    Returns GLclampf3

    • XYZ color tuple: x, y, and z, each in [0.0, 1.0].

Static rgba2hex

  • Converts a color from RGBA space to HEX string.

    Parameters

    • rgba: GLclampf4

      RGBA color tuple: red, green, blue, and alpha, each in [0.0, 1.0]

    Returns string

    • Hexadecimal color string: red, green, blue, and alpha, each in ['00', 'ff'], with '#' prefix

Static Protected to2CharHexCode

  • to2CharHexCode(value: number): string
  • Converts a float value to two-character HEX code.

    Parameters

    • value: number

      A float value in [0.0, 1.0].

    Returns string

    • Two-character hexadecimal representation in [00, FF].

Static xyz2lab

  • Converts a color from XYZ space to CIE-Lab space.

    Parameters

    • xyz: GLclampf3

      XYZ color tuple: x, y, and z, and refer to the D65/2° illuminant.

    Returns GLclampf3

    • LAB color tuple: lightness, greenRed, and blueYellow, each in [0.0, 1.0].

Static xyz2rgb

  • Converts a color from XYZ space to Adobe-RGB space.

    Parameters

    • xyz: GLclampf3

      XYZ color tuple: x, y, and z, and refer to the D65/2° illuminant.

    Returns GLclampf3

    • RGB color tuple: red, green, and blue, each in [0.0, 1.0]