<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.slipshine.net/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AColor_contrast</id>
		<title>Module:Color contrast - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.slipshine.net/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AColor_contrast"/>
		<link rel="alternate" type="text/html" href="http://wiki.slipshine.net/w/index.php?title=Module:Color_contrast&amp;action=history"/>
		<updated>2026-04-17T23:09:16Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://wiki.slipshine.net/w/index.php?title=Module:Color_contrast&amp;diff=212&amp;oldid=prev</id>
		<title>SuperHappy: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://wiki.slipshine.net/w/index.php?title=Module:Color_contrast&amp;diff=212&amp;oldid=prev"/>
				<updated>2016-01-30T14:01:08Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 14:01, 30 January 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>SuperHappy</name></author>	</entry>

	<entry>
		<id>http://wiki.slipshine.net/w/index.php?title=Module:Color_contrast&amp;diff=211&amp;oldid=prev</id>
		<title>Kephir: Sigh. I should read the code sometimes, however ugly it may be.</title>
		<link rel="alternate" type="text/html" href="http://wiki.slipshine.net/w/index.php?title=Module:Color_contrast&amp;diff=211&amp;oldid=prev"/>
				<updated>2015-09-06T12:08:24Z</updated>
		
		<summary type="html">&lt;p&gt;Sigh. I should read the code sometimes, however ugly it may be.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--&lt;br /&gt;
-- This module implements &lt;br /&gt;
--  {{Color contrast ratio}}&lt;br /&gt;
--  {{Greater color contrast ratio}}&lt;br /&gt;
--  {{ColorToLum}}&lt;br /&gt;
--  {{RGBColorToLum}}&lt;br /&gt;
--&lt;br /&gt;
local p = {}&lt;br /&gt;
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' )&lt;br /&gt;
&lt;br /&gt;
local function sRGB ( v ) &lt;br /&gt;
	if (v &amp;lt;= 0.03928) then &lt;br /&gt;
		v = v / 12.92&lt;br /&gt;
	else&lt;br /&gt;
		v = math.pow((v+0.055)/1.055, 2.4)&lt;br /&gt;
	end&lt;br /&gt;
	return v&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function rgbdec2lum( R, G, B )&lt;br /&gt;
	if ( 0 &amp;lt;= R and R &amp;lt; 256 and 0 &amp;lt;= G and G &amp;lt; 256 and 0 &amp;lt;= B and B &amp;lt; 256 ) then&lt;br /&gt;
		return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255)&lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function hsl2lum( h, s, l )&lt;br /&gt;
	if ( 0 &amp;lt;= h and h &amp;lt; 360 and 0 &amp;lt;= s and s &amp;lt;= 1 and 0 &amp;lt;= l and l &amp;lt;= 1 ) then&lt;br /&gt;
		local c = (1 - math.abs(2*l - 1))*s&lt;br /&gt;
		local x = c*(1 - math.abs( math.fmod(h/60, 2) - 1) )&lt;br /&gt;
		local m = l - c/2&lt;br /&gt;
&lt;br /&gt;
		local r, g, b = m, m, m&lt;br /&gt;
		if( 0 &amp;lt;= h and h &amp;lt; 60 ) then&lt;br /&gt;
			r = r + c&lt;br /&gt;
			g = g + x&lt;br /&gt;
		elseif( 60 &amp;lt;= h and h &amp;lt; 120 ) then&lt;br /&gt;
			r = r + x&lt;br /&gt;
			g = g + c&lt;br /&gt;
		elseif( 120 &amp;lt;= h and h &amp;lt; 180 ) then&lt;br /&gt;
			g = g + c&lt;br /&gt;
			b = b + x&lt;br /&gt;
		elseif( 180 &amp;lt;= h and h &amp;lt; 240 ) then&lt;br /&gt;
			g = g + x&lt;br /&gt;
			b = b + c&lt;br /&gt;
		elseif( 240 &amp;lt;= h and h &amp;lt; 300 ) then&lt;br /&gt;
			r = r + x&lt;br /&gt;
			b = b + c&lt;br /&gt;
		elseif( 300 &amp;lt;= h and h &amp;lt; 360 ) then&lt;br /&gt;
			r = r + c&lt;br /&gt;
			b = b + x&lt;br /&gt;
		end&lt;br /&gt;
		return rgbdec2lum(255*r, 255*g, 255*b)&lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function color2lum( c )&lt;br /&gt;
&lt;br /&gt;
	if (c == nil) then&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
	-- whitespace&lt;br /&gt;
	c = c:match( '^%s*(.-)[%s;]*$' )&lt;br /&gt;
&lt;br /&gt;
	-- lowercase&lt;br /&gt;
	c = c:lower()&lt;br /&gt;
&lt;br /&gt;
	-- first try to look it up&lt;br /&gt;
	local L = HTMLcolor[c]&lt;br /&gt;
	if (L ~= nil) then&lt;br /&gt;
		return L&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
   	-- convert from hsl&lt;br /&gt;
   	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&lt;br /&gt;
		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]*%)$')&lt;br /&gt;
		return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)&lt;br /&gt;
   	end&lt;br /&gt;
&lt;br /&gt;
   	-- convert from rgb&lt;br /&gt;
   	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&lt;br /&gt;
		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]*%)$')&lt;br /&gt;
		return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))&lt;br /&gt;
   	end&lt;br /&gt;
&lt;br /&gt;
   	-- convert from rgb percent&lt;br /&gt;
   	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&lt;br /&gt;
		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]*%)$')&lt;br /&gt;
		return rgbdec2lum(255*tonumber(R)/100, 255*tonumber(G)/100, 255*tonumber(B)/100)&lt;br /&gt;
   	end&lt;br /&gt;
