Skip to content

Commit 89a799c

Browse files
committed
materialise (and scan) the entire xterm color cube
This turns the palette from a sparse palette (with holes) back to a dense one. Scanning the entire palette is the first of a series of pessimisations in upcoming commits which will be trading performance for accuracy.
1 parent f4cf642 commit 89a799c

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

autoload/css_color.vim

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,13 @@ else
7575
" the 6 values used in the xterm color cube
7676
" 0 95 135 175 215 255
7777
let s:cubergb = [ 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF ]
78-
79-
" 0..255 mapped to 0..5 based on the color cube values
80-
let s:xvquant = repeat([0],48)
81-
\ + repeat([1],68)
82-
\ + repeat([2],40)
83-
\ + repeat([3],40)
84-
\ + repeat([4],40)
85-
\ + repeat([5],20)
86-
" tweak the mapping for the exact matches (0 and 1 already correct)
87-
let s:xvquant[s:cubergb[2]] = 2
88-
let s:xvquant[s:cubergb[3]] = 3
89-
let s:xvquant[s:cubergb[4]] = 4
90-
let s:xvquant[s:cubergb[5]] = 5
78+
for s:rrr in s:cubergb
79+
for s:ggg in s:cubergb
80+
for s:bbb in s:cubergb
81+
call add( s:xtermcolor, [ s:rrr, s:ggg, s:bbb, len(s:xtermcolor) ] )
82+
endfor
83+
endfor
84+
endfor
9185

9286
" grayscale ramp
9387
let s:xtermcolor += map(range(24),'repeat([10*v:val+8],3) + [v:val+232]')
@@ -101,13 +95,7 @@ else
10195
let g = s:hex[color[2:3]]
10296
let b = s:hex[color[4:5]]
10397

104-
let vr = s:xvquant[r]
105-
let vg = s:xvquant[g]
106-
let vb = s:xvquant[b]
107-
let cidx = vr * 36 + vg * 6 + vb + 16
108-
let ccol = [ s:cubergb[vr], s:cubergb[vg], s:cubergb[vb], cidx ]
109-
110-
for [tr,tg,tb,idx] in [ ccol ] + s:xtermcolor
98+
for [tr,tg,tb,idx] in s:xtermcolor
11199
let dr = tr - r
112100
let dg = tg - g
113101
let db = tb - b

0 commit comments

Comments
 (0)