11

I'm creating my own color scheme for Sublime text based off of a Visual Studio Theme.

The Visual Studio theme has foreground and background defined, but they are not in the standard RGB triplet. I don't know what this number means, and I was wondering how I could convert it into a RGB triplet (ie #FFFFFF) for use in Sublime Text.

Sample:

<Item Name="Comment" Foreground="0x007B7466" Background="0x02000000" BoldFont="No"/>
<Item Name="Plain Text" Foreground="0x00F3F2F1" Background="0x002A2822" BoldFont="No"/>
<Item Name="Selected Text" Foreground="0x00FFFFFF" Background="0x0064614F" BoldFont="No"/>

I've tried searching on here and google, but apparently I can't get my search terms correct to find the right answers.

Richie Li
  • 1,257
  • 2
  • 13
  • 20

3 Answers3

20

Just as an FYI the vsettings file uses BGR not RGB

Shawn
  • 393
  • 1
  • 7
  • 3
    Your little "FYI" was worth a lot more to me than "could be RGB, could be BGR, could be A/XBGR or ARGB, just test it and see.." (no offence to @ssube, he meant well but I don't like answers prodding in the dark) – MarioDS Mar 29 '16 at 12:30
  • 1
    Did earlier versions of Visual Studio use RGB? The reason I ask is that I found a blog post about a dark theme vssettings file for SSMS 2012 (based on VS 2010 shell). When I imported the settings into SSMS 2016 (based on VS 2015 shell) the R and B components appeared reversed, compared to the original values mentioned in the blog. So I was wondering if the format of the colors in the vssettings file changed between VS 2010 and 2015. – Simon Elms Oct 04 '16 at 00:10
5

These appear, at a glance (and with some knowledge of how MS likes to handle colors) to be ARGB or XRGB DWORDs in hex form. Depending on what you're doing, though, they could be A/XBGR.

Most likely, the first two characters are alpha, then red, green, and blue. That's a pretty standard way of laying out colors, since it neatly fits in a memory register and matches texture data for a few formats.

However, some places like to reverse that, which matches other texture formats. The A/X remains at the start, then blue, green, and red.

This should be easy to test for, by providing 0x00FF0000. If blue, the BGR, if red, RGB.

It is possible that they might be using the first channel/byte as something other than alpha. Packing data into the alpha channel of a 3-channel texture is not uncommon. However, only one of the colors is 0x02..., the rest are all 0x00..., so I wouldn't this is going on (there's also a 3.5 byte color in there, so perhaps typos).

You don't need to do any conversion with these, as they are already hex (actual code hex, not the #... web stuff). To "convert" a web hex triplet, just remove the # and prepend 0x00 and you should be good. All the other characters remain the same (case shouldn't matter, though some people like uppercase as procedure).

ssube
  • 47,010
  • 7
  • 103
  • 140
0

If anyone needs to parse VSSettings colors, you can use this code (using the new Span APIs):

// input is like "0x008CFAF1", ABGR
var color = abgr.AsSpan();
byte blue = byte.Parse(color.Slice(4, 2), NumberStyles.AllowHexSpecifier);
byte green = byte.Parse(color.Slice(6, 2), NumberStyles.AllowHexSpecifier);
byte red = byte.Parse(color.Slice(8, 2), NumberStyles.AllowHexSpecifier);
return Color.FromRgb(red, green, blue);

If you don't have access to AsSpan() you can change the Slice operations to Substring.

Will
  • 2,086
  • 23
  • 30