49 void parseHexString(
const std::string &color)
51 if constexpr (std::is_same<T, float>::value)
53 if (color.size() == 9)
55 a = (float) std::stoi(color.substr(1, 2),
nullptr, 16) / 255;
56 r = (float) std::stoi(color.substr(3, 2),
nullptr, 16) / 255;
57 g = (float) std::stoi(color.substr(5, 2),
nullptr, 16) / 255;
58 b = (float) std::stoi(color.substr(7, 2),
nullptr, 16) / 255;
60 else if (color.size() == 7)
62 r = (float) std::stoi(color.substr(1, 2),
nullptr, 16) / 255;
63 g = (float) std::stoi(color.substr(3, 2),
nullptr, 16) / 255;
64 b = (float) std::stoi(color.substr(5, 2),
nullptr, 16) / 255;
68 else if constexpr (std::is_same<T, uint8_t>::value)
70 if (color.size() == 9)
72 a =
static_cast<uint8_t
>(std::stoi(color.substr(1, 2),
nullptr, 16));
73 r =
static_cast<uint8_t
>(std::stoi(color.substr(3, 2),
nullptr, 16));
74 g =
static_cast<uint8_t
>(std::stoi(color.substr(5, 2),
nullptr, 16));
75 b =
static_cast<uint8_t
>(std::stoi(color.substr(7, 2),
nullptr, 16));
77 else if (color.size() == 7)
79 r =
static_cast<uint8_t
>(std::stoi(color.substr(1, 2),
nullptr, 16));
80 g =
static_cast<uint8_t
>(std::stoi(color.substr(3, 2),
nullptr, 16));
81 b =
static_cast<uint8_t
>(std::stoi(color.substr(5, 2),
nullptr, 16));
101 if constexpr (std::is_same<T, float>::value)
104 return tson::Colorf((
float) r / 255, (
float) g / 255, (
float) b / 255, (
float) a / 255);
116 if constexpr (std::is_same<T, float>::value)
117 return tson::Colori(
static_cast<std::uint8_t
>((
float) r * 255),
118 static_cast<std::uint8_t
>((float) g * 255),
119 static_cast<std::uint8_t
>((float) b * 255),
120 static_cast<std::uint8_t
>((float) a * 255));