Module:College color/sandbox: Difference between revisions

Content deleted Content added
Jackmcbarn (talk | contribs)
simplify sRGB
Jackmcbarn (talk | contribs)
add error checking to color2lum
Line 15:
end
end
local function color2lum( corigc )
local csc = mw.text.split(corigc:match('^%s*#?([A-Fa-f0-9]+)%s*$'), '')
if not c then
error('Invalid hex color ' .. origc, 2)
end
local cs = mw.text.split(c, '')
local R, G, B
if( #cs == 6 ) then
R = sRGB( tonumber(cs[1] .. cs[2], 16)/255 )
G = sRGB( tonumber(cs[3] .. cs[4], 16)/255 )
B = sRGB( tonumber(cs[5] .. cs[6], 16)/255 )
elseif ( #cs == 3 ) then
R = sRGB( tonumber(cs[1] .. cs[1], 16)/25515 )
G = sRGB( tonumber(cs[2] .. cs[2], 16)/25515 )
B = sRGB( tonumber(cs[3] .. cs[3], 16)/25515 )
else
error('InvalidWrong number of hex digits in color ' .. corigc, 2)
end
return 0.2126 * R + 0.7152 * G + 0.0722 * B