简体   繁体   中英

256 bit image mask for xterm-256

I am using ncurses with c++ on a xterm-256 display and I would like to print my text in shades of red, but I'm having trouble finding a simple way to do this.

Using this chart I can see that 0x009 is red and that 0x255 - 0x232 will be various shades of black. How can I go about using this information to form a mast for my colors?

I would basically like to form a map such that 10 means white and 20 means red, such that 15 would be pink and so on. I would then create color pairs with

init_pair(10, ???, COLOR_BLACK);
init_pair(11, ???, COLOR_BLACK);
...
init_pair(20, ???, COLOR_BLACK);

so that I could use these colors later to shade from white to red.

It depends on what assumptions you want to make. The layout of the xterm 256color feature is a given, with three parts:

  1. colors 0-15 are ANSI colors and bright versions of those.
  2. colors 16-231 are a 6x6x6 color cube
  3. colors 232-255 are a grayscale ramp, intentionally leaving out black and white

See for example 256color.pl (widely copied from xterm sources). The numbers make more sense than the chart when you see the picture:

在此处输入图片说明

You could simply refer to those color numbers in init_pair . Bright red as you have noticed is 9 ( COLOR_RED + 8).

On the other hand, the color palette can be modified. You could use init_color (giving your own red/green/blue triple) to define a color by number, and use that in init_pair .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM