Module:Color contrast: Difference between revisions
synced changes from sandbox - created an access point to lum available to other modules
imported>Ahmsaqib m (1 revision imported) |
(synced changes from sandbox - created an access point to lum available to other modules) |
||
Line 9: | Line 9: | ||
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' ) | local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' ) | ||
local function sRGB ( v ) | local function sRGB (v) | ||
if (v <= 0.03928) then | if (v <= 0.03928) then | ||
v = v / 12.92 | v = v / 12.92 | ||
Line 18: | Line 18: | ||
end | end | ||
local function rgbdec2lum( R, G, B ) | 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 | 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) | return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255) | ||
Line 26: | Line 26: | ||
end | end | ||
local function hsl2lum( h, s, l ) | 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 | 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 | local c = (1 - math.abs(2*l - 1))*s | ||
Line 58: | Line 58: | ||
end | end | ||
local function color2lum( c ) | -- This exports the function for use in other modules. | ||
-- The colour is passed as a string. | |||
function p._lum(color) | |||
return color2lum(color) | |||
end | |||
local function color2lum(c) | |||
if (c == nil) then | if (c == nil) then | ||
Line 211: | Line 217: | ||
end | 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) | function p.lum(frame) | ||
local color = frame.args[1] or frame:getParent().args[1] | |||
return p._lum(color) | |||
end | end | ||