Jones
Jones

Reputation: 1214

How does ncurses' init_color function translate to traditional rbg colors?

Sorry for the oddly worded title. I'd like to know how the ncurses init_color function maps it's input to colors. Essentially, most developers are used to colors being represented by red, green, and blue on a 0 - 255 scale, but init_color takes an int on a 0 - 1000 scale.

for example:

If I wanted to get the color (75, 0, 130) in ncurses, would I call init_color(COLOR_NAME, 300, 0, 520)?

Upvotes: 1

Views: 353

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54524

short:

(n) * 1000 / 256

which is a little different from your numbers:

293 0 508

long: That of course assumes that the terminal description is written to match ncurses' documentation. But the assumption is from X/Open Curses:

The init_color() function redefines colour number color, on terminals that support the redefinition of colours, to have the red, green, and blue intensity components specified by red, green, and blue, respectively. Calling init_color() also changes all occurrences of the specified colour on the screen to the new definition.

The color_content() function identifies the intensity components of colour number color. It stores the red, green, and blue intensity components of this colour in the addresses pointed to by red, green, and blue, respectively.

For both functions, the color argument must be in the range from 0 to and including COLORS-1. Valid intensity values range from 0 (no intensity component) up to and including 1000 (maximum intensity in that component).

Upvotes: 2

Related Questions