Conditionally clamping input value in Make5/6
This commit is contained in:
@@ -13,14 +13,22 @@ namespace OpenVulkano::Math
|
|||||||
{
|
{
|
||||||
class RGB565
|
class RGB565
|
||||||
{
|
{
|
||||||
static uint16_t Make5(int16_t val)
|
template<typename T>
|
||||||
|
static uint16_t Make5(T val)
|
||||||
{
|
{
|
||||||
val = std::clamp<int16_t>(val, 0, 255);
|
if constexpr (std::is_same_v<T, uint8_t> || std::is_same_v<T, int8_t>)
|
||||||
|
{
|
||||||
|
val = std::clamp<int16_t>(val, 0, 255);
|
||||||
|
}
|
||||||
return val * 31.0f / 255.0f;
|
return val * 31.0f / 255.0f;
|
||||||
}
|
}
|
||||||
static uint16_t Make6(int16_t val)
|
template<typename T>
|
||||||
|
static uint16_t Make6(T val)
|
||||||
{
|
{
|
||||||
val = std::clamp<int16_t>(val, 0, 255);
|
if constexpr (std::is_same_v<T, uint8_t> || std::is_same_v<T, int8_t>)
|
||||||
|
{
|
||||||
|
val = std::clamp<int16_t>(val, 0, 255);
|
||||||
|
}
|
||||||
return val * 63.0f / 255.0f;
|
return val * 63.0f / 255.0f;
|
||||||
}
|
}
|
||||||
static uint8_t Unmake5(uint16_t val) { return static_cast<uint8_t>(val * 255.0f / 31.0f); }
|
static uint8_t Unmake5(uint16_t val) { return static_cast<uint8_t>(val * 255.0f / 31.0f); }
|
||||||
|
|||||||
Reference in New Issue
Block a user