Terminal++ 3.1.0.4
A C++ library for interacting with ANSI terminal windows
Loading...
Searching...
No Matches
graphics.hpp
1#pragma once
2#include "terminalpp/core.hpp"
3
4//* =========================================================================
8//* =========================================================================
10
11// clang-format off
12inline constexpr byte no_attributes = 0;
13
14// Intensity Constants
15inline constexpr byte bold = 1;
16inline constexpr byte faint = 2;
17inline constexpr byte normal_intensity = 22;
18
19// Underlining Constants
20inline constexpr byte underlined = 4;
21inline constexpr byte not_underlined = 24;
22
23// Blinking Constants
24inline constexpr byte blinking = 5;
25inline constexpr byte steady = 25;
26
27// Polarity Constants
28inline constexpr byte negative_polarity = 7;
29inline constexpr byte positive_polarity = 27;
30
31// "Low" colour constants
32inline constexpr byte foreground_colour_base = 30;
33inline constexpr byte background_colour_base = 40;
34
35inline constexpr byte colour_black = 0;
36inline constexpr byte colour_red = 1;
37inline constexpr byte colour_green = 2;
38inline constexpr byte colour_yellow = 3;
39inline constexpr byte colour_blue = 4;
40inline constexpr byte colour_magenta = 5;
41inline constexpr byte colour_cyan = 6;
42inline constexpr byte colour_white = 7;
43inline constexpr byte colour_default = 9;
44// clang-format on
45
46// "High" colour constants.
47// High colours are the middle 216 RGB colours of the 256-colour palette,
48// where there are 6 possible values for each of R, G, B, and the colour
49// components are stored according to multiples of that number such that
50// the value of the colour is 36R + 6G + B. This is then stored offset
51// 16.
52inline constexpr byte high_colour_offset = 16;
53
54// High colours (16-231) are sorted according to their respective hues.
55inline constexpr auto red_coefficient = 36;
56inline constexpr auto green_coefficient = 6;
57inline constexpr auto blue_coefficient = 1;
58
59// ==========================================================================
61// ==========================================================================
62constexpr byte encode_high_components(byte red, byte green, byte blue) noexcept
63{
64 return high_colour_offset + (red * red_coefficient)
65 + (green * green_coefficient) + (blue * blue_coefficient);
66}
67
68// ==========================================================================
70// ==========================================================================
71constexpr byte high_red_component(byte value) noexcept
72{
73 return (value - high_colour_offset) / red_coefficient;
74}
75
76// ==========================================================================
78// ==========================================================================
79constexpr byte high_green_component(byte value) noexcept
80{
81 return ((value - high_colour_offset) % red_coefficient) / green_coefficient;
82}
83
84// ==========================================================================
86// ==========================================================================
87constexpr byte high_blue_component(byte value) noexcept
88{
89 return (value - high_colour_offset) % green_coefficient;
90}
91
92// "Greyscale" colour constants.
93// Greyscale colours are last 24 RGB colours of the 256-colour palette,
94// each of which represents a grey colour from black to white. This value
95// is then stored offset 232.
96inline constexpr byte greyscale_colour_offset = 232;
97
98// ==========================================================================
100// ==========================================================================
101constexpr byte encode_greyscale_component(byte grey) noexcept
102{
103 return greyscale_colour_offset + grey;
104}
105
106// ==========================================================================
108// ==========================================================================
109constexpr byte greyscale_component(byte value) noexcept
110{
111 return value - greyscale_colour_offset;
112}
113
114} // namespace terminalpp::ansi::graphics
Contains constants for the Select Graphics Rendition command parameters.
constexpr byte encode_greyscale_component(byte grey) noexcept
Encode a greyscale value.
Definition graphics.hpp:101
constexpr byte encode_high_components(byte red, byte green, byte blue) noexcept
Encode an RGB value.
Definition graphics.hpp:62
constexpr byte high_green_component(byte value) noexcept
Extract the green component of a high colour value.
Definition graphics.hpp:79
constexpr byte high_red_component(byte value) noexcept
Extract the red component of a high colour value.
Definition graphics.hpp:71
constexpr byte greyscale_component(byte value) noexcept
Extract a greyscale value.
Definition graphics.hpp:109
constexpr byte high_blue_component(byte value) noexcept
Extract the blue component of a high colour value.
Definition graphics.hpp:87