On Fr, 10 Jan 2014, Bram Moolenaar wrote:

> Christian Brabandt wrote:
> 
> > On Di, 07 Jan 2014, Matteo Cavalleri wrote:
> > 
> > > some easy steps to reproduce the problem:
> > > 
> > > :set t_Co?
> > > t_Co=256
> > > :set background?
> > > background=light
> > > :set background=dark
> > > :set background?
> > > background=dark
> > > :hi Normal ctermfg=grey ctermbg=234
> > > :set background?
> > > background=light
> > > :hi Normal ctermfg=grey ctermbg=0
> > > :set background?
> > > background=dark
> > 
> > > as you can see, the "hi" command changes background to light when
> > > ctermbg is set to 234, however, according to
> > > http://upload.wikimedia.org/wikipedia/commons/9/95/Xterm_color_chart.png
> > > color 234 is indeed a dark grey
> > 
> > I see the problem:
> > 
> > 7728           if (color >= 0)
> > 7729            {
> > 7730                if (termcap_active)
> > 7731                    term_bg_color(color);
> > 7732                if (t_colors < 16)
> > 7733                    i = (color == 0 || color == 4);
> > 7734                else
> > 7735                    i = (color < 7 || color == 8);
> > 7736                /* Set the 'background' option if the value is
> > 7737                 * wrong. */
> > 7738                if (i != (*p_bg == 'd'))
> > 7739                    set_option_value((char_u *)"bg", 0L,
> > 7740                            i ?  (char_u *)"dark"
> > 7741                              : (char_u *)"light", 0);
> > 7742            }
> > 
> > i.e. Vim always sets a light background for all colors except the first 
> > 7 and color 8 for which it will set a dark background. I don't think Vim 
> > should try to determine what color is used and depending on it's value 
> > try to set a sane 'bg' value for the other 256 colors (in a 256 color 
> > terminal or the 88 rxvt color cube) so for now, I would propose to 
> > adjust the logic only slightly to something like this:
> > 
> > diff --git a/src/syntax.c b/src/syntax.c
> > --- a/src/syntax.c
> > +++ b/src/syntax.c
> > @@ -7731,6 +7731,14 @@
> >                                 term_bg_color(color);
> >                             if (t_colors < 16)
> >                                 i = (color == 0 || color == 4);
> > +                           else if (t_colors == 256)
> > +                           {
> > +                               i = (color < 7 || color == 8 ||
> > +                                       (color > 231 && color < 244));
> > +                               if (i > 16 && i < 232)
> > +                                   i = (*p_bg == 'd');
> > +                           }
> > +
> > 
> > Which means only for the lower 12 (dark) gray colors (232 until 243) in 
> > the 256 color cube set the 'bg' to dark, for all other (except the ones 
> > mentioned above) leave the bg setting alone.
> 
> It's a start.  However, if we change this we might as well do it
> properly.
> 
> In my opinion we should take the color chart and compute the brightness
> of each color.  If it's above 50% 'background' should be set to light.
> 
> There at least is this image:
> http://upload.wikimedia.org/wikipedia/en/thumb/1/15/Xterm_256color_chart.svg/2000px-Xterm_256color_chart.svg.png
> 
> A list of #RGB values could be used to compute the brightness.

How about the attached patch? For colors > 15, it uses the rxvt color 
cube for 88 color terminals and the xterm color cube for 256 color 
terminals and computes the luminance. If the luminance is above a 
certain treshhold, it uses a light background, else it uses a dark 
background.

It uses the same logic, that I have been using for my Colorizer plugin 
(https://github.com/chrisbra/color_highlight) for which I haven't seen 
any complaints about the luminance yet (of course this doesn't mean this 
is correct by all means).

Best,
Christian
-- 

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff --git a/src/syntax.c b/src/syntax.c
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -7731,6 +7731,51 @@
 				term_bg_color(color);
 			    if (t_colors < 16)
 				i = (color == 0 || color == 4);
+			    else if (color >= 16 && t_colors == 88) /* rxvt color cube */
+			    {
+				int r = 0;
+				int g = 0;
+				int b = 0;
+				int colorcube[4] = {0x00, 0x8B, 0xCD, 0xFF};
+				int luminance;
+
+				if (color >= 16 && color < 80)
+				{
+				    color -= 16;
+				    r = colorcube[(color / 16) % 4];
+				    g = colorcube[(color / 4) % 4];
+				    b = colorcube[color % 4];
+				}
+				else if (color >= 80)
+				{
+				    color -= 80;
+				    r = g = b = 46.36 + (float)color * 23.18 + (color > 0 ? 23.18 : 0.0);
+				}
+				luminance = 30 * r + 59 * g + 11 * b;
+				i  = (luminance <= 12000);
+			    }
+			    else if (color >= 16 && t_colors == 256) /* xterm color cube */
+			    {
+				int r = 0;
+				int g = 0;
+				int b = 0;
+				int colorcube[6] = {0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF};
+				int luminance;
+
+				if (color >= 16 && color < 232)
+				{
+				    color -= 16;
+				    r = colorcube[(color / 36) % 6];
+				    g = colorcube[(color / 6) % 6];
+				    b = colorcube[color % 6];
+				}
+				else if (color >= 232)
+				    r = g = b = 8 + (color - 232) * 0x0a;
+
+				luminance = 30 * r + 59 * g + 11 * b;
+				i  = (luminance <= 12000);
+			    }
+
 			    else
 				i = (color < 7 || color == 8);
 			    /* Set the 'background' option if the value is

Raspunde prin e-mail lui