3#include <ntr/ntr_Include.hpp>
7 enum class PixelFormat : u32 {
18 static inline constexpr u32 GetPaletteColorCountForPixelFormat(
const PixelFormat fmt) {
20 case PixelFormat::Palette4: {
23 case PixelFormat::Palette16: {
26 case PixelFormat::Palette256: {
35 enum class MappingType : u32 {
43 enum class CharacterFormat : u32 {
49 enum class ScreenColorMode : u16 {
55 enum class ScreenFormat : u16 {
86 static constexpr u32 RedShift = 0;
87 static constexpr u32 RedBits = 8;
89 static constexpr u32 GreenShift = 8;
90 static constexpr u32 GreenBits = 8;
92 static constexpr u32 BlueShift = 16;
93 static constexpr u32 BlueBits = 8;
95 static constexpr u32 AlphaShift = 24;
96 static constexpr u32 AlphaBits = 8;
98 static_assert(
sizeof(
Color) ==
sizeof(u32));
100 constexpr Color TransparentColor = { .clr = { .r = 0, .g = 0, .b = 0, .a = 0 } };
101 constexpr Color BlackColor = { .clr = { .r = 0, .g = 0, .b = 0, .a = 0xff } };
118 static constexpr u32 RedShift = 0;
119 static constexpr u32 RedBits = 5;
121 static constexpr u32 GreenShift = 5;
122 static constexpr u32 GreenBits = 5;
124 static constexpr u32 BlueShift = 10;
125 static constexpr u32 BlueBits = 5;
127 static constexpr u32 AlphaShift = 0;
128 static constexpr u32 AlphaBits = 0;
130 static_assert(
sizeof(
Color) ==
sizeof(u16));
147 static constexpr u32 RedShift = 0;
148 static constexpr u32 RedBits = 5;
150 static constexpr u32 GreenShift = 5;
151 static constexpr u32 GreenBits = 5;
153 static constexpr u32 BlueShift = 10;
154 static constexpr u32 BlueBits = 5;
156 static constexpr u32 AlphaShift = 15;
157 static constexpr u32 AlphaBits = 1;
159 static_assert(
sizeof(
Color) ==
sizeof(u16));
163 template<
typename C1,
typename C2>
164 inline constexpr C2 ConvertColor(
const C1 clr) {
165 if constexpr(std::is_same_v<C1, C2>) {
169 constexpr auto c1_r_mask = ~(UINT32_MAX << C1::RedBits);
170 constexpr auto c2_r_mask = ~(UINT32_MAX << C2::RedBits);
171 const auto r = ((((clr.raw_val >> C1::RedShift) & c1_r_mask) * 0xff) + c1_r_mask / 2) / c1_r_mask;
172 const decltype(C2::raw_val) r_cmp =
static_cast<decltype(C2::raw_val)
>(((r * c2_r_mask + 0x7f) / 0xff) << C2::RedShift);
174 constexpr auto c1_g_mask = ~(UINT32_MAX << C1::GreenBits);
175 constexpr auto c2_g_mask = ~(UINT32_MAX << C2::GreenBits);
176 const auto g = ((((clr.raw_val >> C1::GreenShift) & c1_g_mask) * 0xff) + c1_g_mask / 2) / c1_g_mask;
177 const decltype(C2::raw_val) g_cmp =
static_cast<decltype(C2::raw_val)
>(((g * c2_g_mask + 0x7f) / 0xff) << C2::GreenShift);
179 constexpr auto c1_b_mask = ~(UINT32_MAX << C1::BlueBits);
180 constexpr auto c2_b_mask = ~(UINT32_MAX << C2::BlueBits);
181 const auto b = ((((clr.raw_val >> C1::BlueShift) & c1_b_mask) * 0xff) + c1_b_mask / 2) / c1_b_mask;
182 const decltype(C2::raw_val) b_cmp =
static_cast<decltype(C2::raw_val)
>(((b * c2_b_mask + 0x7f) / 0xff) << C2::BlueShift);
184 if constexpr((C1::AlphaBits > 0) && (C2::AlphaBits > 0)) {
185 constexpr auto c1_a_mask = ~(UINT32_MAX << C1::AlphaBits);
186 constexpr auto c2_a_mask = ~(UINT32_MAX << C2::AlphaBits);
187 const auto a = ((((clr.raw_val >> C1::AlphaShift) & c1_a_mask) * 0xff) + c1_a_mask / 2) / c1_a_mask;
188 const decltype(C2::raw_val) a_cmp =
static_cast<decltype(C2::raw_val)
>(((a * c2_a_mask + 0x7f) / 0xff) << C2::AlphaShift);
191 .raw_val =
static_cast<decltype(C2::raw_val)
>(r_cmp | g_cmp | b_cmp | a_cmp)
194 else if constexpr(C1::AlphaBits <= 0) {
195 constexpr auto c2_a_mask = ~(UINT32_MAX << C2::AlphaBits);
197 const decltype(C2::raw_val) a_cmp =
static_cast<decltype(C2::raw_val)
>(((a * c2_a_mask + 0x7f) / 0xff) << C2::AlphaShift);
200 .raw_val =
static_cast<decltype(C2::raw_val)
>(r_cmp | g_cmp | b_cmp | a_cmp)
203 else if constexpr(C2::AlphaBits <= 0) {
205 .raw_val =
static_cast<decltype(C2::raw_val)
>(r_cmp | g_cmp | b_cmp)
210 constexpr size_t TileSize = 8;
Definition gfx_Base.hpp:61
Definition gfx_Base.hpp:136
Definition gfx_Base.hpp:75
Definition gfx_Base.hpp:107