47 lines
738 B
C++
47 lines
738 B
C++
/*
|
|
* 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);
|
|
}
|