From 5caa80ad190ea7989287ce89bb9914d5521f7bdf Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Wed, 2 Oct 2024 17:15:41 +0300 Subject: [PATCH] Conditionally clamping input value in Make5/6 --- openVulkanoCpp/Math/RGB565.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/openVulkanoCpp/Math/RGB565.hpp b/openVulkanoCpp/Math/RGB565.hpp index 2a667d7..ef86ed6 100644 --- a/openVulkanoCpp/Math/RGB565.hpp +++ b/openVulkanoCpp/Math/RGB565.hpp @@ -13,14 +13,22 @@ namespace OpenVulkano::Math { class RGB565 { - static uint16_t Make5(int16_t val) + template + static uint16_t Make5(T val) { - val = std::clamp(val, 0, 255); + if constexpr (std::is_same_v || std::is_same_v) + { + val = std::clamp(val, 0, 255); + } return val * 31.0f / 255.0f; } - static uint16_t Make6(int16_t val) + template + static uint16_t Make6(T val) { - val = std::clamp(val, 0, 255); + if constexpr (std::is_same_v || std::is_same_v) + { + val = std::clamp(val, 0, 255); + } return val * 63.0f / 255.0f; } static uint8_t Unmake5(uint16_t val) { return static_cast(val * 255.0f / 31.0f); }