The Battle for Wesnoth  1.19.7+dev
Classes | Functions | Variables
color.hpp File Reference
#include <SDL2/SDL_pixels.h>
#include <algorithm>
#include <cstdint>
#include <ostream>
#include <string>
#include <utility>
Include dependency graph for color.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  color_t
 The basic class for representing 8-bit RGB or RGBA colour values. More...
 
struct  std::hash< color_t >
 

Functions

constexpr uint8_t float_to_color (double n)
 Convert a double in the range [0.0,1.0] to an 8-bit colour value. More...
 
constexpr uint8_t float_to_color (float n)
 Convert a float in the range [0.0,1.0] to an 8-bit colour value. More...
 
constexpr uint8_t color_multiply (uint8_t n1, uint8_t n2)
 Multiply two 8-bit colour values as if in the range [0.0,1.0]. More...
 
constexpr uint8_t color_blend (uint8_t n1, uint8_t n2, uint8_t p)
 Blend 8-bit colour value with another in the given proportion. More...
 
std::ostream & operator<< (std::ostream &s, const color_t &c)
 

Variables

constexpr uint32_t SDL_ALPHA_MASK = 0xFF000000
 
constexpr uint32_t SDL_RED_MASK = 0x00FF0000
 
constexpr uint32_t SDL_GREEN_MASK = 0x0000FF00
 
constexpr uint32_t SDL_BLUE_MASK = 0x000000FF
 
constexpr uint32_t SDL_ALPHA_BITSHIFT = 24
 
constexpr uint32_t SDL_RED_BITSHIFT = 16
 
constexpr uint32_t SDL_GREEN_BITSHIFT = 8
 
constexpr uint32_t SDL_BLUE_BITSHIFT = 0
 
constexpr uint32_t RGBA_ALPHA_MASK = 0x000000FF
 
constexpr uint32_t RGBA_RED_MASK = 0xFF000000
 
constexpr uint32_t RGBA_GREEN_MASK = 0x00FF0000
 
constexpr uint32_t RGBA_BLUE_MASK = 0x0000FF00
 
constexpr uint32_t RGBA_ALPHA_BITSHIFT = 0
 
constexpr uint32_t RGBA_RED_BITSHIFT = 24
 
constexpr uint32_t RGBA_GREEN_BITSHIFT = 16
 
constexpr uint32_t RGBA_BLUE_BITSHIFT = 8
 
constexpr uint8_t ALPHA_OPAQUE = SDL_ALPHA_OPAQUE
 

Function Documentation

◆ color_blend()

constexpr uint8_t color_blend ( uint8_t  n1,
uint8_t  n2,
uint8_t  p 
)
constexpr

Blend 8-bit colour value with another in the given proportion.

A proportion of 0 returns the first value, 255 the second.

Definition at line 306 of file color.hpp.

References color_multiply(), and p.

Referenced by color_t::smooth_blend().

◆ color_multiply()

constexpr uint8_t color_multiply ( uint8_t  n1,
uint8_t  n2 
)
constexpr

Multiply two 8-bit colour values as if in the range [0.0,1.0].

Definition at line 296 of file color.hpp.

Referenced by color_blend(), and image::o_modification::operator()().

◆ float_to_color() [1/2]

constexpr uint8_t float_to_color ( double  n)
constexpr

Convert a double in the range [0.0,1.0] to an 8-bit colour value.

Definition at line 280 of file color.hpp.

References n.

Referenced by display::fade_to(), display::fade_tod_mask(), image::o_modification::operator()(), unit_frame::redraw(), unit_drawer::redraw_unit(), and display::update_fps_label().

◆ float_to_color() [2/2]

constexpr uint8_t float_to_color ( float  n)
constexpr

Convert a float in the range [0.0,1.0] to an 8-bit colour value.

Definition at line 288 of file color.hpp.

References n.

◆ operator<<()

std::ostream& operator<< ( std::ostream &  s,
const color_t c 
)
inline

Definition at line 257 of file color.hpp.

References c, and s.

Variable Documentation

◆ ALPHA_OPAQUE

