Skip to main content

HSP

Hue, Saturation, Perceived Brightness

The formula used to generate HSP is similar to the one Photoshop uses when converting images to greyscale.

Hue value is between 0 and 360. Saturation, perceived brightness, and alpha are between 0 and 100 (as in, percent).

When passing PR and PB values, PR + PG + PB must = 1.

By default,

  • PR = 0.299
  • PG = 0.587
  • PB = 0.114

** This formula is not as accurate as most others, but does offer another way of adjusting brightness in an image.

New Color

Color.from('hsp',[h, s, p, a?],{
pb: number, // optional, default = 0.114
pr: number // optional, default = 0.299
})

Conversion to

.to('hsp',{
round: boolean, // optional, default = true
pb: number, // optional, default = 0.114
pr: number // optional, default = 0.299
})

Get methods

.getH(): number
.getS(): number
.getP(): number
.getA(): number // if alpha is not set, defaults to 100
.getPr(): number
.getPb(): number
.getPg(): number // 1 - Pr - Pb

JavaScript

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

const color1 = Color.from('hsp', [300, 100, 65]).to('rgb')
// rgb { r: 255, g: 0, b: 255, a: 255, bitDepth: 8, max: 255 }
const color3 = Color.from('rgb', [255, 0, 255]).to('hsp')
// hsp { h: 300, s: 100, p: 64, a: 100, pr: 0.299, pg: 0.587, pb: 0.114 }

TypeScript

import Color from 'chromaticity-color-utilities'

const c: Color.hsp = Color.from('hsp', [300, 100, 65])