Skip to content

Commit

Permalink
Toggle between old and new colorimetries
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumball2415 committed Feb 26, 2022
1 parent 3655def commit 5890ad3
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 17 deletions.
20 changes: 10 additions & 10 deletions Core/BisqwitNtscFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#include "EmulationSettings.h"
#include "Console.h"

BisqwitNtscFilter::BisqwitNtscFilter(shared_ptr<Console> console, int resDivider) : BaseVideoFilter(console)
BisqwitNtscFilter::BisqwitNtscFilter(shared_ptr<Console> console, int resDivider, bool SMPTE_C) : BaseVideoFilter(console)
{
_resDivider = resDivider;
_stopThread = false;
_workDone = false;
_SMPTE_C = SMPTE_C;

const int8_t signalLumaLow[4] = { -29, -15, 22, 71 };
const int8_t signalLumaHigh[4] = { 32, 66, 105, 105 };
Expand Down Expand Up @@ -49,7 +50,7 @@ BisqwitNtscFilter::BisqwitNtscFilter(shared_ptr<Console> console, int resDivider
outputBuffer += GetOverscan().GetScreenWidth() * 64 / _resDivider / _resDivider * (120 - GetOverscan().Top);
}

DecodeFrame(120, 239 - GetOverscan().Bottom, _ppuOutputBuffer, outputBuffer, (IsOddFrame() ? 8 : 0) + 327360);
DecodeFrame(120, 239 - GetOverscan().Bottom, _ppuOutputBuffer, outputBuffer, (IsOddFrame() ? 8 : 0) + 327360, SMPTE_C);

_workDone = true;
}
Expand All @@ -69,7 +70,7 @@ void BisqwitNtscFilter::ApplyFilter(uint16_t *ppuOutputBuffer)

_workDone = false;
_waitWork.Signal();
DecodeFrame(GetOverscan().Top, 120, ppuOutputBuffer, GetOutputBuffer(), (IsOddFrame() ? 8 : 0) + GetOverscan().Top*341*8);
DecodeFrame(GetOverscan().Top, 120, ppuOutputBuffer, GetOutputBuffer(), (IsOddFrame() ? 8 : 0) + GetOverscan().Top*341*8, _SMPTE_C);
while(!_workDone) {}
}

Expand All @@ -89,7 +90,6 @@ void BisqwitNtscFilter::OnBeforeApplyFilter()
NtscFilterSettings ntscSettings = _console->GetSettings()->GetNtscFilterSettings();

_keepVerticalRes = ntscSettings.KeepVerticalResolution;
//_SMPTE_C = ntscSettings.NtscSmpteC;

const double pi = std::atan(1.0) * 4;
int contrast = (int)((pictureSettings.Contrast + 1.0) * (pictureSettings.Contrast + 1.0) * 167941);
Expand Down Expand Up @@ -209,7 +209,7 @@ void BisqwitNtscFilter::GenerateNtscSignal(int8_t *ntscSignal, int &phase, int r
phase += (341 - 256 - _paddingSize * 2) * _signalsPerPixel;
}

