Skip to content

Instantly share code, notes, and snippets.

@jda0
Last active April 28, 2018 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jda0/bd852aea1a18d384b726c0b9206995be to your computer and use it in GitHub Desktop.
Save jda0/bd852aea1a18d384b726c0b9206995be to your computer and use it in GitHub Desktop.
class Color {
constructor (r, g, b) {
this.r = r
this.g = g
this.b = b
}
toHex () {
return [this.r, this.g, this.b].reduce(
(a, b) => a + ('00' + b.toString(16)).slice(-2),
'#'
)
}
static fromUV (y, cb, cr) {
const y_ = y * 219
const cb_ = cb * 224 - 112
const cr_ = cr * 224 - 112
return new Color(
1.164 * y_ + 1.793 * cr_,
1.164 * y_ - 0.213 * cb_ - 0.533 * cr_,
1.164 * y_ + 2.112 * cb_
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment