Created
November 10, 2019 23:47
-
-
Save Cynosphere/1f25b0307d50a9360d216a09c3f2d7c5 to your computer and use it in GitHub Desktop.
GLua/Lua RGB <--> YCbCr Color Space Conversions
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
local function RGBToYCbCr(r, g, b) | |
local Y = 0.299 * r + 0.587 * g + 0.114 * b | |
local Cb = -0.169 * r - 0.331 * g + 0.500 * b + 128 | |
local Cr = 0.500 * r - 0.419 * g - 0.081 * b + 128 | |
return Y, Cb, Cr | |
end | |
local function YCbCrToRGB(Y, Cb, Cr) | |
local r = 1 * Y + 0 * (Cb - 128) + 1.4 * (Cr - 128) | |
local g = 1 * Y - 0.343 * (Cb - 128) - 0.711 * (Cr - 128) | |
local b = 1 * Y + 1.765 * (Cb - 128) + 0 * (Cr - 128) | |
return r, g, b | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case:
Demo