constexpr uint8_t ALPHA_OPAQUE = SDL_ALPHA_OPAQUE
constexpr

◆ RGBA_ALPHA_BITSHIFT

constexpr uint32_t RGBA_ALPHA_BITSHIFT = 0
constexpr

Definition at line 40 of file color.hpp.

Referenced by color_t::from_rgba_bytes(), and color_t::to_rgba_bytes().

◆ RGBA_ALPHA_MASK

constexpr uint32_t RGBA_ALPHA_MASK = 0x000000FF
constexpr

Definition at line 35 of file color.hpp.

Referenced by color_t::from_rgba_bytes().

◆ RGBA_BLUE_BITSHIFT

constexpr uint32_t RGBA_BLUE_BITSHIFT = 8
constexpr

Definition at line 43 of file color.hpp.

Referenced by color_t::from_rgba_bytes(), and color_t::to_rgba_bytes().

◆ RGBA_BLUE_MASK

constexpr uint32_t RGBA_BLUE_MASK = 0x0000FF00
constexpr

Definition at line 38 of file color.hpp.

Referenced by color_t::from_rgba_bytes().

◆ RGBA_GREEN_BITSHIFT

constexpr uint32_t RGBA_GREEN_BITSHIFT = 16
constexpr

Definition at line 42 of file color.hpp.

Referenced by color_t::from_rgba_bytes(), and color_t::to_rgba_bytes().

◆ RGBA_GREEN_MASK

constexpr uint32_t RGBA_GREEN_MASK = 0x00FF0000
constexpr

Definition at line 37 of file color.hpp.

Referenced by color_t::from_rgba_bytes().

◆ RGBA_RED_BITSHIFT

constexpr uint32_t RGBA_RED_BITSHIFT = 24
constexpr

Definition at line 41 of file color.hpp.

Referenced by color_t::from_rgba_bytes(), and color_t::to_rgba_bytes().

◆ RGBA_RED_MASK

constexpr uint32_t RGBA_RED_MASK = 0xFF000000
constexpr

Definition at line 36 of file color.hpp.

Referenced by color_t::from_rgba_bytes().

◆ SDL_ALPHA_BITSHIFT

constexpr uint32_t SDL_ALPHA_BITSHIFT = 24
constexpr

Definition at line 30 of file color.hpp.

Referenced by color_t::from_argb_bytes(), and color_t::to_argb_bytes().

◆ SDL_ALPHA_MASK

constexpr uint32_t SDL_ALPHA_MASK = 0xFF000000
constexpr

Definition at line 25 of file color.hpp.

Referenced by color_t::from_argb_bytes(), and surface::is_neutral().

◆ SDL_BLUE_BITSHIFT

constexpr uint32_t SDL_BLUE_BITSHIFT = 0
constexpr

Definition at line 33 of file color.hpp.

Referenced by color_t::from_argb_bytes(), and color_t::to_argb_bytes().

◆ SDL_BLUE_MASK

constexpr uint32_t SDL_BLUE_MASK = 0x000000FF
constexpr

Definition at line 28 of file color.hpp.

Referenced by color_t::from_argb_bytes().

◆ SDL_GREEN_BITSHIFT

constexpr uint32_t SDL_GREEN_BITSHIFT = 8
constexpr

Definition at line 32 of file color.hpp.

Referenced by color_t::from_argb_bytes(), and color_t::to_argb_bytes().

◆ SDL_GREEN_MASK

constexpr uint32_t SDL_GREEN_MASK = 0x0000FF00
constexpr

Definition at line 27 of file color.hpp.

Referenced by color_t::from_argb_bytes().

◆ SDL_RED_BITSHIFT

constexpr uint32_t SDL_RED_BITSHIFT = 16
constexpr

Definition at line 31 of file color.hpp.

Referenced by color_t::from_argb_bytes(), and color_t::to_argb_bytes().

◆ SDL_RED_MASK

constexpr uint32_t SDL_RED_MASK = 0x00FF0000
constexpr

Definition at line 26 of file color.hpp.

Referenced by color_t::from_argb_bytes(), and surface::is_neutral().