Module:Color contrast: Difference between revisions

add support for rgb(x,y,z)
(combine)
(add support for rgb(x,y,z))
Line 19:
 
local function rgbdec2lum( R, G, B )
if ( 0 <= R and R < 256 and 0 <= G and G < 256 and 0 <= B and B < 256 ) then
return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255)
else
return lum''
end
end
 
local function hsl2lum( h, s, l )
local lum = ''
if ( 0 <= h and h < 360 and 0 <= s and s <= 1 and 0 <= l and l <= 1 ) then
local c = (1 - math.abs(2*l - 1))*s
Line 49 ⟶ 52:
b = b + x
end
lum =return rgbdec2lum(255*r, 255*g, 255*b)
else
return ''
end
return lum
end
 
Line 72 ⟶ 76:
 
-- convert from hsl
if mw.ustring.match(c,'^hsl[Hh][Ss][Ll]%([%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*%%[%s]*,[%s]*[0-9][0-9]*%%[%s]*%)$') then
local h, s, l = mw.ustring.match(c,'^hsl[Hh][Ss][Ll]%([%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)%%[%s]*,[%s]*([0-9][0-9]*)%%[%s]*%)$')
return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)
end
 
-- convert from rgb
if mw.ustring.match(c,'^[Rr][Gg][Bb]%([%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*[%s]*%)$') then
local R, G, B = mw.ustring.match(c,'^[Rr][Gg][Bb]%([%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*%)$')
return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))
end
 
Anonymous user