Module:Color contrast: Difference between revisions

refactor
No edit summary
(refactor)
Line 16:
end
return v
end
 
local function rgbdec2lum( R, G, B )
lum = return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255)
end
 
Line 25 ⟶ 29:
local m = l - c/2
 
local Rr, Gg, Bb = m, m, m
if( 0 <= h and h < 60 ) then
Rr = Rr + c
Gg = Gg + x
elseif( 60 <= h and h < 120 ) then
Rr = Rr + x
Gg = Gg + c
elseif( 120 <= h and h < 180 ) then
Gg = Rg + c
Bb = Gb + x
elseif( 180 <= h and h < 240 ) then
Gg = Rg + x
Bb = Gb + c
elseif( 240 <= h and h < 300 ) then
Rr = Rr + x
Bb = Gb + c
elseif( 300 <= h and h < 360 ) then
Rr = Rr + c
Bb = Gb + x
end
lum = rgbdec2lum(255*r, 255*g, 255*b)
lum = 0.2126 * sRGB(R) + 0.7152 * sRGB(G) + 0.0722 * sRGB(B)
end
return lum
Line 81 ⟶ 85:
local cs = mw.text.split(c or '', '')
if( #cs == 6 ) then
local R = sRGB( (16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2]))/255 )
local G = sRGB( (16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4]))/255 )
local B = sRGB( (16*tonumber('0x' .. cs[5]) + tonumber('0x' .. cs[6]))/255 )
 
return rgbdec2lum(R, G, B)
L = 0.2126 * R + 0.7152 * G + 0.0722 * B
return L
elseif ( #cs == 3 ) then
local R = sRGB( (16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[1]))/255 )
local G = sRGB( (16*tonumber('0x' .. cs[2]) + tonumber('0x' .. cs[2]))/255 )
local B = sRGB( (16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[3]))/255 )
 
return rgbdec2lum(R, G, B)
L = 0.2126 * R + 0.7152 * G + 0.0722 * B
return L
end
 
Anonymous user