25.03.2024, 13:03
Code:
RGB = event.getvalue()
-- Norm of RGB values
R = bit.rshift(bit.band(RGB, 0xFF0000), 16)
G = bit.rshift(bit.band(RGB, 0x00FF00), 8)
B = bit.band(RGB, 0x0000FF)
Red = R / 255
Green = G / 255
Blue = B / 255
-- Gamma correction
if Red > 0.04045 then
Red = ((Red + 0.055) / (1 + 0.055))^2.4
else
Red = Red / 12.92
end
if Green > 0.04045 then
Green = ((Green + 0.055) / (1 + 0.055))^2.4
else
Green = Green / 12.92
end
if Blue > 0.04045 then
Blue = ((Blue + 0.055) / (1 + 0.055))^2.4
else
Blue = Red / 12.92
end
-- Coversion RGB > XY
X = Red * 0.649926 + Green * 0.103455 + Blue * 0.197109
Y = Red * 0.234327 + Green * 0.743075 + Blue * 0.022598
Z = Green * 0.053077 + Blue * 1.035763
x = X / (X+Y+Z)
y = Y / (X+Y+Z)
-- Coversion XY > CCT
n = (x - 0.3320) / (0.1858 - y)
cct = math.floor((-449 * ((x - 0.332) / (y - 0.1858))^3) + (3525 * ((x - 0.332) / (y - 0.1858))^2) - (6823.3 * ((x - 0.332) / (y - 0.1858))) + (5520.33))
log(cct)