1
0
mirror of https://github.com/gryf/wombat256grf.git synced 2025-12-17 19:40:19 +01:00

Update rgb_number function

This commit is contained in:
2021-01-19 18:58:35 +01:00
parent a034c74df0
commit 7a8aa2c501

View File

@@ -80,30 +80,27 @@ fun s:get_grey_color_idx(n)
endfun endfun
" returns an approximate color index for the given color level " returns an approximate color index for the given color level
fun <SID>rgb_number(x) fun s:get_approximate_rgb_idx(x)
if &t_Co == 88 if &t_Co == 88
if a:x < 69 let l:rgb_map = {69: 0, 172: 1, 230: 2}
return 0 for i in sort(keys(l:rgb_map), "s:sort_ints")
elseif a:x < 172 if a:x < i
return 1 return l:rgb_map[i]
elseif a:x < 230 endif
return 2 endfor
else
return 3 return 3
endif endif
else
if a:x < 75 if a:x < 75
return 0 return 0
else endif
let l:n = (a:x - 55) / 40 let l:n = (a:x - 55) / 40
let l:m = (a:x - 55) % 40 let l:m = (a:x - 55) % 40
if l:m < 20 if l:m < 20
return l:n return l:n
else endif
return l:n + 1 return l:n + 1
endif
endif
endif
endfun endfun
" returns the actual color level for the given color index " returns the actual color level for the given color index
@@ -144,9 +141,9 @@ fun <SID>color(r, g, b)
let l:gz = s:get_approximate_grey_idx(a:b) let l:gz = s:get_approximate_grey_idx(a:b)
" get the closest color " get the closest color
let l:x = <SID>rgb_number(a:r) let l:x = s:get_approximate_rgb_idx(a:r)
let l:y = <SID>rgb_number(a:g) let l:y = s:get_approximate_rgb_idx(a:g)
let l:z = <SID>rgb_number(a:b) let l:z = s:get_approximate_rgb_idx(a:b)
if l:gx == l:gy && l:gy == l:gz if l:gx == l:gy && l:gy == l:gz
" there are two possibilities " there are two possibilities
@@ -340,7 +337,7 @@ delf <SID>rgb
delf <SID>color delf <SID>color
delf <SID>rgb_color delf <SID>rgb_color
delf <SID>rgb_level delf <SID>rgb_level
delf <SID>rgb_number delf s:get_approximate_rgb_idx
delf s:get_grey_color_idx delf s:get_grey_color_idx
delf s:get_grey_level delf s:get_grey_level
delf s:get_approximate_grey_idx delf s:get_approximate_grey_idx