From 0a43f69e8714ce38c3ce54c5d174c10ecb2811c7 Mon Sep 17 00:00:00 2001 From: Eladash Date: Mon, 19 Jun 2023 22:49:40 +0300 Subject: [PATCH] Utilities/Memory Viewer: Add G8 and G32MAX image formats --- rpcs3/rpcs3qt/memory_viewer_panel.cpp | 45 ++++++++++++++++++++++++++- rpcs3/rpcs3qt/memory_viewer_panel.h | 4 ++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/rpcs3/rpcs3qt/memory_viewer_panel.cpp b/rpcs3/rpcs3qt/memory_viewer_panel.cpp index 143d125271..e25b2d745f 100644 --- a/rpcs3/rpcs3qt/memory_viewer_panel.cpp +++ b/rpcs3/rpcs3qt/memory_viewer_panel.cpp @@ -185,6 +185,8 @@ memory_viewer_panel::memory_viewer_panel(QWidget* parent, std::shared_ptraddItem("ARGB", QVariant::fromValue(color_format::ARGB)); cbox_img_mode->addItem("RGBA", QVariant::fromValue(color_format::RGBA)); cbox_img_mode->addItem("ABGR", QVariant::fromValue(color_format::ABGR)); + cbox_img_mode->addItem("G8", QVariant::fromValue(color_format::G8)); + cbox_img_mode->addItem("G32MAX", QVariant::fromValue(color_format::G32MAX)); cbox_img_mode->setCurrentIndex(1); //ARGB hbox_tools_img_mode->addWidget(cbox_img_mode); tools_img_mode->setLayout(hbox_tools_img_mode); @@ -946,7 +948,7 @@ void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, color_format form return; } - const auto convertedBuffer = new (std::nothrow) u8[memsize]; + const auto convertedBuffer = new (std::nothrow) u8[memsize / texel_bytes * u64{4}]; if (!convertedBuffer) { @@ -1022,6 +1024,47 @@ void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, color_format form } break; } + case color_format::G8: + { + const u32 pitch = width * 1; + const u32 pitch_new = width * 4; + for (u32 y = 0; y < height; y++) + { + const u32 offset = y * pitch; + const u32 offset_new = y * pitch_new; + for (u32 x = 0; x < pitch; x++) + { + const u8 color = originalBuffer[offset + x]; + convertedBuffer[offset_new + x * 4 + 0] = color; + convertedBuffer[offset_new + x * 4 + 1] = color; + convertedBuffer[offset_new + x * 4 + 2] = color; + convertedBuffer[offset_new + x * 4 + 3] = 255; + } + } + break; + } + case color_format::G32MAX: + { + // Special: whitens as 4-byte groups tend to have a higher value, in order to perceive memory contents + // May be used to search for instructions or floats for example + + const u32 pitch = width * 4; + + for (u32 y = 0; y < height; y++) + { + const u32 offset = y * pitch; + for (u32 x = 0; x < pitch; x += 4) + { + const u8 color = std::max({originalBuffer[offset + x + 0], originalBuffer[offset + x + 1], originalBuffer[offset + x + 2], originalBuffer[offset + x + 3]}); + convertedBuffer[offset + x + 0] = color; + convertedBuffer[offset + x + 1] = color; + convertedBuffer[offset + x + 2] = color; + convertedBuffer[offset + x + 3] = 255; + } + } + + break; + } } // Flip vertically diff --git a/rpcs3/rpcs3qt/memory_viewer_panel.h b/rpcs3/rpcs3qt/memory_viewer_panel.h index b8f4e88d69..4398c77dc9 100644 --- a/rpcs3/rpcs3qt/memory_viewer_panel.h +++ b/rpcs3/rpcs3qt/memory_viewer_panel.h @@ -57,7 +57,9 @@ public: RGB, ARGB, RGBA, - ABGR + ABGR, + G8, + G32MAX }; Q_ENUM(color_format)