Skip to main content

RGB

Red, Green, Blue

All values are between 0 and (2 ** bitDepth) - 1. With a default bit depth of 8, values are within 0-255. A color with a bit depth of 16 will have values ranging from 0-65535.

8-bit color is sometimes referred to as 24-bit or 32-bit (8 bits per channel, with 32-bit including an alpha channel). This package uses the more correct implementation of 32-bit meaning 32 bits per channel, and so generally most use cases would fall between 8 and 16 bit color depth.

rgb, RGB, rgba, and RGBA are synonymous.

New Color

Color.from('rgb',[r, g, b, a?],{
bitDepth: number // optional, default = 8
})
Color.from('rgba',[r, g, b, a?],{
bitDepth: number // optional, default = 8
})

Conversion to

.to('rgb',{
bitDepth: number, // optional, default = 8
round: boolean // optional, default = true
})

Get methods

.getR(): number
.getG(): number
.getB(): number
.getA(): number // if alpha is not set, defaults to max value -- (2 ** bitDepth) - 1
.getBitDepth(): number
.getMax(): number // maximum value of any single R/G/B/A value -- (2 ** bitDepth) - 1

JavaScript

const Color = require('chromaticity-color-utilities')

const color1 = Color.from('rgb', [255, 0, 255])
const color3 = color2.to('rgb')

const color4 = Color.from('rgb', [1023, 0, 1023], { bitDepth: 10 })

TypeScript

import Color from 'chromaticity-color-utilities'

const c: Color.rgb = Color.from('rgb', [255, 0, 255])