From d262daa66f6f047160e21479489add9a2df785af Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Tue, 23 Jul 2024 02:27:29 +0200 Subject: [PATCH] Add RGB565 class --- openVulkanoCpp/Math/RGB565.hpp | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 openVulkanoCpp/Math/RGB565.hpp diff --git a/openVulkanoCpp/Math/RGB565.hpp b/openVulkanoCpp/Math/RGB565.hpp new file mode 100644 index 0000000..1600b5a --- /dev/null +++ b/openVulkanoCpp/Math/RGB565.hpp @@ -0,0 +1,46 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Math/Math.hpp" + +namespace OpenVulkano::Math +{ + class RGB565 + { + uint16_t Make5(uint8_t val) + { + return val * 31.0f / 255.0f; + } + + uint16_t Make6(uint8_t val) + { + return val * 63.0f / 255.0f; + } + + public: + union + { + uint16_t value; + struct + { + uint16_t b : 5; + uint16_t g : 6; + uint16_t r : 5; + }; + }; + + RGB565(Math::Vector4uc color = {0, 0, 0, 1}) + : b(Make5(color.b)) + , g(Make6(color.g)) + , r(Make5(color.r)) + { + } + }; + + static_assert(sizeof(RGB565) == 2); +}