libtcod
Loading...
Searching...
No Matches
color.h File Reference

Color handling module. More...

#include <stdbool.h>
#include <stdint.h>
#include <istream>
#include <ostream>
#include <stdexcept>
#include "config.h"

Go to the source code of this file.

Classes

struct  TCOD_ColorRGB
 A 3-channel RGB color struct. More...
 
struct  TCOD_ColorRGBA
 A 4-channel RGBA color struct. More...
 

Typedefs

typedef struct TCOD_ColorRGB TCOD_color_t
 
typedef struct TCOD_ColorRGB TCOD_ColorRGB
 
typedef struct TCOD_ColorRGBA TCOD_ColorRGBA
 

Functions

TCOD_color_t TCOD_color_RGB (uint8_t r, uint8_t g, uint8_t b)
 Return a new TCOD_color_t from RGB values.
 
TCOD_color_t TCOD_color_HSV (float hue, float saturation, float value)
 Return a new TCOD_color_t from HSV values.
 
bool TCOD_color_equals (TCOD_color_t c1, TCOD_color_t c2)
 Return true value if c1 and c2 are equal.
 
TCOD_color_t TCOD_color_add (TCOD_color_t c1, TCOD_color_t c2)
 Add two colors together and return the result.
 
TCOD_color_t TCOD_color_subtract (TCOD_color_t c1, TCOD_color_t c2)
 Subtract c2 from c1 and return the result.
 
TCOD_color_t TCOD_color_multiply (TCOD_color_t c1, TCOD_color_t c2)
 Multiply two colors together and return the result.
 
TCOD_color_t TCOD_color_multiply_scalar (TCOD_color_t c1, float value)
 Multiply a color with a scalar value and return the result.
 
TCOD_color_t TCOD_color_lerp (TCOD_color_t c1, TCOD_color_t c2, float coef)
 Interpolate two colors together and return the result.
 
void TCOD_color_set_HSV (TCOD_color_t *color, float hue, float saturation, float value)
 Sets a colors values from HSV values.
 
void TCOD_color_get_HSV (TCOD_color_t color, float *hue, float *saturation, float *value)
 Get a set of HSV values from a color.
 
float TCOD_color_get_hue (TCOD_color_t color)
 Return a colors hue.
 
void TCOD_color_set_hue (TCOD_color_t *color, float hue)
 Change a colors hue.
 
float TCOD_color_get_saturation (TCOD_color_t color)
 Return a colors saturation.
 
void TCOD_color_set_saturation (TCOD_color_t *color, float saturation)
 Change a colors saturation.
 
float TCOD_color_get_value (TCOD_color_t color)
 Get a colors value.
 
void TCOD_color_set_value (TCOD_color_t *color, float value)
 Change a colors value.
 
void TCOD_color_shift_hue (TCOD_color_t *color, float shift)
 Shift a colors hue by an amount.
 
void TCOD_color_scale_HSV (TCOD_color_t *color, float saturation_coef, float value_coef)
 Scale a colors saturation and value.
 
void TCOD_color_gen_map (TCOD_color_t *map, int nb_key, const TCOD_color_t *key_color, const int *key_index)
 Generate an interpolated gradient of colors.
 

Detailed Description

Color handling module.

Function Documentation

◆ TCOD_color_add()

TCOD_color_t TCOD_color_add ( TCOD_color_t c1,
TCOD_color_t c2 )

Add two colors together and return the result.

Parameters
c1The first color.
c2The second color.
Returns
A new TCOD_color_t struct with the result.

◆ TCOD_color_gen_map()

void TCOD_color_gen_map ( TCOD_color_t * map,
int nb_key,
const TCOD_color_t * key_color,
const int * key_index )

Generate an interpolated gradient of colors.

Parameters
mapArray to fill with the new gradient.
nb_keyThe array size of the key_color and key_index parameters.
key_colorAn array of colors to use, in order.
key_indexAn array mapping key_color items to the map array.
TCOD_color_t[256] gradient;
const TCOD_color_t[4] key_color = {TCOD_black, TCOD_dark_amber, TCOD_cyan, TCOD_white};
const int[4] key_index = {0, 64, 192, 255};
TCOD_color_gen_map(&gradient, 4, &key_color, &key_index);
void TCOD_color_gen_map(TCOD_color_t *map, int nb_key, const TCOD_color_t *key_color, const int *key_index)
Generate an interpolated gradient of colors.

◆ TCOD_color_get_HSV()

void TCOD_color_get_HSV ( TCOD_color_t color,
float * hue,
float * saturation,
float * value )

Get a set of HSV values from a color.