&lt;br /&gt;
	-- remove leading # (if there is one) and whitespace&lt;br /&gt;
	c = mw.ustring.match(c, '^[%s#]*([a-f0-9]*)[%s]*$')&lt;br /&gt;
&lt;br /&gt;
	-- split into rgb&lt;br /&gt;
	local cs = mw.text.split(c or '', '')&lt;br /&gt;
	if( #cs == 6 ) then&lt;br /&gt;
		local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2])&lt;br /&gt;
		local G = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4])&lt;br /&gt;
		local B = 16*tonumber('0x' .. cs[5]) + tonumber('0x' .. cs[6])&lt;br /&gt;
&lt;br /&gt;
		return rgbdec2lum(R, G, B)&lt;br /&gt;
	elseif ( #cs == 3 ) then&lt;br /&gt;
		local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[1])&lt;br /&gt;
		local G = 16*tonumber('0x' .. cs[2]) + tonumber('0x' .. cs[2])&lt;br /&gt;
		local B = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[3])&lt;br /&gt;
&lt;br /&gt;
		return rgbdec2lum(R, G, B)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- failure, return blank&lt;br /&gt;
	return ''&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._greatercontrast(args)&lt;br /&gt;
	local bias = tonumber(args['bias'] or '0') or 0&lt;br /&gt;
	local v1 = color2lum(args[1] or '')&lt;br /&gt;
	local c2 = args[2] or '#FFFFFF'&lt;br /&gt;
	local v2 = color2lum(c2)&lt;br /&gt;
	local c3 = args[3] or '#000000'&lt;br /&gt;
	local v3 = color2lum(c3)&lt;br /&gt;
	local ratio1 = 0;&lt;br /&gt;
	local ratio2 = 0;&lt;br /&gt;
	if (type(v1) == 'number' and type(v2) == 'number') then&lt;br /&gt;
		ratio1 = (v2 + 0.05)/(v1 + 0.05)&lt;br /&gt;
		ratio1 = (ratio1 &amp;lt; 1) and 1/ratio1 or ratio1&lt;br /&gt;
	end&lt;br /&gt;
	if (type(v1) == 'number' and type(v3) == 'number') then&lt;br /&gt;
		ratio2 = (v3 + 0.05)/(v1 + 0.05)&lt;br /&gt;
		ratio2 = (ratio2 &amp;lt; 1) and 1/ratio2 or ratio2&lt;br /&gt;
	end&lt;br /&gt;
	return (ratio1 + bias &amp;gt; ratio2) and c2 or c3&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._ratio(args)&lt;br /&gt;
	local v1 = color2lum(args[1])&lt;br /&gt;
	local v2 = color2lum(args[2])&lt;br /&gt;
	if (type(v1) == 'number' and type(v2) == 'number') then&lt;br /&gt;
		-- v1 should be the brighter of the two.&lt;br /&gt;
		if v2 &amp;gt; v1 then&lt;br /&gt;
			v1, v2 = v2, v1&lt;br /&gt;
		end&lt;br /&gt;
		return (v1 + 0.05)/(v2 + 0.05)&lt;br /&gt;
	else&lt;br /&gt;
		return args['error'] or '?'&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._styleratio(args)&lt;br /&gt;
	local style = (args[1] or ''):lower()&lt;br /&gt;
	local bg, fg = 'white', 'black'&lt;br /&gt;
	local lum_bg, lum_fg = 1, 0&lt;br /&gt;
&lt;br /&gt;
	if args[2] then&lt;br /&gt;
		local lum = color2lum(args[2])&lt;br /&gt;
		if lum ~= '' then bg, lum_bg = args[2], lum end&lt;br /&gt;
	end&lt;br /&gt;
	if args[3] then&lt;br /&gt;
		local lum = color2lum(args[3])&lt;br /&gt;
		if lum ~= '' then fg, lum_fg = args[3], lum end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local slist = mw.text.split(style or '', ';')&lt;br /&gt;
	for k = 1,#slist do&lt;br /&gt;
		s = slist[k]&lt;br /&gt;
		local k,v = s:match( '^[%s]*([^:]-):([^:]-)[%s;]*$' )&lt;br /&gt;
		k = k or ''&lt;br /&gt;
		v = v or ''&lt;br /&gt;
		if (k:match('^[%s]*(background)[%s]*$') or k:match('^[%s]*(background%-color)[%s]*$')) then&lt;br /&gt;
			local lum = color2lum(v)&lt;br /&gt;
			if( lum ~= '' ) then bg, lum_bg = v, lum end&lt;br /&gt;
		elseif (k:match('^[%s]*(color)[%s]*$')) then&lt;br /&gt;
			local lum = color2lum(v)&lt;br /&gt;
			if( lum ~= '' ) then bg, lum_fg = v, lum end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if lum_bg &amp;gt; lum_fg then&lt;br /&gt;
		return (lum_bg + 0.05)/(lum_fg + 0.05)&lt;br /&gt;
	else&lt;br /&gt;
		return (lum_fg + 0.05)/(lum_bg + 0.05)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.lum(frame)&lt;br /&gt;
	return color2lum(frame.args[1] or frame:getParent().args[1])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.ratio(frame)&lt;br /&gt;
	local args = frame.args[1] and frame.args or frame:getParent().args&lt;br /&gt;
	return p._ratio(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.styleratio(frame)&lt;br /&gt;
	local args = frame.args[1] and frame.args or frame:getParent().args&lt;br /&gt;
	return p._styleratio(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.greatercontrast(frame)&lt;br /&gt;
	local args = frame.args[1] and frame.args or frame:getParent().args&lt;br /&gt;
	return p._greatercontrast(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Kephir</name></author>	</entry>

	</feed>