Jump to content

Module:Color contrast: Difference between revisions

refactor
m>Frietjes
No edit summary
m>Frietjes
(refactor)
Line 16: Line 16:
end
end
return v
return v
end
local function rgbdec2lum( R, G, B )
return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255)
end
end


Line 25: Line 29:
local m = l - c/2
local m = l - c/2


local R, G, B = m, m, m
local r, g, b = m, m, m
if( 0 <= h and h < 60 ) then
if( 0 <= h and h < 60 ) then
R = R + c
r = r + c
G = G + x
g = g + x
elseif( 60 <= h and h < 120 ) then
elseif( 60 <= h and h < 120 ) then
R = R + x
r = r + x
G = G + c
g = g + c
elseif( 120 <= h and h < 180 ) then
elseif( 120 <= h and h < 180 ) then
G = R + c
g = g + c
B = G + x
b = b + x
elseif( 180 <= h and h < 240 ) then
elseif( 180 <= h and h < 240 ) then
G = R + x
g = g + x
B = G + c
b = b + c
elseif( 240 <= h and h < 300 ) then
elseif( 240 <= h and h < 300 ) then
R = R + x
r = r + x
B = G + c
b = b + c
elseif( 300 <= h and h < 360 ) then
elseif( 300 <= h and h < 360 ) then
R = R + c
r = r + c
B = G + x
b = b + x
end
end
lum = 0.2126 * sRGB(R) + 0.7152 * sRGB(G) + 0.0722 * sRGB(B)
lum = rgbdec2lum(255*r, 255*g, 255*b)
end
end
return lum
return lum
Line 81: Line 85:
local cs = mw.text.split(c or '', '')
local cs = mw.text.split(c or '', '')
if( #cs == 6 ) then
if( #cs == 6 ) then
local R = sRGB( (16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2]))/255 )
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2])
local G = sRGB( (16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4]))/255 )
local G = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4])
local B = sRGB( (16*tonumber('0x' .. cs[5]) + tonumber('0x' .. cs[6]))/255 )
local B = 16*tonumber('0x' .. cs[5]) + tonumber('0x' .. cs[6])


L = 0.2126 * R + 0.7152 * G + 0.0722 * B
return rgbdec2lum(R, G, B)
return L
elseif ( #cs == 3 ) then
elseif ( #cs == 3 ) then
local R = sRGB( (16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[1]))/255 )
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[1])
local G = sRGB( (16*tonumber('0x' .. cs[2]) + tonumber('0x' .. cs[2]))/255 )
local G = 16*tonumber('0x' .. cs[2]) + tonumber('0x' .. cs[2])
local B = sRGB( (16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[3]))/255 )
local B = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[3])


L = 0.2126 * R + 0.7152 * G + 0.0722 * B
return rgbdec2lum(R, G, B)
return L
end
end


Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.