Support rgba hex format

This commit is contained in:
Jipok 2021-12-20 14:36:56 +05:00
parent 2e9619f630
commit 941b283681
1 changed files with 5 additions and 5 deletions

View File

@ -47,22 +47,22 @@ end
function common.color(str)
local r, g, b, a = str:match("#(%x%x)(%x%x)(%x%x)")
local r, g, b, a = str:match("^#(%x%x)(%x%x)(%x%x)(%x?%x?)$")
if r then
r = tonumber(r, 16)
g = tonumber(g, 16)
b = tonumber(b, 16)
a = 1
a = tonumber(a, 16) or 0xff
elseif str:match("rgba?%s*%([%d%s%.,]+%)") then
local f = str:gmatch("[%d.]+")
r = (f() or 0)
g = (f() or 0)
b = (f() or 0)
a = f() or 1
a = (f() or 1) * 0xff
else
error(string.format("bad color string '%s'", str))
end
return r, g, b, a * 0xff
return r, g, b, a
end