Module:Color contrast: Difference between revisions

synced changes from sandbox - created an access point to lum available to other modules
m (1 revision imported)
imported>Gonnym
(synced changes from sandbox - created an access point to lum available to other modules)
Line 9:
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' )
 
local function sRGB ( v )
if (v <= 0.03928) then
v = v / 12.92
Line 18:
end
 
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)
Line 26:
end
 
local function hsl2lum( h, s, l )
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 58:
end
 
local-- This exports the function color2lum(for use in cother )modules.
-- The colour is passed as a string.
function p._lum(color)
return color2lum(color)
end
 
local function color2lum(c)
 
if (c == nil) then
Line 211 ⟶ 217:
end
 
--[[
Use {{#invoke:Color contrast|somecolor}} directly or
{{#invoke:Color contrast}} from a wrapper template.
 
Parameters:
-- |1= — required; A color to check.
--]]
function p.lum(frame)
returnlocal color = color2lum(frame.args[1] or frame:getParent().args[1])
return p._lum(color)
end
 
Anonymous user