49 return (v << 4) | (v);
60 return (v << 3) | (v >> 2);
70 return (v << 2) | (v >> 4);
79 const u32 r = (src & 0x000F) << 0;
80 const u32 g = (src & 0x00F0) << 4;
81 const u32 b = (src & 0x0F00) << 8;
82 const u32 a = (src & 0xF000) << 12;
84 const u32 c = r | g | b | a;
98 u8 a = (src >> 15) & 0x1;
100 return (a << 24) | (b << 16) | (g << 8) | r;
114 return (a << 24) | (b << 16) | (g << 8) | r;
123 u32 r = (value >> 3) & 0x1F;
124 u32 g = (value >> 5) & (0x3F << 5);
125 u32 b = (value >> 8) & (0x1F << 11);
126 return (
u16)(r | g | b);
135 u32 r = (value >> 3) & 0x1F;
136 u32 g = (value >> 6) & (0x1F << 5);
137 u32 b = (value >> 9) & (0x1F << 10);
138 u32 a = (value >> 16) & 0x8000;
139 return (
u16)(r | g | b | a);
148 const u32 c = value >> 4;
149 const u16 r = (c >> 0) & 0x000F;
150 const u16 g = (c >> 4) & 0x00F0;
151 const u16 b = (c >> 8) & 0x0F00;
152 const u16 a = (c >> 12) & 0xF000;
153 return r | g | b | a;
163 std::string hex =
"#";
167 if (!alpha) hex.resize(7);
181 if (!hex.empty() && hex.at(0) ==
'#') hex = hex.substr(1);
183 while (hex.length() < 8) hex +=
"f";
198 fcolor.r = (
color & 0xFF) / 255.0f;
199 fcolor.g = ((
color >> 8) & 0xFF) / 255.0f;
200 fcolor.b = ((
color >> 16) & 0xFF) / 255.0f;
201 fcolor.a = ((
color >> 24) & 0xFF) / 255.0f;
215 u8 c =
static_cast<u8>(std::round(
color * 255.0f));
231 u32 a = ((
u32)(0xFF)) << 24;
233 return (a | b | g | r);
250 return (a | b | g | r);
260 return (c < 0.0f) ? 0.0f : c * (1.0f / 12.92f);
262 return std::pow((c + 0.055f) * (1.0f / 1.055f), 2.4f);
274 for (std::size_t i = 0; i < std::min<std::size_t>(
color.length(), 3U); i++) {
288 return (c < 0.0f) ? 0.0f : c * 12.92f;
290 return 1.055f * std::pow(c, 1.0f / 2.4f) - 0.055f;
301 for (std::size_t i = 0; i < std::min<std::size_t>(
color.length(), 3U); i++) {
Provides functions and classes for handling binary data.
Contains macros and definitions for fixed-width types.
float SRGBToLinear(float c) noexcept
Converts an sRGB color value to a linear color value.
Definition color.hpp:258
u8 Convert4To8(u8 v) noexcept
Converts a 4-bit color channel value to an 8-bit color channel value.
Definition color.hpp:47
glm::vec4 IntToFloat(u32 color) noexcept
Converts an integer color value to a floating-point vector representation.
Definition color.hpp:196
u32 RGBA4444ToRGBA8888(u16 src) noexcept
Converts RGBA4444 color format to RGBA8888 color format.
Definition color.hpp:78
u8 Convert5To8(u8 v) noexcept
Converts a 5-bit color channel value to an 8-bit color channel value.
Definition color.hpp:58
u16 RGBA8888ToRGBA4444(u32 value) noexcept
Converts RGBA8888 color format to RGBA4444 color format.
Definition color.hpp:147
u32 RGBA5551ToRGBA8888(u16 src) noexcept
Converts RGBA5551 color format to RGBA8888 color format.
Definition color.hpp:94
u16 RGBA8888ToRGBA5551(u32 value) noexcept
Converts RGBA8888 color format to RGBA5551 color format.
Definition color.hpp:134
float LinearToSRGB(float c) noexcept
Converts a linear color value to an sRGB color value.
Definition color.hpp:286
u32 HexToInt(std::string hex)
Converts a hex string representation of a color to an integer color value.
Definition color.hpp:178
u32 RGB565ToRGBA8888(u16 src) noexcept
Converts RGB565 color format to RGBA8888 color format.
Definition color.hpp:109
std::string IntToHex(u32 color, bool alpha=true)
Converts an integer color value to a hex string representation.
Definition color.hpp:162
u8 FloatToInt(float color) noexcept
Converts a floating-point color value to an integer color representation.
Definition color.hpp:213
u16 RGBA8888ToRGB565(u32 value) noexcept
Converts RGBA8888 color format to RGB565 color format.
Definition color.hpp:122
u8 Convert6To8(u8 v) noexcept
Converts a 6-bit color channel value to an 8-bit color channel value.
Definition color.hpp:68
#define NNL_EXPECTS_DBG(precondition)
Debug-only precondition check.
Definition contract.hpp:59
T SwapEndian(T src) noexcept
Swaps endianness of a value.
Definition data.hpp:51
std::uint16_t u16
16-bit unsigned integer
Definition fixed_type.hpp:62
std::uint32_t u32
32-bit unsigned integer
Definition fixed_type.hpp:60
std::uint8_t u8
8-bit unsigned integer
Definition fixed_type.hpp:64
std::string IntToHex(T i, bool prefix=false, bool prepend=true)
Converts an integer to a hexadecimal string.
Definition string.hpp:95
Provides functions for color conversion and manipulation.
Definition color.hpp:34
Definition exception.hpp:56
Contains various utility functions for working with strings.