Parameters
colorThe color
huePointer to a float, filled with the hue. (degrees)
saturationPointer to a float, filled with the saturation. (0 to 1)
valuePointer to a float, filled with the value. (0 to 1)

The hue, saturation, and value parameters can not be NULL pointers,

◆ TCOD_color_get_hue()

float TCOD_color_get_hue ( TCOD_color_t color)

Return a colors hue.

Parameters
colorA color struct.
Returns
The colors hue. (degrees)

◆ TCOD_color_get_saturation()

float TCOD_color_get_saturation ( TCOD_color_t color)

Return a colors saturation.

Parameters
colorA color struct.
Returns
The colors saturation. (0 to 1)

◆ TCOD_color_get_value()

float TCOD_color_get_value ( TCOD_color_t color)

Get a colors value.

Parameters
colorA color struct.
Returns
The colors value. (0 to 1)

◆ TCOD_color_HSV()

TCOD_color_t TCOD_color_HSV ( float hue,
float saturation,
float value )

Return a new TCOD_color_t from HSV values.

Parameters
hueThe colors hue (in degrees.)
saturationThe colors saturation (from 0 to 1)
valueThe colors value (from 0 to 1)
Returns
A new TCOD_color_t struct.

The saturation and value parameters are automatically clamped to 0 and 1.

TCOD_color_t light_blue = TCOD_color_HSV(240.0f, 0.75f, 1.0f);

Use TCOD_color_set_HSV to fill an existing struct with HSV values.

◆ TCOD_color_lerp()

TCOD_color_t TCOD_color_lerp ( TCOD_color_t c1,
TCOD_color_t c2,
float coef )

Interpolate two colors together and return the result.

Parameters
c1The first color (where coef if 0)
c2The second color (where coef if 1)
coefThe coefficient.
Returns
A new TCOD_color_t struct with the result.

◆ TCOD_color_multiply()

TCOD_color_t TCOD_color_multiply ( TCOD_color_t c1,
TCOD_color_t c2 )

Multiply two colors together and return the result.

Parameters
c1The first color.
c2The second color.
Returns
A new TCOD_color_t struct with the result.

◆ TCOD_color_multiply_scalar()

TCOD_color_t TCOD_color_multiply_scalar ( TCOD_color_t c1,
float value )

Multiply a color with a scalar value and return the result.

Parameters
c1The color to multiply.
valueThe scalar float.
Returns
A new TCOD_color_t struct with the result.

◆ TCOD_color_RGB()

TCOD_color_t TCOD_color_RGB ( uint8_t r,
uint8_t g,
uint8_t b )

Return a new TCOD_color_t from RGB values.

Deprecated
This function is redundant and should be replaced with a braced initializer: TCOD_ColorRGB white = {255, 255, 255};

◆ TCOD_color_scale_HSV()

void TCOD_color_scale_HSV ( TCOD_color_t * color,
float saturation_coef,
float value_coef )

Scale a colors saturation and value.

Parameters
colorPointer to a color struct.
saturation_coefMultiplier for this colors saturation.
value_coefMultiplier for this colors value.

◆ TCOD_color_set_HSV()

void TCOD_color_set_HSV ( TCOD_color_t * color,
float hue,
float saturation,
float value )

Sets a colors values from HSV values.

Parameters
colorThe color to be changed.
hueThe colors hue (in degrees.)
saturationThe colors saturation (from 0 to 1)
valueThe colors value (from 0 to 1)

◆ TCOD_color_set_hue()

void TCOD_color_set_hue ( TCOD_color_t * color,
float hue )

Change a colors hue.

Parameters
colorPointer to a color struct.
hueThe hue in degrees.

◆ TCOD_color_set_saturation()

void TCOD_color_set_saturation ( TCOD_color_t * color,
float saturation )

Change a colors saturation.

Parameters
colorPointer to a color struct.
saturationThe desired saturation value.

◆ TCOD_color_set_value()

void TCOD_color_set_value ( TCOD_color_t * color,
float value )

Change a colors value.

Parameters
colorPointer to a color struct.
valueThe desired value.

◆ TCOD_color_shift_hue()

void TCOD_color_shift_hue ( TCOD_color_t * color,
float shift )

Shift a colors hue by an amount.

Parameters
colorPointer to a color struct.
hue_shiftThe distance to shift the hue, in degrees.

◆ TCOD_color_subtract()

TCOD_color_t TCOD_color_subtract ( TCOD_color_t c1,
TCOD_color_t c2 )

Subtract c2 from c1 and return the result.

Parameters
c1The first color.
c2The second color.
Returns
A new TCOD_color_t struct with the result.