From b8624003f0a9952088a26a7744a88562140923ed Mon Sep 17 00:00:00 2001 From: Sour Date: Sat, 9 Mar 2019 00:08:08 -0500 Subject: [PATCH] Improved color output (white is output as white instead of a light shade of gray, etc.) --- Core/DefaultVideoFilter.cpp | 23 ++++++++++++++++------- Core/DefaultVideoFilter.h | 3 +++ Core/EventManager.cpp | 14 ++++++-------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Core/DefaultVideoFilter.cpp b/Core/DefaultVideoFilter.cpp index 2e108ea..f6dcbc1 100644 --- a/Core/DefaultVideoFilter.cpp +++ b/Core/DefaultVideoFilter.cpp @@ -90,19 +90,28 @@ void DefaultVideoFilter::DecodePpuBuffer(uint16_t *ppuOutputBuffer, uint32_t* ou }*/ } +uint8_t DefaultVideoFilter::To8Bit(uint8_t color) +{ + return (color << 3) + (color >> 2); +} + +uint32_t DefaultVideoFilter::ToArgb(uint16_t rgb555) +{ + uint8_t b = To8Bit(rgb555 >> 10); + uint8_t g = To8Bit((rgb555 >> 5) & 0x1F); + uint8_t r = To8Bit(rgb555 & 0x1F); + + return 0xFF000000 | (r << 16) | (g << 8) | b; +} + void DefaultVideoFilter::ApplyFilter(uint16_t *ppuOutputBuffer) { uint32_t *out = GetOutputBuffer(); uint32_t pixelCount = GetFrameInfo().Width * GetFrameInfo().Height; + for(uint32_t i = 0; i < pixelCount; i++) { - uint16_t rgb555 = ppuOutputBuffer[i]; - uint8_t b = (rgb555 >> 10) * 256 / 32; - uint8_t g = ((rgb555 >> 5) & 0x1F) * 256 / 32; - uint8_t r = (rgb555 & 0x1F) * 256 / 32; - - out[i] = 0xFF000000 | (r << 16) | (g << 8) | b; + out[i] = ToArgb(ppuOutputBuffer[i]); } - //DecodePpuBuffer(ppuOutputBuffer, GetOutputBuffer(), _console->GetSettings()->GetVideoFilterType() <= VideoFilterType::BisqwitNtsc); } void DefaultVideoFilter::RgbToYiq(double r, double g, double b, double &y, double &i, double &q) diff --git a/Core/DefaultVideoFilter.h b/Core/DefaultVideoFilter.h index 0bffdfa..5c4b8b9 100644 --- a/Core/DefaultVideoFilter.h +++ b/Core/DefaultVideoFilter.h @@ -15,6 +15,7 @@ private: void RgbToYiq(double r, double g, double b, double &y, double &i, double &q); void YiqToRgb(double y, double i, double q, double &r, double &g, double &b); + __forceinline static uint8_t To8Bit(uint8_t color); protected: void DecodePpuBuffer(uint16_t *ppuOutputBuffer, uint32_t* outputBuffer, bool displayScanlines); @@ -24,4 +25,6 @@ protected: public: DefaultVideoFilter(shared_ptr console); void ApplyFilter(uint16_t *ppuOutputBuffer); + + static uint32_t ToArgb(uint16_t rgb555); }; \ No newline at end of file diff --git a/Core/EventManager.cpp b/Core/EventManager.cpp index 975d81e..bff289a 100644 --- a/Core/EventManager.cpp +++ b/Core/EventManager.cpp @@ -5,6 +5,7 @@ #include "Ppu.h" #include "Debugger.h" #include "DebugBreakHelper.h" +#include "DefaultVideoFilter.h" EventManager::EventManager(Debugger *debugger, Cpu *cpu, Ppu *ppu) { @@ -164,12 +165,7 @@ void EventManager::GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions uint32_t pixelCount = 256*2*239*2; for(uint32_t y = 0, len = overscanMode ? 239*2 : 224*2; y < len; y++) { for(uint32_t x = 0; x < 512; x++) { - uint16_t rgb555 = ppuBuffer[(y << 9) | x]; - uint8_t b = (rgb555 >> 10) * 256 / 32; - uint8_t g = ((rgb555 >> 5) & 0x1F) * 256 / 32; - uint8_t r = (rgb555 & 0x1F) * 256 / 32; - - buffer[(y + 2)*340*2 + x + 22*2] = 0xFF000000 | (r << 16) | (g << 8) | b; + buffer[(y + 2)*340*2 + x + 22*2] = DefaultVideoFilter::ToArgb(ppuBuffer[(y << 9) | x]); } } @@ -180,8 +176,10 @@ void EventManager::GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions for(int i = 0; i < 340 * 2; i++) { buffer[nmiScanline + i] = nmiColor; buffer[nmiScanline + 340 * 2 + i] = nmiColor; - buffer[scanlineOffset + i] = currentScanlineColor; - buffer[scanlineOffset + 340 * 2 + i] = currentScanlineColor; + if(_snapshotScanline != 0) { + buffer[scanlineOffset + i] = currentScanlineColor; + buffer[scanlineOffset + 340 * 2 + i] = currentScanlineColor; + } } for(DebugEventInfo &evt : _snapshot) {