mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-10-30 11:47:51 +00:00
Merge pull request #5526 from FearlessTobi/port-4535-4548
Port yuzu-emu/yuzu#4535 and yuzu-emu/yuzu#4548: Changes to the Common namespace
This commit is contained in:
commit
d89a6d491e
7 changed files with 68 additions and 67 deletions
|
@ -315,31 +315,31 @@ void GraphicsSurfaceWidget::Pick(int x, int y) {
|
|||
auto GetText = [offset](Format format, const u8* pixel) {
|
||||
switch (format) {
|
||||
case Format::RGBA8: {
|
||||
auto value = Color::DecodeRGBA8(pixel) / 255.0f;
|
||||
auto value = Common::Color::DecodeRGBA8(pixel) / 255.0f;
|
||||
return QStringLiteral("Red: %1, Green: %2, Blue: %3, Alpha: %4")
|
||||
.arg(QString::number(value.r(), 'f', 2), QString::number(value.g(), 'f', 2),
|
||||
QString::number(value.b(), 'f', 2), QString::number(value.a(), 'f', 2));
|
||||
}
|
||||
case Format::RGB8: {
|
||||
auto value = Color::DecodeRGB8(pixel) / 255.0f;
|
||||
auto value = Common::Color::DecodeRGB8(pixel) / 255.0f;
|
||||
return QStringLiteral("Red: %1, Green: %2, Blue: %3")
|
||||
.arg(QString::number(value.r(), 'f', 2), QString::number(value.g(), 'f', 2),
|
||||
QString::number(value.b(), 'f', 2));
|
||||
}
|
||||
case Format::RGB5A1: {
|
||||
auto value = Color::DecodeRGB5A1(pixel) / 255.0f;
|
||||
auto value = Common::Color::DecodeRGB5A1(pixel) / 255.0f;
|
||||
return QStringLiteral("Red: %1, Green: %2, Blue: %3, Alpha: %4")
|
||||
.arg(QString::number(value.r(), 'f', 2), QString::number(value.g(), 'f', 2),
|
||||
QString::number(value.b(), 'f', 2), QString::number(value.a(), 'f', 2));
|
||||
}
|
||||
case Format::RGB565: {
|
||||
auto value = Color::DecodeRGB565(pixel) / 255.0f;
|
||||
auto value = Common::Color::DecodeRGB565(pixel) / 255.0f;
|
||||
return QStringLiteral("Red: %1, Green: %2, Blue: %3")
|
||||
.arg(QString::number(value.r(), 'f', 2), QString::number(value.g(), 'f', 2),
|
||||
QString::number(value.b(), 'f', 2));
|
||||
}
|
||||
case Format::RGBA4: {
|
||||
auto value = Color::DecodeRGBA4(pixel) / 255.0f;
|
||||
auto value = Common::Color::DecodeRGBA4(pixel) / 255.0f;
|
||||
return QStringLiteral("Red: %1, Green: %2, Blue: %3, Alpha: %4")
|
||||
.arg(QString::number(value.r(), 'f', 2), QString::number(value.g(), 'f', 2),
|
||||
QString::number(value.b(), 'f', 2), QString::number(value.a(), 'f', 2));
|
||||
|
@ -347,7 +347,7 @@ void GraphicsSurfaceWidget::Pick(int x, int y) {
|
|||
case Format::IA8:
|
||||
return QStringLiteral("Index: %1, Alpha: %2").arg(pixel[0], pixel[1]);
|
||||
case Format::RG8: {
|
||||
auto value = Color::DecodeRG8(pixel) / 255.0f;
|
||||
auto value = Common::Color::DecodeRG8(pixel) / 255.0f;
|
||||
return QStringLiteral("Red: %1, Green: %2")
|
||||
.arg(QString::number(value.r(), 'f', 2), QString::number(value.g(), 'f', 2));
|
||||
}
|
||||
|
@ -370,17 +370,17 @@ void GraphicsSurfaceWidget::Pick(int x, int y) {
|
|||
// TODO: Display block information or channel values?
|
||||
return QStringLiteral("Compressed data");
|
||||
case Format::D16: {
|
||||
auto value = Color::DecodeD16(pixel);
|
||||
auto value = Common::Color::DecodeD16(pixel);
|
||||
return QStringLiteral("Depth: %1").arg(QString::number(value / (float)0xFFFF, 'f', 4));
|
||||
}
|
||||
case Format::D24: {
|
||||
auto value = Color::DecodeD24(pixel);
|
||||
auto value = Common::Color::DecodeD24(pixel);
|
||||
return QStringLiteral("Depth: %1")
|
||||
.arg(QString::number(value / (float)0xFFFFFF, 'f', 4));
|
||||
}
|
||||
case Format::D24X8:
|
||||
case Format::X24S8: {
|
||||
auto values = Color::DecodeD24S8(pixel);
|
||||
auto values = Common::Color::DecodeD24S8(pixel);
|
||||
return QStringLiteral("Depth: %1, Stencil: %2")
|
||||
.arg(QString::number(values[0] / (float)0xFFFFFF, 'f', 4), values[1]);
|
||||
}
|
||||
|
@ -604,27 +604,27 @@ void GraphicsSurfaceWidget::OnUpdate() {
|
|||
|
||||
switch (surface_format) {
|
||||
case Format::D16: {
|
||||
u32 data = Color::DecodeD16(pixel);
|
||||
u32 data = Common::Color::DecodeD16(pixel);
|
||||
color.r() = data & 0xFF;
|
||||
color.g() = (data >> 8) & 0xFF;
|
||||
break;
|
||||
}
|
||||
case Format::D24: {
|
||||
u32 data = Color::DecodeD24(pixel);
|
||||
u32 data = Common::Color::DecodeD24(pixel);
|
||||
color.r() = data & 0xFF;
|
||||
color.g() = (data >> 8) & 0xFF;
|
||||
color.b() = (data >> 16) & 0xFF;
|
||||
break;
|
||||
}
|
||||
case Format::D24X8: {
|
||||
Common::Vec2<u32> data = Color::DecodeD24S8(pixel);
|
||||
Common::Vec2<u32> data = Common::Color::DecodeD24S8(pixel);
|
||||
color.r() = data.x & 0xFF;
|
||||
color.g() = (data.x >> 8) & 0xFF;
|
||||
color.b() = (data.x >> 16) & 0xFF;
|
||||
break;
|
||||
}
|
||||
case Format::X24S8: {
|
||||
Common::Vec2<u32> data = Color::DecodeD24S8(pixel);
|
||||
Common::Vec2<u32> data = Common::Color::DecodeD24S8(pixel);
|
||||
color.r() = color.g() = color.b() = data.y;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "common/swap.h"
|
||||
#include "common/vector_math.h"
|
||||
|
||||
namespace Color {
|
||||
namespace Common::Color {
|
||||
|
||||
/// Convert a 1-bit color component to 8 bit
|
||||
[[nodiscard]] constexpr u8 Convert1To8(u8 value) {
|
||||
|
@ -268,4 +268,4 @@ inline void EncodeX24S8(u8 stencil, u8* bytes) {
|
|||
bytes[3] = stencil;
|
||||
}
|
||||
|
||||
} // namespace Color
|
||||
} // namespace Common::Color
|
||||
|
|
|
@ -50,19 +50,19 @@ inline void Read(T& var, const u32 raw_addr) {
|
|||
static Common::Vec4<u8> DecodePixel(Regs::PixelFormat input_format, const u8* src_pixel) {
|
||||
switch (input_format) {
|
||||
case Regs::PixelFormat::RGBA8:
|
||||
return Color::DecodeRGBA8(src_pixel);
|
||||
return Common::Color::DecodeRGBA8(src_pixel);
|
||||
|
||||
case Regs::PixelFormat::RGB8:
|
||||
return Color::DecodeRGB8(src_pixel);
|
||||
return Common::Color::DecodeRGB8(src_pixel);
|
||||
|
||||
case Regs::PixelFormat::RGB565:
|
||||
return Color::DecodeRGB565(src_pixel);
|
||||
return Common::Color::DecodeRGB565(src_pixel);
|
||||
|
||||
case Regs::PixelFormat::RGB5A1:
|
||||
return Color::DecodeRGB5A1(src_pixel);
|
||||
return Common::Color::DecodeRGB5A1(src_pixel);
|
||||
|
||||
case Regs::PixelFormat::RGBA4:
|
||||
return Color::DecodeRGBA4(src_pixel);
|
||||
return Common::Color::DecodeRGBA4(src_pixel);
|
||||
|
||||
default:
|
||||
LOG_ERROR(HW_GPU, "Unknown source framebuffer format {:x}", input_format);
|
||||
|
@ -274,23 +274,23 @@ static void DisplayTransfer(const Regs::DisplayTransferConfig& config) {
|
|||
u8* dst_pixel = dst_pointer + dst_offset;
|
||||
switch (config.output_format) {
|
||||
case Regs::PixelFormat::RGBA8:
|
||||
Color::EncodeRGBA8(src_color, dst_pixel);
|
||||
Common::Color::EncodeRGBA8(src_color, dst_pixel);
|
||||
break;
|
||||
|
||||
case Regs::PixelFormat::RGB8:
|
||||
Color::EncodeRGB8(src_color, dst_pixel);
|
||||
Common::Color::EncodeRGB8(src_color, dst_pixel);
|
||||
break;
|
||||
|
||||
case Regs::PixelFormat::RGB565:
|
||||
Color::EncodeRGB565(src_color, dst_pixel);
|
||||
Common::Color::EncodeRGB565(src_color, dst_pixel);
|
||||
break;
|
||||
|
||||
case Regs::PixelFormat::RGB5A1:
|
||||
Color::EncodeRGB5A1(src_color, dst_pixel);
|
||||
Common::Color::EncodeRGB5A1(src_color, dst_pixel);
|
||||
break;
|
||||
|
||||
case Regs::PixelFormat::RGBA4:
|
||||
Color::EncodeRGBA4(src_color, dst_pixel);
|
||||
Common::Color::EncodeRGBA4(src_color, dst_pixel);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -115,19 +115,19 @@ static void SendData(Memory::MemorySystem& memory, const u32* input, ConversionB
|
|||
|
||||
switch (output_format) {
|
||||
case OutputFormat::RGBA8:
|
||||
Color::EncodeRGBA8(col_vec, output);
|
||||
Common::Color::EncodeRGBA8(col_vec, output);
|
||||
output += 4;
|
||||
break;
|
||||
case OutputFormat::RGB8:
|
||||
Color::EncodeRGB8(col_vec, output);
|
||||
Common::Color::EncodeRGB8(col_vec, output);
|
||||
output += 3;
|
||||
break;
|
||||
case OutputFormat::RGB5A1:
|
||||
Color::EncodeRGB5A1(col_vec, output);
|
||||
Common::Color::EncodeRGB5A1(col_vec, output);
|
||||
output += 2;
|
||||
break;
|
||||
case OutputFormat::RGB565:
|
||||
Color::EncodeRGB565(col_vec, output);
|
||||
Common::Color::EncodeRGB565(col_vec, output);
|
||||
output += 2;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -35,23 +35,23 @@ void DrawPixel(int x, int y, const Common::Vec4<u8>& color) {
|
|||
|
||||
switch (framebuffer.color_format) {
|
||||
case FramebufferRegs::ColorFormat::RGBA8:
|
||||
Color::EncodeRGBA8(color, dst_pixel);
|
||||
Common::Color::EncodeRGBA8(color, dst_pixel);
|
||||
break;
|
||||
|
||||
case FramebufferRegs::ColorFormat::RGB8:
|
||||
Color::EncodeRGB8(color, dst_pixel);
|
||||
Common::Color::EncodeRGB8(color, dst_pixel);
|
||||
break;
|
||||
|
||||
case FramebufferRegs::ColorFormat::RGB5A1:
|
||||
Color::EncodeRGB5A1(color, dst_pixel);
|
||||
Common::Color::EncodeRGB5A1(color, dst_pixel);
|
||||
break;
|
||||
|
||||
case FramebufferRegs::ColorFormat::RGB565:
|
||||
Color::EncodeRGB565(color, dst_pixel);
|
||||
Common::Color::EncodeRGB565(color, dst_pixel);
|
||||
break;
|
||||
|
||||
case FramebufferRegs::ColorFormat::RGBA4:
|
||||
Color::EncodeRGBA4(color, dst_pixel);
|
||||
Common::Color::EncodeRGBA4(color, dst_pixel);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -76,19 +76,19 @@ const Common::Vec4<u8> GetPixel(int x, int y) {
|
|||
|
||||
switch (framebuffer.color_format) {
|
||||
case FramebufferRegs::ColorFormat::RGBA8:
|
||||
return Color::DecodeRGBA8(src_pixel);
|
||||
return Common::Color::DecodeRGBA8(src_pixel);
|
||||
|
||||
case FramebufferRegs::ColorFormat::RGB8:
|
||||
return Color::DecodeRGB8(src_pixel);
|
||||
return Common::Color::DecodeRGB8(src_pixel);
|
||||
|
||||
case FramebufferRegs::ColorFormat::RGB5A1:
|
||||
return Color::DecodeRGB5A1(src_pixel);
|
||||
return Common::Color::DecodeRGB5A1(src_pixel);
|
||||
|
||||
case FramebufferRegs::ColorFormat::RGB565:
|
||||
return Color::DecodeRGB565(src_pixel);
|
||||
return Common::Color::DecodeRGB565(src_pixel);
|
||||
|
||||
case FramebufferRegs::ColorFormat::RGBA4:
|
||||
return Color::DecodeRGBA4(src_pixel);
|
||||
return Common::Color::DecodeRGBA4(src_pixel);
|
||||
|
||||
default:
|
||||
LOG_CRITICAL(Render_Software, "Unknown framebuffer color format {:x}",
|
||||
|
@ -115,11 +115,11 @@ u32 GetDepth(int x, int y) {
|
|||
|
||||
switch (framebuffer.depth_format) {
|
||||
case FramebufferRegs::DepthFormat::D16:
|
||||
return Color::DecodeD16(src_pixel);
|
||||
return Common::Color::DecodeD16(src_pixel);
|
||||
case FramebufferRegs::DepthFormat::D24:
|
||||
return Color::DecodeD24(src_pixel);
|
||||
return Common::Color::DecodeD24(src_pixel);
|
||||
case FramebufferRegs::DepthFormat::D24S8:
|
||||
return Color::DecodeD24S8(src_pixel).x;
|
||||
return Common::Color::DecodeD24S8(src_pixel).x;
|
||||
default:
|
||||
LOG_CRITICAL(HW_GPU, "Unimplemented depth format {}",
|
||||
static_cast<u32>(framebuffer.depth_format.Value()));
|
||||
|
@ -144,7 +144,7 @@ u8 GetStencil(int x, int y) {
|
|||
|
||||
switch (framebuffer.depth_format) {
|
||||
case FramebufferRegs::DepthFormat::D24S8:
|
||||
return Color::DecodeD24S8(src_pixel).y;
|
||||
return Common::Color::DecodeD24S8(src_pixel).y;
|
||||
|
||||
default:
|
||||
LOG_WARNING(
|
||||
|
@ -171,15 +171,15 @@ void SetDepth(int x, int y, u32 value) {
|
|||
|
||||
switch (framebuffer.depth_format) {
|
||||
case FramebufferRegs::DepthFormat::D16:
|
||||
Color::EncodeD16(value, dst_pixel);
|
||||
Common::Color::EncodeD16(value, dst_pixel);
|
||||
break;
|
||||
|
||||
case FramebufferRegs::DepthFormat::D24:
|
||||
Color::EncodeD24(value, dst_pixel);
|
||||
Common::Color::EncodeD24(value, dst_pixel);
|
||||
break;
|
||||
|
||||
case FramebufferRegs::DepthFormat::D24S8:
|
||||
Color::EncodeD24X8(value, dst_pixel);
|
||||
Common::Color::EncodeD24X8(value, dst_pixel);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -211,7 +211,7 @@ void SetStencil(int x, int y, u8 value) {
|
|||
break;
|
||||
|
||||
case Pica::FramebufferRegs::DepthFormat::D24S8:
|
||||
Color::EncodeX24S8(value, dst_pixel);
|
||||
Common::Color::EncodeX24S8(value, dst_pixel);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -86,18 +86,18 @@ union ETC1Tile {
|
|||
ret.g() += static_cast<int>(differential.dg);
|
||||
ret.b() += static_cast<int>(differential.db);
|
||||
}
|
||||
ret.r() = Color::Convert5To8(ret.r());
|
||||
ret.g() = Color::Convert5To8(ret.g());
|
||||
ret.b() = Color::Convert5To8(ret.b());
|
||||
ret.r() = Common::Color::Convert5To8(ret.r());
|
||||
ret.g() = Common::Color::Convert5To8(ret.g());
|
||||
ret.b() = Common::Color::Convert5To8(ret.b());
|
||||
} else {
|
||||
if (x < 2) {
|
||||
ret.r() = Color::Convert4To8(static_cast<u8>(separate.r1));
|
||||
ret.g() = Color::Convert4To8(static_cast<u8>(separate.g1));
|
||||
ret.b() = Color::Convert4To8(static_cast<u8>(separate.b1));
|
||||
ret.r() = Common::Color::Convert4To8(static_cast<u8>(separate.r1));
|
||||
ret.g() = Common::Color::Convert4To8(static_cast<u8>(separate.g1));
|
||||
ret.b() = Common::Color::Convert4To8(static_cast<u8>(separate.b1));
|
||||
} else {
|
||||
ret.r() = Color::Convert4To8(static_cast<u8>(separate.r2));
|
||||
ret.g() = Color::Convert4To8(static_cast<u8>(separate.g2));
|
||||
ret.b() = Color::Convert4To8(static_cast<u8>(separate.b2));
|
||||
ret.r() = Common::Color::Convert4To8(static_cast<u8>(separate.r2));
|
||||
ret.g() = Common::Color::Convert4To8(static_cast<u8>(separate.g2));
|
||||
ret.b() = Common::Color::Convert4To8(static_cast<u8>(separate.b2));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,27 +80,27 @@ Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned in
|
|||
|
||||
switch (info.format) {
|
||||
case TextureFormat::RGBA8: {
|
||||
auto res = Color::DecodeRGBA8(source + MortonInterleave(x, y) * 4);
|
||||
auto res = Common::Color::DecodeRGBA8(source + MortonInterleave(x, y) * 4);
|
||||
return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())};
|
||||
}
|
||||
|
||||
case TextureFormat::RGB8: {
|
||||
auto res = Color::DecodeRGB8(source + MortonInterleave(x, y) * 3);
|
||||
auto res = Common::Color::DecodeRGB8(source + MortonInterleave(x, y) * 3);
|
||||
return {res.r(), res.g(), res.b(), 255};
|
||||
}
|
||||
|
||||
case TextureFormat::RGB5A1: {
|
||||
auto res = Color::DecodeRGB5A1(source + MortonInterleave(x, y) * 2);
|
||||
auto res = Common::Color::DecodeRGB5A1(source + MortonInterleave(x, y) * 2);
|
||||
return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())};
|
||||
}
|
||||
|
||||
case TextureFormat::RGB565: {
|
||||
auto res = Color::DecodeRGB565(source + MortonInterleave(x, y) * 2);
|
||||
auto res = Common::Color::DecodeRGB565(source + MortonInterleave(x, y) * 2);
|
||||
return {res.r(), res.g(), res.b(), 255};
|
||||
}
|
||||
|
||||
case TextureFormat::RGBA4: {
|
||||
auto res = Color::DecodeRGBA4(source + MortonInterleave(x, y) * 2);
|
||||
auto res = Common::Color::DecodeRGBA4(source + MortonInterleave(x, y) * 2);
|
||||
return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())};
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned in
|
|||
}
|
||||
|
||||
case TextureFormat::RG8: {
|
||||
auto res = Color::DecodeRG8(source + MortonInterleave(x, y) * 2);
|
||||
auto res = Common::Color::DecodeRG8(source + MortonInterleave(x, y) * 2);
|
||||
return {res.r(), res.g(), 0, 255};
|
||||
}
|
||||
|
||||
|
@ -138,8 +138,8 @@ Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned in
|
|||
case TextureFormat::IA4: {
|
||||
const u8* source_ptr = source + MortonInterleave(x, y);
|
||||
|
||||
u8 i = Color::Convert4To8(((*source_ptr) & 0xF0) >> 4);
|
||||
u8 a = Color::Convert4To8((*source_ptr) & 0xF);
|
||||
u8 i = Common::Color::Convert4To8(((*source_ptr) & 0xF0) >> 4);
|
||||
u8 a = Common::Color::Convert4To8((*source_ptr) & 0xF);
|
||||
|
||||
if (disable_alpha) {
|
||||
// Show intensity as red, alpha as green
|
||||
|
@ -154,7 +154,7 @@ Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned in
|
|||
const u8* source_ptr = source + morton_offset / 2;
|
||||
|
||||
u8 i = (morton_offset % 2) ? ((*source_ptr & 0xF0) >> 4) : (*source_ptr & 0xF);
|
||||
i = Color::Convert4To8(i);
|
||||
i = Common::Color::Convert4To8(i);
|
||||
|
||||
return {i, i, i, 255};
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned in
|
|||
const u8* source_ptr = source + morton_offset / 2;
|
||||
|
||||
u8 a = (morton_offset % 2) ? ((*source_ptr & 0xF0) >> 4) : (*source_ptr & 0xF);
|
||||
a = Color::Convert4To8(a);
|
||||
a = Common::Color::Convert4To8(a);
|
||||
|
||||
if (disable_alpha) {
|
||||
return {a, a, a, 255};
|
||||
|
@ -194,7 +194,8 @@ Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned in
|
|||
memcpy(&packed_alpha, subtile_ptr, sizeof(u64));
|
||||
subtile_ptr += sizeof(u64);
|
||||
|
||||
alpha = Color::Convert4To8((packed_alpha >> (4 * (x * subtile_width + y))) & 0xF);
|
||||
alpha =
|
||||
Common::Color::Convert4To8((packed_alpha >> (4 * (x * subtile_width + y))) & 0xF);
|
||||
}
|
||||
|
||||
u64_le subtile_data;
|
||||
|
|
Loading…
Reference in a new issue