stripped down all pixwerx code to a minimal istic subset

This commit is contained in:
Hartmut Seichter 2023-06-30 20:41:02 +02:00
commit 612677c52d
398 changed files with 164811 additions and 0 deletions

63
src/lib/rgba.hpp Normal file
View file

@ -0,0 +1,63 @@
#ifndef PARADISO_RGBA_HPP
#define PARADISO_RGBA_HPP
#include "globals.hpp"
namespace paradiso
{
struct RGBA final
{
using value_type = std::uint32_t;
value_type pixel{0x0};
static constexpr RGBA from_rgb(uint8_t red, uint8_t green, uint8_t blue) noexcept
{
return from_rgba(red, green, blue, 0xFF);
}
static constexpr RGBA from_rgba(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) noexcept
{
return {
.pixel = (value_type)(((((red << 8) | green) << 8) | blue) << 8) | alpha};
}
constexpr void to_float(float rgba_f[4]) const noexcept
{
rgba_f[0] = static_cast<float>(this->red()) / 0xFF;
rgba_f[1] = static_cast<float>(this->green()) / 0xFF;
rgba_f[2] = static_cast<float>(this->blue()) / 0xFF;
rgba_f[3] = static_cast<float>(this->alpha()) / 0xFF;
}
constexpr uint8_t red() const noexcept { return (pixel & 0xFF000000) >> 24; }
constexpr uint8_t green() const noexcept { return uint8_t((pixel & 0xFF0000) >> 16); }
constexpr uint8_t blue() const noexcept { return uint8_t((pixel & 0xFF00) >> 8); }
constexpr uint8_t alpha() const noexcept { return uint8_t(pixel & 0xFF); }
constexpr RGBA &set_red(uint8_t v) noexcept
{
pixel = (pixel & 0x00FFFFFF) | (v << 24);
return *this;
}
constexpr RGBA &set_green(uint8_t v) noexcept
{
pixel = (pixel & 0xFF00FFFF) | (v << 16);
return *this;
}
constexpr RGBA &set_blue(uint8_t v) noexcept
{
pixel = (pixel & 0xFFFF00FF) | (v << 8);
return *this;
}
constexpr RGBA &set_alpha(uint8_t v) noexcept
{
pixel = (pixel & 0xFFFFFF00) | v;
return *this;
}
};
}
#endif