void BisqwitNtscFilter::DecodeFrame(int startRow, int endRow, uint16_t *ppuOutputBuffer, uint32_t* outputBuffer, int startPhase)
void BisqwitNtscFilter::DecodeFrame(int startRow, int endRow, uint16_t *ppuOutputBuffer, uint32_t* outputBuffer, int startPhase, bool SMPTE_C)
{
int pixelsPerCycle = 8 / _resDivider;
int phase = startPhase;
Expand All @@ -229,7 +229,7 @@ void BisqwitNtscFilter::DecodeFrame(int startRow, int endRow, uint16_t *ppuOutpu
GenerateNtscSignal(rowSignal, phase, y);

//Convert the NTSC signal to RGB
NtscDecodeLine(lineWidth * _signalsPerPixel, rowSignal, outputBuffer, (startCycle + 7) % 12);
NtscDecodeLine(lineWidth * _signalsPerPixel, rowSignal, outputBuffer, (startCycle + 7) % 12, SMPTE_C);

outputBuffer += rowPixelGap;
}
Expand Down Expand Up @@ -281,7 +281,7 @@ void BisqwitNtscFilter::DecodeFrame(int startRow, int endRow, uint16_t *ppuOutpu
* In essence it conveys in one integer the same information that real NTSC signal
* would convey in the colorburst period in the beginning of each scanline.
*/
void BisqwitNtscFilter::NtscDecodeLine(int width, const int8_t* signal, uint32_t* target, int phase0)
void BisqwitNtscFilter::NtscDecodeLine(int width, const int8_t* signal, uint32_t* target, int phase0, bool SMPTE_C)
{
auto Read = [=](int pos) -> char { return pos >= 0 ? signal[pos] : 0; };
auto Cos = [=](int pos) -> char { return _sinetable[(pos + 36) % 12 + phase0]; };
Expand All @@ -299,9 +299,9 @@ void BisqwitNtscFilter::NtscDecodeLine(int width, const int8_t* signal, uint32_t
qsum += Read(s) * Sin(s) - Read(s - _qWidth) * Sin(s - _qWidth);

if(!(s % _resDivider) && s >= leftOverscan) {
int r = std::min(255, std::max(0, (ysum*_y + isum*_irC + qsum*_qrC) / 65536));
int g = std::min(255, std::max(0, (ysum*_y + isum*_igC + qsum*_qgC) / 65536));
int b = std::min(255, std::max(0, (ysum*_y + isum*_ibC + qsum*_qbC) / 65536));
int r = std::min(255, std::max(0, (ysum*_y + isum*(SMPTE_C ? _irC : _ir) + qsum*(SMPTE_C ? _qrC : _qr)) / 65536));
int g = std::min(255, std::max(0, (ysum*_y + isum*(SMPTE_C ? _igC : _ig) + qsum*(SMPTE_C ? _qgC : _qg)) / 65536));
int b = std::min(255, std::max(0, (ysum*_y + isum*(SMPTE_C ? _ibC : _ib) + qsum*(SMPTE_C ? _qbC : _qb)) / 65536));

*target = 0xFF000000 | (r << 16) | (g << 8) | b;
target++;
Expand Down
6 changes: 3 additions & 3 deletions Core/BisqwitNtscFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class BisqwitNtscFilter : public BaseVideoFilter

void RecursiveBlend(int iterationCount, uint64_t *output, uint64_t *currentLine, uint64_t *nextLine, int pixelsPerCycle, bool verticalBlend);

void NtscDecodeLine(int width, const int8_t* signal, uint32_t* target, int phase0);
void NtscDecodeLine(int width, const int8_t* signal, uint32_t* target, int phase0, bool SMPTE_C);

void GenerateNtscSignal(int8_t *ntscSignal, int &phase, int rowNumber);
void DecodeFrame(int startRow, int endRow, uint16_t *ppuOutputBuffer, uint32_t* outputBuffer, int startPhase);
void DecodeFrame(int startRow, int endRow, uint16_t *ppuOutputBuffer, uint32_t* outputBuffer, int startPhase, bool SMPTE_C);
void OnBeforeApplyFilter();

public:
BisqwitNtscFilter(shared_ptr<Console> console, int resDivider);
BisqwitNtscFilter(shared_ptr<Console> console, int resDivider, bool SMPTE_C);
virtual ~BisqwitNtscFilter();

virtual void ApplyFilter(uint16_t *ppuOutputBuffer);
Expand Down
3 changes: 3 additions & 0 deletions Core/EmulationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ enum class VideoFilterType
Prescale8x = 23,
Prescale10x = 24,
Raw = 25,
BisqwitNtscSMPTECQuarterRes = 26,
BisqwitNtscSMPTECHalfRes = 27,
BisqwitNtscSMPTEC = 28,
HdPack = 999
};

Expand Down
3 changes: 3 additions & 0 deletions Core/ScaleFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ shared_ptr<ScaleFilter> ScaleFilter::GetScaleFilter(VideoFilterType filter)
case VideoFilterType::BisqwitNtsc:
case VideoFilterType::BisqwitNtscHalfRes:
case VideoFilterType::BisqwitNtscQuarterRes:
case VideoFilterType::BisqwitNtscSMPTEC:
case VideoFilterType::BisqwitNtscSMPTECHalfRes:
case VideoFilterType::BisqwitNtscSMPTECQuarterRes:
case VideoFilterType::NTSC:
case VideoFilterType::HdPack:
case VideoFilterType::Raw:
Expand Down
9 changes: 6 additions & 3 deletions Core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ void VideoDecoder::UpdateVideoFilter()
switch(_videoFilterType) {
case VideoFilterType::None: break;
case VideoFilterType::NTSC: _videoFilter.reset(new NtscFilter(_console)); break;
case VideoFilterType::BisqwitNtsc: _videoFilter.reset(new BisqwitNtscFilter(_console, 1)); break;
case VideoFilterType::BisqwitNtscHalfRes: _videoFilter.reset(new BisqwitNtscFilter(_console, 2)); break;
case VideoFilterType::BisqwitNtscQuarterRes: _videoFilter.reset(new BisqwitNtscFilter(_console, 4)); break;
case VideoFilterType::BisqwitNtsc: _videoFilter.reset(new BisqwitNtscFilter(_console, 1, false)); break;
case VideoFilterType::BisqwitNtscHalfRes: _videoFilter.reset(new BisqwitNtscFilter(_console, 2, false)); break;
case VideoFilterType::BisqwitNtscQuarterRes: _videoFilter.reset(new BisqwitNtscFilter(_console, 4, false)); break;
case VideoFilterType::BisqwitNtscSMPTEC: _videoFilter.reset(new BisqwitNtscFilter(_console, 1, true)); break;
case VideoFilterType::BisqwitNtscSMPTECHalfRes: _videoFilter.reset(new BisqwitNtscFilter(_console, 2, true)); break;
case VideoFilterType::BisqwitNtscSMPTECQuarterRes: _videoFilter.reset(new BisqwitNtscFilter(_console, 4, true)); break;
case VideoFilterType::Raw: _videoFilter.reset(new RawVideoFilter(_console)); break;
default: _scaleFilter = ScaleFilter::GetScaleFilter(_videoFilterType); break;
}
Expand Down
7 changes: 6 additions & 1 deletion GUI.NET/Forms/Config/frmVideoConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ protected override bool ValidateInput()
tlpNtscFilter2.Visible = false;
chkMergeFields.Visible = true;
grpNtscFilter.Visible = true;
} else if(filter == VideoFilterType.BisqwitNtsc || filter == VideoFilterType.BisqwitNtscHalfRes || filter == VideoFilterType.BisqwitNtscQuarterRes) {
} else if(filter == VideoFilterType.BisqwitNtsc ||
filter == VideoFilterType.BisqwitNtscHalfRes ||
filter == VideoFilterType.BisqwitNtscQuarterRes ||
filter == VideoFilterType.BisqwitNtscSMPTEC ||
filter == VideoFilterType.BisqwitNtscSMPTECHalfRes ||
filter == VideoFilterType.BisqwitNtscSMPTECQuarterRes) {
tlpNtscFilter1.Visible = true;
tlpNtscFilter2.Visible = true;
chkMergeFields.Visible = false;
Expand Down
30 changes: 30 additions & 0 deletions GUI.NET/Forms/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions GUI.NET/Forms/frmMain.Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ private void UpdateFilterMenu(VideoFilterType filterType)
mnuNtscBisqwitFullFilter.Checked = (filterType == VideoFilterType.BisqwitNtsc);
mnuNtscBisqwitHalfFilter.Checked = (filterType == VideoFilterType.BisqwitNtscHalfRes);
mnuNtscBisqwitQuarterFilter.Checked = (filterType == VideoFilterType.BisqwitNtscQuarterRes);
mnuNtscSMPTECBisqwitFullFilter.Checked = (filterType == VideoFilterType.BisqwitNtscSMPTEC);
mnuNtscSMPTECBisqwitHalfFilter.Checked = (filterType == VideoFilterType.BisqwitNtscSMPTECHalfRes);
mnuNtscSMPTECBisqwitQuarterFilter.Checked = (filterType == VideoFilterType.BisqwitNtscSMPTECQuarterRes);

mnuXBRZ2xFilter.Checked = (filterType == VideoFilterType.xBRZ2x);
mnuXBRZ3xFilter.Checked = (filterType == VideoFilterType.xBRZ3x);
Expand Down Expand Up @@ -370,5 +373,20 @@ private void mnuNtscBisqwitQuarterFilter_Click(object sender, EventArgs e)
{
SetVideoFilter(VideoFilterType.BisqwitNtscQuarterRes);
}

private void mnuNtscSMPTECBisqwitFullFilter_Click(object sender, EventArgs e)
{
SetVideoFilter(VideoFilterType.BisqwitNtscSMPTEC);
}

private void mnuNtscSMPTECBisqwitHalfFilter_Click(object sender, EventArgs e)
{
SetVideoFilter(VideoFilterType.BisqwitNtscSMPTECHalfRes);
}

private void mnuNtscSMPTECBisqwitQuarterFilter_Click(object sender, EventArgs e)
{
SetVideoFilter(VideoFilterType.BisqwitNtscSMPTECQuarterRes);
}
}
}
3 changes: 3 additions & 0 deletions GUI.NET/Forms/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,9 @@ private void UpdateMenus()
mnuNtscBisqwitQuarterFilter.Enabled = !isHdPackLoader;
mnuNtscBisqwitHalfFilter.Enabled = !isHdPackLoader;
mnuNtscBisqwitFullFilter.Enabled = !isHdPackLoader;
mnuNtscSMPTECBisqwitQuarterFilter.Enabled = !isHdPackLoader;
mnuNtscSMPTECBisqwitHalfFilter.Enabled = !isHdPackLoader;
mnuNtscSMPTECBisqwitFullFilter.Enabled = !isHdPackLoader;
}
} catch { }
}
Expand Down
3 changes: 3 additions & 0 deletions GUI.NET/InteropEmu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,9 @@ public enum VideoFilterType
Prescale6x = 22,
Prescale8x = 23,
Prescale10x = 24,
BisqwitNtscSMPTECQuarterRes = 26,
BisqwitNtscSMPTECHalfRes = 27,
BisqwitNtscSMPTEC = 28,
}

public enum HDPackOuputTileType
Expand Down

0 comments on commit 5890ad3

Please sign in to comment.