Skip to content

Instantly share code, notes, and snippets.

@Cynosphere
Cynosphere / ycbcr.lua
Created November 10, 2019 23:47
GLua/Lua RGB <--> YCbCr Color Space Conversions
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)