ELinks 0.18.0
|
Terminal color composing. More...
#include "elinks.h"
#include "terminal/color.h"
#include "terminal/draw.h"
#include "util/color.h"
#include "util/error.h"
#include "terminal/palette.inc"
Data Structures | |
struct | rgb |
struct | rgb_cache_entry |
struct | color_mode_info |
Macros | |
#define | RED_COLOR_MASK 0x00FF0000 |
#define | GREEN_COLOR_MASK 0x0000FF00 |
#define | BLUE_COLOR_MASK 0x000000FF |
#define | RED_COLOR(color) (unsigned char)(((color) & RED_COLOR_MASK) >> 16) |
#define | GREEN_COLOR(color) (unsigned char)(((color) & GREEN_COLOR_MASK) >> 8) |
#define | BLUE_COLOR(color) (unsigned char)(((color) & BLUE_COLOR_MASK) >> 0) |
#define | RED(color) (RED_COLOR(color) << 3) |
#define | GREEN(color) (GREEN_COLOR(color) << 2) |
#define | BLUE(color) (BLUE_COLOR(color) << 0) |
#define | RGBCOLOR(color) (RED(color) + GREEN(color) + BLUE(color)) |
#define | RGB_HASH_SIZE 4096 |
#define | HASH_RGB(color, l) ((RGBCOLOR(color) + (l)) & (RGB_HASH_SIZE - 1)) |
#define | CMPCODE(c) (((c) << 1 | (c) >> 2) & TERM_COLOR_MASK) |
#define | use_inverse(bg, fg) CMPCODE(fg & TERM_COLOR_MASK) < CMPCODE(bg) |
Typedefs | |
typedef int | assert_enough_color_modes[(sizeof(color_modes)/sizeof(color_modes[0])==COLOR_MODES) ? 1 :-1] |
Get a compile-time error if the color_modes array has the wrong size. | |
Enumerations | |
enum | palette_range { PALETTE_FULL = 0 , PALETTE_HALF , PALETTE_RANGES } |
Controls what color ranges to use when setting the terminal color. More... | |
Functions | |
static int | color_distance (const struct rgb *c1, const struct rgb *c2) |
static unsigned char | get_color (color_T color, const struct rgb *palette, int level) |
Locates the nearest terminal color. | |
NONSTATIC_INLINE void | set_term_color16 (struct screen_char *schar, color_flags_T flags, unsigned char fg, unsigned char bg) |
color_T | get_term_color16 (unsigned int index) |
Mixes the color pair and attributes to a terminal text color. | |
void | get_screen_char_color (struct screen_char *schar, struct color_pair *pair, color_flags_T flags, color_mode_T color_mode) |
void | set_term_color (struct screen_char *schar, struct color_pair *pair, color_flags_T flags, color_mode_T color_mode) |
Variables | |
static const struct color_mode_info | color_mode_16 |
static const struct color_mode_info *const | color_modes [] |
static const char | fg_color [16][8] |
Map foreground colors to more visible ones on various backgrounds. | |
Terminal color composing.
#define BLUE | ( | color | ) | (BLUE_COLOR(color) << 0) |
#define BLUE_COLOR | ( | color | ) | (unsigned char)(((color) & BLUE_COLOR_MASK) >> 0) |
#define BLUE_COLOR_MASK 0x000000FF |
#define CMPCODE | ( | c | ) | (((c) << 1 | (c) >> 2) & TERM_COLOR_MASK) |
#define GREEN | ( | color | ) | (GREEN_COLOR(color) << 2) |
#define GREEN_COLOR | ( | color | ) | (unsigned char)(((color) & GREEN_COLOR_MASK) >> 8) |
#define GREEN_COLOR_MASK 0x0000FF00 |
#define HASH_RGB | ( | color, | |
l ) ((RGBCOLOR(color) + (l)) & (RGB_HASH_SIZE - 1)) |
#define RED | ( | color | ) | (RED_COLOR(color) << 3) |
#define RED_COLOR | ( | color | ) | (unsigned char)(((color) & RED_COLOR_MASK) >> 16) |
#define RED_COLOR_MASK 0x00FF0000 |
#define RGB_HASH_SIZE 4096 |
#define use_inverse | ( | bg, | |
fg ) CMPCODE(fg & TERM_COLOR_MASK) < CMPCODE(bg) |
typedef int assert_enough_color_modes[(sizeof(color_modes)/sizeof(color_modes[0])==COLOR_MODES) ? 1 :-1] |
Get a compile-time error if the color_modes array has the wrong size.
enum palette_range |
Controls what color ranges to use when setting the terminal color.
Enumerator | |
---|---|
PALETTE_FULL | |
PALETTE_HALF | |
PALETTE_RANGES |
|
inlinestatic |
Locates the nearest terminal color.
void get_screen_char_color | ( | struct screen_char * | schar, |
struct color_pair * | pair, | ||
color_flags_T | flags, | ||
color_mode_T | color_mode ) |
color_T get_term_color16 | ( | unsigned int | index | ) |
Mixes the color pair and attributes to a terminal text color.
If flags has masked in the COLOR_INCREASE_CONTRAST the foreground color will be adjusted.
XXX: schar may not be NULL and is modified adding stuff like boldness.
void set_term_color | ( | struct screen_char * | schar, |
struct color_pair * | pair, | ||
color_flags_T | flags, | ||
color_mode_T | color_mode ) |
NONSTATIC_INLINE void set_term_color16 | ( | struct screen_char * | schar, |
color_flags_T | flags, | ||
unsigned char | fg, | ||
unsigned char | bg ) |
|
static |
|
static |
|
static |
Map foreground colors to more visible ones on various backgrounds.
Use like: fg = fg_color[fg][bg];
This table is based mostly on wild guesses of mine. Feel free to correct it. –pasky