Add RGB565 class

This commit is contained in:
Georg Hagen
2024-07-23 02:27:29 +02:00
parent 545f248436
commit d262daa66f

View File

@@ -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);
}