Module:Color contrast: Difference between revisions

    m>Frietjes
    (add support for rgb(x,y,z))
    m>Frietjes
    (simplify, already lowercased)
    Line 76: Line 76:


       -- convert from hsl
       -- convert from hsl
       if mw.ustring.match(c,'^[Hh][Ss][Ll]%([%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*%%[%s]*,[%s]*[0-9][0-9]*%%[%s]*%)$') then
       if mw.ustring.match(c,'^hsl%([%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,'^[Hh][Ss][Ll]%([%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)%%[%s]*,[%s]*([0-9][0-9]*)%%[%s]*%)$')
    local h, s, l = mw.ustring.match(c,'^hsl%([%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)
    return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)
       end
       end


       -- convert from rgb
       -- 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
       if mw.ustring.match(c,'^rgb%([%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]*%)$')
    local R, G, B = mw.ustring.match(c,'^rgb%([%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))
    return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))
       end
       end