Last active
April 28, 2018 15:10
-
-
Save jda0/bd852aea1a18d384b726c0b9206995be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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