ELinks 0.18.0
color.c File Reference

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"
Include dependency graph for color.c:

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)
#define GREEN_COLOR(color)
#define BLUE_COLOR(color)
#define RED(color)
#define GREEN(color)
#define BLUE(color)
#define RGBCOLOR(color)
#define RGB_HASH_SIZE   4096
#define HASH_RGB(color, l)
#define CMPCODE(c)
#define use_inverse(bg, fg)

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.

Detailed Description

Terminal color composing.

Macro Definition Documentation

◆ BLUE

#define BLUE ( color)
Value:
(BLUE_COLOR(color) << 0)
#define BLUE_COLOR(color)
Definition renderer.c:245

◆ BLUE_COLOR

#define BLUE_COLOR ( color)
Value:
(unsigned char)(((color) & BLUE_COLOR_MASK) >> 0)
#define BLUE_COLOR_MASK
Definition renderer.c:241

◆ BLUE_COLOR_MASK

#define BLUE_COLOR_MASK   0x000000FF

◆ CMPCODE

#define CMPCODE ( c)
Value:
(((c) << 1 | (c) >> 2) & TERM_COLOR_MASK)
#define TERM_COLOR_MASK
Definition color.h:20

◆ GREEN

#define GREEN ( color)
Value:
(GREEN_COLOR(color) << 2)
#define GREEN_COLOR(color)
Definition renderer.c:244

◆ GREEN_COLOR

#define GREEN_COLOR ( color)
Value:
(unsigned char)(((color) & GREEN_COLOR_MASK) >> 8)
#define GREEN_COLOR_MASK
Definition renderer.c:240

◆ GREEN_COLOR_MASK

#define GREEN_COLOR_MASK   0x0000FF00

◆ HASH_RGB

#define HASH_RGB ( color,
l )
Value:
((RGBCOLOR(color) + (l)) & (RGB_HASH_SIZE - 1))
#define RGBCOLOR(color)
Definition color.c:50
#define RGB_HASH_SIZE
Definition color.c:52

◆ RED

#define RED ( color)
Value:
(RED_COLOR(color) << 3)
#define RED_COLOR(color)
Definition renderer.c:243

◆ RED_COLOR

#define RED_COLOR ( color)
Value:
(unsigned char)(((color) & RED_COLOR_MASK) >> 16)
#define RED_COLOR_MASK
Definition renderer.c:239

◆ RED_COLOR_MASK

#define RED_COLOR_MASK   0x00FF0000

◆ RGB_HASH_SIZE

#define RGB_HASH_SIZE   4096

◆ RGBCOLOR

#define RGBCOLOR ( color)
Value:
(RED(color) + GREEN(color) + BLUE(color))
#define BLUE(color)
Definition color.c:48
#define RED(color)
Definition color.c:46
#define GREEN(color)
Definition color.c:47

◆ use_inverse

#define use_inverse ( bg,
fg )
Value:
#define CMPCODE(c)
Definition color.c:241

Typedef Documentation

◆ assert_enough_color_modes

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.

Enumeration Type Documentation

◆ palette_range

Controls what color ranges to use when setting the terminal color.

Todo
TODO: Part of the 256 color palette is gray scale, maybe we could experiment with a grayscale mode. ;) –jonas
Enumerator
PALETTE_FULL 
PALETTE_HALF 
PALETTE_RANGES 

Function Documentation

◆ color_distance()

int color_distance ( const struct rgb * c1,
const struct rgb * c2 )
inlinestatic

◆ get_color()

unsigned char get_color ( color_T color,
const struct rgb * palette,
int level )
inlinestatic

Locates the nearest terminal color.

◆ get_screen_char_color()

void get_screen_char_color ( struct screen_char * schar,
struct color_pair * pair,
color_flags_T flags,
color_mode_T color_mode )

◆ get_term_color16()

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.

◆ set_term_color()

void set_term_color ( struct screen_char * schar,
struct color_pair * pair,
color_flags_T flags,
color_mode_T color_mode )

◆ set_term_color16()

NONSTATIC_INLINE void set_term_color16 ( struct screen_char * schar,
color_flags_T flags,
unsigned char fg,
unsigned char bg )

Variable Documentation

◆ color_mode_16

const struct color_mode_info color_mode_16
static
Initial value:
= {
palette16,
{
{ 8, 16 },
{ 8, 8 },
}
}

◆ color_modes

const struct color_mode_info* const color_modes[]
static
Initial value:
= {
}
static const struct color_mode_info color_mode_16
Definition color.c:133

◆ fg_color

const char fg_color[16][8]
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