Default to using builtin rgb.txt maps

Provide a variable to override this behavior and use showrgb instead.
This sacrifices a tiny bit of accuracy in favor of a large speed boost.
This commit is contained in:
Matt Wozniski 2009-03-28 02:20:27 -04:00
parent b5ea2fa88d
commit 7171f7976c
2 changed files with 15 additions and 3 deletions

View File

@ -300,6 +300,14 @@ g:CSApprox_hook_{scheme}_post *csapprox-hooks*
colorscheme named "123 foo_bar-baz456.vim", the hook searched for colorscheme named "123 foo_bar-baz456.vim", the hook searched for
will be, eg, g:CSApprox_hook_foo_barbaz456_post will be, eg, g:CSApprox_hook_foo_barbaz456_post
g:CSApprox_use_showrgb *g:CSApprox_use_showrgb*
By default, CSApprox will use a built in mapping of color names to values.
This optimization greatly helps speed, but means that colors addressed by
name might not match up perfectly between gvim (which uses the system's
real rgb database) and CSApprox (which uses the builtin database). To
force CSApprox to try the systemwide database first, and only fall back on
the builtin database if it isn't available, set this variable non-zero.
g:CSApprox_approximator_function *g:CSApprox_approximator_function* g:CSApprox_approximator_function *g:CSApprox_approximator_function*
If the default approximation function doesn't work well enough, the user If the default approximation function doesn't work well enough, the user
(or another author wishing to extend this plugin) can write another (or another author wishing to extend this plugin) can write another

View File

@ -294,6 +294,10 @@ let s:rgb_defaults = { "lightred" : "#FFBBBB",
" color values (as '#rrggbb'). " color values (as '#rrggbb').
function! s:UpdateRgbHash() function! s:UpdateRgbHash()
try try
if !exists("g:CSApprox_use_showrgb") || !g:CSApprox_use_showrgb
throw "Not using showrgb"
endif
" We want to use the 'showrgb' program, if it's around " We want to use the 'showrgb' program, if it's around
let lines = split(system('showrgb'), '\n') let lines = split(system('showrgb'), '\n')
@ -496,9 +500,9 @@ function! s:SetCtermFromGui(hl)
let hl.cterm[which] = val let hl.cterm[which] = val
elseif val =~ '^#\=\x\{6}$' elseif val =~ '^#\=\x\{6}$'
let val = substitute(val, '^#', '', '') let val = substitute(val, '^#', '', '')
let r = str2nr(val[0] . val[1], 16) let r = str2nr(val[0:1], 16)
let g = str2nr(val[2] . val[3], 16) let g = str2nr(val[2:3], 16)
let b = str2nr(val[4] . val[5], 16) let b = str2nr(val[4:5], 16)
let hl.cterm[which] = g:CSApprox_approximator_function(r, g, b) let hl.cterm[which] = g:CSApprox_approximator_function(r, g, b)
exe 'hi ' . hl.name . ' cterm' . which . '=' . hl.cterm[which] exe 'hi ' . hl.name . ' cterm' . which . '=' . hl.cterm[which]
else else