Quantcast

Color.plist rgb values are wrong (fix attached)

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Color.plist rgb values are wrong (fix attached)

Zvezdan Petkovic
I am a long time Vim user, but I downloaded MacVim for the first time  
this last weekend.  One of the first things I noticed is that my color  
scheme in a syntax highlighted file did not look right.

The information in :h macvim says this about Colors.plist

"Apart from the system colors, it is also possible to use standard X11  
color names (see http://en.wikipedia.org/wiki/X11_color_names) which  
usually come in a file called "rgb.txt".  MacVim does not have such a  
file, instead it keeps these colors in a dictionary called  
"Colors.plist".  The key in this dictionary is the name of the color  
and the value is an RGB value of the form #rrggbb stored as an integer."

First, those colors are easily accessible on every Mac with X11  
installed.  Simply run "showrgb" program (/usr/X11/bin/showrgb).
The numbers seem to correspond to the Wikipedia article.

However, it turns out those integers in Colors.plist are not right.
Take, for example, the value for MediumAquamarine: 6737066.

Now take a look at the Wikipedia page.
The RGB numbers are 102 205 170, or #66CDAA
The showrgb program gives the same decimal numbers for this color.

Let's open a terminal and check the hex number in bc.

        $ bc
        ...
        obase=16
        102
        66

        205
        CD

        170
        AA
        ^D

So Wikipedia hex value is correct.
Let's now use bc to convert this hex value to an integer.

        $ bc
        ...
        ibase=16
        66CDAA
        6737322
        ^D

Ouch. 6737322 != 6737066 (value from Colors.plist)

Similarly for practically all other colors!

I don't know how these numbers have been obtained, but they are simply  
wrong.  Even a simple color, such as Blue, is wrong -- 212.
It is clear from that Wikipedia page that Blue is #FF (0 0 255).
I mean, it's the B in RGB.  :-)

Now, being someone who prefers programming to typing huge amount of  
numbers I have written the attached program to generate the *correct*  
Colors.plist using the output of "showrgb" X11 utility.

I hope it gets used in the next MacVim snapshot.

Attached is also the correct Colors.plist generated by that program.
You can run the program on your Mac and compare that it produces the  
same plist.

Best regards,

        Zvezdan

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


#!/usr/bin/env python
#
# Copyright (c) 2009 Zvezdan Petkovic <[hidden email]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Convert output of X11 showrgb program to Colors.plist for MacVim.

The showrgb output format is:

    144 238 144 light green
    144 238 144 LightGreen

The Colors.plist format is:

    <key>lightgreen</key>
    <integer>9498256</integer>

The color names are converted into a single lowecase word.
The duplicates, such as light green and LightGreen, are eliminated,
resulting in only one entry.
The three numbers for RGB are converted into a proper 24-bit integer.

Usage: rgb2plist.py >Colors.plist

"""

import sys

header = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- generated from /usr/X11/bin/showrgb output by rgb2plist.py -->
<dict>"""

closing = """</dict>
</plist>"""

showrgb = '/usr/X11/bin/showrgb'

def main():
    if sys.version_info[:2] >= (2, 4):
        import subprocess
        pipe = subprocess.Popen(showrgb, stdout=subprocess.PIPE).stdout
    else:
        import os
        pipe = os.popen(showrgb)

    colors = {}
    for line in pipe:
        parts = line.split()
        color = ''.join(parts[3:]).lower()
        red, green, blue = [int(i) for i in parts[0:3]]
        rgb = red << 16 | green << 8 | blue
        colors[color] = rgb
    pipe.close()

    print header

    for color in sorted(colors):
        print "\t<key>" + color + "</key>"
        print "\t<integer>" + str(colors[color]) + "</integer>"

    print closing

if  __name__ == '__main__':
    main()

Colors.plist (43K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Color.plist rgb values are wrong (fix attached)

Björn Winckler

2009/2/25 Zvezdan Petkovic:

> I am a long time Vim user, but I downloaded MacVim for the first time
> this last weekend.  One of the first things I noticed is that my color
> scheme in a syntax highlighted file did not look right.
>
> The information in :h macvim says this about Colors.plist
>
> "Apart from the system colors, it is also possible to use standard X11
> color names (see http://en.wikipedia.org/wiki/X11_color_names) which
> usually come in a file called "rgb.txt".  MacVim does not have such a
> file, instead it keeps these colors in a dictionary called
> "Colors.plist".  The key in this dictionary is the name of the color
> and the value is an RGB value of the form #rrggbb stored as an integer."
>
> First, those colors are easily accessible on every Mac with X11
> installed.  Simply run "showrgb" program (/usr/X11/bin/showrgb).
> The numbers seem to correspond to the Wikipedia article.
>
> However, it turns out those integers in Colors.plist are not right.
> Take, for example, the value for MediumAquamarine: 6737066.
>
> Now take a look at the Wikipedia page.
> The RGB numbers are 102 205 170, or #66CDAA
> The showrgb program gives the same decimal numbers for this color.
>
> Let's open a terminal and check the hex number in bc.
>
>        $ bc
>        ...
>        obase=16
>        102
>        66
>
>        205
>        CD
>
>        170
>        AA
>        ^D
>
> So Wikipedia hex value is correct.
> Let's now use bc to convert this hex value to an integer.
>
>        $ bc
>        ...
>        ibase=16
>        66CDAA
>        6737322
>        ^D
>
> Ouch. 6737322 != 6737066 (value from Colors.plist)
>
> Similarly for practically all other colors!
>
> I don't know how these numbers have been obtained, but they are simply
> wrong.  Even a simple color, such as Blue, is wrong -- 212.
> It is clear from that Wikipedia page that Blue is #FF (0 0 255).
> I mean, it's the B in RGB.  :-)
>
> Now, being someone who prefers programming to typing huge amount of
> numbers I have written the attached program to generate the *correct*
> Colors.plist using the output of "showrgb" X11 utility.
>
> I hope it gets used in the next MacVim snapshot.
>
> Attached is also the correct Colors.plist generated by that program.
> You can run the program on your Mac and compare that it produces the
> same plist.

Hi Zvezdan,

You are right that the current Colors.plist looks strange.  I don't
actually remember how I generated that file but I think I wrote an
Obj-C program which opened rgb.txt (which I must have downloaded from
somewhere) and used NSColor to convert to rgb.  Sounds rather silly
now that I think about it but that's how I am.

I will push your Colors.plist to the public repo so it will be in snapshot 44.

Thanks!
Björn

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Color.plist rgb values are wrong (fix attached)

Björn Winckler

2009/2/25 björn:
> You are right that the current Colors.plist looks strange.  I don't
> actually remember how I generated that file but I think I wrote an
> Obj-C program which opened rgb.txt (which I must have downloaded from
> somewhere) and used NSColor to convert to rgb.  Sounds rather silly
> now that I think about it but that's how I am.
>
> I will push your Colors.plist to the public repo so it will be in snapshot 44.

It seems three colors that are in Vim are not included in the output
of "showrgb", namely:

darkyellow
lightmagenta
lightred

I have added these manually to Colors.plist and pushed the changes.

Björn

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Color.plist rgb values are wrong (fix attached)

Zvezdan Petkovic

On Feb 25, 2009, at 2:25 PM, björn wrote:
> It seems three colors that are in Vim are not included in the output
> of "showrgb", namely:
>
> darkyellow
> lightmagenta
> lightred

Yes, I noticed that in vimdiff of the original and generated plist.
However, since neither showrgb nor Wikipedia page on X11 colors list  
those three colors I thought they could be safely omitted.

> I have added these manually to Colors.plist and pushed the changes.


Perhaps you think they are important to maintain compatibility in case  
they were used previously in Vim?

If you want, we can add them to the initialization part before the  
first for loop in rgb2plist.py.  So, instead of starting with an empty  
dictionary

     colors = {}

we could start with

     colors = dict(darkyellow=1234, lightmagenta=5678, lightred=90)

putting the original numbers in, of course.  :-)
It's a small change to apply and easy to test if it works.
Still, if you don't have time I could apply it.

Then they would be generated from the program with all the other  
numbers.  We wouldn't need to think about forgetting them in case the  
plist is ever re-generated (assuming that you committed rgb2plist.py  
together with Colors.plist to the repo).

        Zvezdan
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Color.plist rgb values are wrong (fix attached)

Dewdman42
In reply to this post by Zvezdan Petkovic
I'm just catching up to this thread.  I see that the latest 7.2 version of Macvim seems to have the new Colors.plist values, as fixed by you guys on this thread.  Still, what I observe is that the colors on MacVim do not seem to appear correctly.  The white color is faded towards grey, the dark backgrounds are less dark, etc then what I see on other platforms.  

Am I alone on this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Color.plist rgb values are wrong (fix attached)

Dewdman42
Here is an image comparing 3 windows.  I did this screen snap all at once, all three windows are appearing on my mac desktop at the same time(the windows one is using MS RemoteDesktop to view vim on windows).  

(see notes below)



The left most window is out of the box MacVim with the "desert" colorscheme.  Note the white fonts are clearly less-than-white.  

On the far right is a remote desktop connection to  PC running Vim over there, and you can see that the background is darker, the white letters are brighter....on the same display.

In the middle is a modified version of desert colorscheme that changed the guibg to gray14 instead of gray20 in order to get it to match what I would expect to see, but still you can see the white letters are not completely as white as they should be.

This is with the very latest 7.2 stable 1.2 (33.3).

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Color.plist rgb values are wrong (fix attached)

Björn Winckler
On 10 August 2010 06:05, Dewdman42 wrote:

>
> Here is an image comparing 3 windows.  I did this screen snap all at once,
> all three windows are appearing on my mac desktop at the same time(the
> windows one is using MS RemoteDesktop to view vim on windows).
>
> (see notes below)
>
> http://vim.1045645.n5.nabble.com/file/n2375109/example.jpg
>
> The left most window is out of the box MacVim with the "desert" colorscheme.
> Note the white fonts are clearly less-than-white.
>
> On the far right is a remote desktop connection to  PC running Vim over
> there, and you can see that the background is darker, the white letters are
> brighter....on the same display.
>
> In the middle is a modified version of desert colorscheme that changed the
> guibg to gray14 instead of gray20 in order to get it to match what I would
> expect to see, but still you can see the white letters are not completely as
> white as they should be.
>
> This is with the very latest 7.2 stable 1.2 (33.3).

It's fixed in the latest snapshot, or you could try the 7.3 BETA:

http://github.com/b4winckler/macvim/downloads

(By the way: This problem has nothing to do with the original issue
reported in this thread.  It was caused by the fact that MacVim used
to use calibrated colors, but nowadays it uses device colors like most
other apps.)

Björn

--
You received this message from the "vim_mac" 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
Loading...