xvdiff
xvdiff

Reputation: 2229

Representing colors

I'm currently trying to create some sort of graphical interface framework for consoles and terminal emulators, similar to lanterna, but with a more declarative approach, however I stumpled upon something that is giving me headaches for days now: Colors.

What I'm looking forward to is a way to represent colors as well as color palettes independently of the underlying implementation and scheme (ANSI, Indexed, 24-bit for VGA, xterm, Windows..). My initial idea was to create a simple struct that represents a color in the RGB color space:

public struct Color {
    public byte R, G, B;
}

... and declare a predefined set of colors such as public static readonly Color Black = new Color(0, 0, 0); However this might won't work because e.g. red on xterm is not the same as red in a Windows Console. Then I thought about using enum, but here I'm unable to define what value a color exactly has.

What would be a possible way to achive this? Are there other color spaces that might be more suitable to represent colors than RGB?

Upvotes: 2

Views: 372

Answers (1)

peaceoutside
peaceoutside

Reputation: 962

Also, it would be nice if they could be combine e.g: Color Yellow = Color.Red | Color.Green. Does this make sense somehow?

If Color is simply an integer, then Color.Yellow == Color.Red | Color.Green works without any extra code (it's equivalent to 0xFFFF00 == 0xFF0000 | 0x00FF00). If you want color to have separate R, G and B properties, then you could do some fancy operator overloading and have that still work.

What I'm looking forward to is a way to represent colors as well as color palettes independently of the underlying implementation and scheme (ANSI, Indexed, 24-bit for VGA, xterm, Windows..). My initial idea was to create a simple struct that represents a color in the RGB color space:

...

Are there other color spaces that might be more suitable to represent colors than RGB?

I'm a fan of this one:

http://en.wikipedia.org/wiki/Lab_color_space

This explains why:

http://mycarta.wordpress.com/2012/05/29/the-rainbow-is-dead-long-live-the-rainbow-series-outline/

Upvotes: 1

Related Questions