Available since LÖVE 11.3 |
This function is not supported in earlier versions. |
Converts a color from 0..255 to 0..1 range.
r, g, b, a = love.math.colorFromBytes( rb, gb, bb, ab )
number rb
number gb
number bb
number ab (nil)
number r
number g
number b
number a (nil)
Here's implementation for 11.2 and earlier.
function love.math.colorFromBytes(r, g, b, a) if type(r) == "table" then r, g, b, a = r[1], r[2], r[3], r[4] end r = clamp01(floor(r + 0.5) / 255) g = clamp01(floor(g + 0.5) / 255) b = clamp01(floor(b + 0.5) / 255) a = a ~= nil and clamp01(floor(a + 0.5) / 255) or nil return r, g, b, a end
Where clamp01
is defined as follows
local function clamp01(x) return math.min(math.max(x, 0), 1) end