Improved color output (white is output as white instead of a light shade of gray, etc.)

This commit is contained in:
Sour 2019-03-09 00:08:08 -05:00
parent af11e9fcef
commit b8624003f0
3 changed files with 25 additions and 15 deletions

View file

@ -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) void DefaultVideoFilter::ApplyFilter(uint16_t *ppuOutputBuffer)
{ {
uint32_t *out = GetOutputBuffer(); uint32_t *out = GetOutputBuffer();
uint32_t pixelCount = GetFrameInfo().Width * GetFrameInfo().Height; uint32_t pixelCount = GetFrameInfo().Width * GetFrameInfo().Height;
for(uint32_t i = 0; i < pixelCount; i++) { for(uint32_t i = 0; i < pixelCount; i++) {
uint16_t rgb555 = ppuOutputBuffer[i]; out[i] = ToArgb(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;
} }
//DecodePpuBuffer(ppuOutputBuffer, GetOutputBuffer(), _console->GetSettings()->GetVideoFilterType() <= VideoFilterType::BisqwitNtsc);
} }
void DefaultVideoFilter::RgbToYiq(double r, double g, double b, double &y, double &i, double &q) void DefaultVideoFilter::RgbToYiq(double r, double g, double b, double &y, double &i, double &q)

View file

@ -15,6 +15,7 @@ private:
void RgbToYiq(double r, double g, double b, double &y, double &i, double &q); 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); void YiqToRgb(double y, double i, double q, double &r, double &g, double &b);
__forceinline static uint8_t To8Bit(uint8_t color);
protected: protected:
void DecodePpuBuffer(uint16_t *ppuOutputBuffer, uint32_t* outputBuffer, bool displayScanlines); void DecodePpuBuffer(uint16_t *ppuOutputBuffer, uint32_t* outputBuffer, bool displayScanlines);
@ -24,4 +25,6 @@ protected:
public: public:
DefaultVideoFilter(shared_ptr<Console> console); DefaultVideoFilter(shared_ptr<Console> console);
void ApplyFilter(uint16_t *ppuOutputBuffer); void ApplyFilter(uint16_t *ppuOutputBuffer);
static uint32_t ToArgb(uint16_t rgb555);
}; };

View file

@ -5,6 +5,7 @@
#include "Ppu.h" #include "Ppu.h"
#include "Debugger.h" #include "Debugger.h"
#include "DebugBreakHelper.h" #include "DebugBreakHelper.h"
#include "DefaultVideoFilter.h"
EventManager::EventManager(Debugger *debugger, Cpu *cpu, Ppu *ppu) 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; uint32_t pixelCount = 256*2*239*2;
for(uint32_t y = 0, len = overscanMode ? 239*2 : 224*2; y < len; y++) { for(uint32_t y = 0, len = overscanMode ? 239*2 : 224*2; y < len; y++) {
for(uint32_t x = 0; x < 512; x++) { for(uint32_t x = 0; x < 512; x++) {
uint16_t rgb555 = ppuBuffer[(y << 9) | x]; buffer[(y + 2)*340*2 + x + 22*2] = DefaultVideoFilter::ToArgb(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;
} }
} }
@ -180,8 +176,10 @@ void EventManager::GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions
for(int i = 0; i < 340 * 2; i++) { for(int i = 0; i < 340 * 2; i++) {
buffer[nmiScanline + i] = nmiColor; buffer[nmiScanline + i] = nmiColor;
buffer[nmiScanline + 340 * 2 + i] = nmiColor; buffer[nmiScanline + 340 * 2 + i] = nmiColor;
buffer[scanlineOffset + i] = currentScanlineColor; if(_snapshotScanline != 0) {
buffer[scanlineOffset + 340 * 2 + i] = currentScanlineColor; buffer[scanlineOffset + i] = currentScanlineColor;
buffer[scanlineOffset + 340 * 2 + i] = currentScanlineColor;
}
} }
for(DebugEventInfo &evt : _snapshot) { for(DebugEventInfo &evt : _snapshot) {