Video: Fixed/changed some aspect ratio calculations

-Fixed calculation for width for NTSC/PAL
-NTSC/PAL are PAR, as before, but 4:3/16:9 are now DAR instead, since their purpose is to fill the user's screen, regardless of overscan settings
This commit is contained in:
Sour 2020-04-29 20:24:21 -04:00
parent 5ff456bc09
commit 5daa1b6225
7 changed files with 94 additions and 129 deletions

View file

@ -109,27 +109,12 @@ void BaseVideoFilter::TakeScreenshot(VideoFilterType filterType, string filename
pngBuffer = frameBuffer;
//TODO
/*
uint32_t rotationAngle = _console->GetSettings()->GetScreenRotation();
shared_ptr<RotateFilter> rotateFilter;
if(rotationAngle > 0) {
rotateFilter.reset(new RotateFilter(rotationAngle));
pngBuffer = rotateFilter->ApplyFilter(pngBuffer, frameInfo.Width, frameInfo.Height);
frameInfo = rotateFilter->GetFrameInfo(frameInfo);
}*/
shared_ptr<ScaleFilter> scaleFilter = ScaleFilter::GetScaleFilter(filterType);
if(scaleFilter) {
pngBuffer = scaleFilter->ApplyFilter(pngBuffer, frameInfo.Width, frameInfo.Height, _console->GetSettings()->GetVideoConfig().ScanlineIntensity);
frameInfo = scaleFilter->GetFrameInfo(frameInfo);
}
//TODO
/*
VideoHud hud;
hud.DrawHud(_console, pngBuffer, frameInfo, _console->GetSettings()->GetOverscanDimensions());
*/
if(!filename.empty()) {
PNGHelper::WritePNG(filename, pngBuffer, frameInfo.Width, frameInfo.Height);
} else {

View file

@ -229,9 +229,9 @@ double EmuSettings::GetAspectRatio(ConsoleRegion region)
{
switch(_video.AspectRatio) {
case VideoAspectRatio::NoStretching: return 0.0;
case VideoAspectRatio::Auto: return region == ConsoleRegion::Pal ? (9440000.0 / 6384411.0) : (128.0 / 105.0);
case VideoAspectRatio::NTSC: return 128.0 / 105.0;
case VideoAspectRatio::PAL: return 9440000.0 / 6384411.0;
case VideoAspectRatio::Auto: return region == ConsoleRegion::Pal ? (11.0 / 8.0) : (8.0 / 7.0);
case VideoAspectRatio::NTSC: return 8.0 / 7.0;
case VideoAspectRatio::PAL: return 11.0 / 8.0;
case VideoAspectRatio::Standard: return 4.0 / 3.0;
case VideoAspectRatio::Widescreen: return 16.0 / 9.0;
case VideoAspectRatio::Custom: return _video.CustomAspectRatio;

View file

@ -40,27 +40,27 @@ ScreenSize VideoDecoder::GetScreenSize(bool ignoreScale)
{
ScreenSize size;
FrameInfo frameInfo = _videoFilter->GetFrameInfo();
double aspectRatio = _console->GetSettings()->GetAspectRatio(_console->GetRegion());
double scale = (ignoreScale ? 1 : _console->GetSettings()->GetVideoConfig().VideoScale);
double scale = (ignoreScale ? 1 : _console->GetSettings()->GetVideoConfig().VideoScale);
bool useHighResOutput = _baseFrameInfo.Width >= 512 || _videoFilterType == VideoFilterType::NTSC;
int divider = useHighResOutput ? 2 : 1;
size.Width = (int32_t)(frameInfo.Width * scale / divider);
size.Height = (int32_t)(frameInfo.Height * scale / divider);
size.Scale = scale;
double aspectRatio = _console->GetSettings()->GetAspectRatio(_console->GetRegion());
if(aspectRatio != 0.0) {
OverscanDimensions overscan = _console->GetSettings()->GetOverscan();
uint32_t originalHeight = frameInfo.Height + (overscan.Top + overscan.Bottom) * divider;
uint32_t originalWidth = frameInfo.Width + (overscan.Left + overscan.Right) * divider;
size.Width = (uint32_t)(originalHeight * scale * aspectRatio * ((double)frameInfo.Width / originalWidth)) / divider;
VideoAspectRatio aspect = _console->GetSettings()->GetVideoConfig().AspectRatio;
bool usePar = aspect == VideoAspectRatio::NTSC || aspect == VideoAspectRatio::PAL || aspect == VideoAspectRatio::Auto;
if(usePar) {
OverscanDimensions overscan = _console->GetSettings()->GetOverscan();
uint32_t fullWidth = frameInfo.Width + (overscan.Left + overscan.Right);
size.Width = (uint32_t)(256 * scale * aspectRatio * frameInfo.Width / fullWidth);
} else {
size.Width = (uint32_t)(size.Height * aspectRatio);
}
}
/*
if(_console->GetSettings()->GetScreenRotation() % 180) {
std::swap(size.Width, size.Height);
}*/
size.Scale = scale;
return size;
}
@ -79,16 +79,6 @@ void VideoDecoder::UpdateVideoFilter()
default: _scaleFilter = ScaleFilter::GetScaleFilter(_videoFilterType); break;
}
}
//TODO
/*
if(_console->GetSettings()->GetScreenRotation() == 0 && _rotateFilter) {
_rotateFilter.reset();
} else if(_console->GetSettings()->GetScreenRotation() > 0) {
if(!_rotateFilter || _rotateFilter->GetAngle() != _console->GetSettings()->GetScreenRotation()) {
_rotateFilter.reset(new RotateFilter(_console->GetSettings()->GetScreenRotation()));
}
}*/
}
void VideoDecoder::DecodeFrame(bool forRewind)
@ -104,22 +94,11 @@ void VideoDecoder::DecodeFrame(bool forRewind)
_inputHud->DrawControllers(_videoFilter->GetOverscan(), _frameNumber);
_console->GetDebugHud()->Draw(outputBuffer, _videoFilter->GetOverscan(), frameInfo.Width, _frameNumber);
/*
if(_rotateFilter) {
outputBuffer = _rotateFilter->ApplyFilter(outputBuffer, frameInfo.Width, frameInfo.Height);
frameInfo = _rotateFilter->GetFrameInfo(frameInfo);
}*/
if(_scaleFilter) {
outputBuffer = _scaleFilter->ApplyFilter(outputBuffer, frameInfo.Width, frameInfo.Height, _console->GetSettings()->GetVideoConfig().ScanlineIntensity);
frameInfo = _scaleFilter->GetFrameInfo(frameInfo);
}
/*
if(_hud) {
_hud->DrawHud(_console, outputBuffer, frameInfo, _videoFilter->GetOverscan());
}*/
ScreenSize screenSize = GetScreenSize(true);
VideoConfig config = _console->GetSettings()->GetVideoConfig();
if(_previousScale != config.VideoScale || screenSize.Height != _previousScreenSize.Height || screenSize.Width != _previousScreenSize.Width) {

View file

@ -57,16 +57,23 @@ public:
info.timing.fps = _console->GetRegion() == ConsoleRegion::Ntsc ? 60.098811862348404716732985230828 : 50.006977968268290848936010226333;
info.timing.sample_rate = audio.SampleRate;
float ratio = (float)_console->GetSettings()->GetAspectRatio(_console->GetRegion());
if(ratio == 0.0f) {
ratio = (float)256 / 239;
}
OverscanDimensions overscan = _console->GetSettings()->GetOverscan();
int width = (256 - overscan.Left - overscan.Right);
int height = (239 - overscan.Top - overscan.Bottom);
ratio *= (float)width / height / 256 * 239;
info.geometry.aspect_ratio = ratio;
double aspectRatio = _console->GetSettings()->GetAspectRatio(_console->GetRegion());
if(aspectRatio != 0.0) {
VideoAspectRatio aspect = _console->GetSettings()->GetVideoConfig().AspectRatio;
bool usePar = aspect == VideoAspectRatio::NTSC || aspect == VideoAspectRatio::PAL || aspect == VideoAspectRatio::Auto;
if(usePar) {
info.geometry.aspect_ratio = (float)(width * aspectRatio / height);
} else {
info.geometry.aspect_ratio = (float)aspectRatio;
}
} else {
info.geometry.aspect_ratio = (float)width / height;
}
info.geometry.base_width = width;
info.geometry.base_height = height;

View file

@ -43,8 +43,8 @@ namespace Mesen.GUI.Config
[MinMax(0, 100)] public UInt32 OverscanLeft = 0;
[MinMax(0, 100)] public UInt32 OverscanRight = 0;
[MinMax(0, 100)] public UInt32 OverscanTop = 0;
[MinMax(0, 100)] public UInt32 OverscanBottom = 0;
[MinMax(0, 100)] public UInt32 OverscanTop = 7;
[MinMax(0, 100)] public UInt32 OverscanBottom = 8;
[MarshalAs(UnmanagedType.I1)] public bool FullscreenForceIntegerScale = false;
[MarshalAs(UnmanagedType.I1)] public bool UseExclusiveFullscreen = false;

View file

@ -839,9 +839,9 @@
</Enum>
<Enum ID="VideoAspectRatio">
<Value ID="NoStretching">Default (No Stretching)</Value>
<Value ID="Auto">Auto (8:7 or 11:8 based on game)</Value>
<Value ID="NTSC">NTSC (8:7)</Value>
<Value ID="PAL">PAL (11:8)</Value>
<Value ID="Auto">Auto (NTSC or PAL based on game)</Value>
<Value ID="NTSC">NTSC (8:7 PAR)</Value>
<Value ID="PAL">PAL (11:8 PAR)</Value>
<Value ID="Standard">Standard (4:3)</Value>
<Value ID="Widescreen">Widescreen (16:9)</Value>
<Value ID="Custom">Custom</Value>

View file

@ -31,6 +31,9 @@
this.tabMain = new System.Windows.Forms.TabControl();
this.tpgGeneral = new System.Windows.Forms.TabPage();
this.tlpMain = new System.Windows.Forms.TableLayoutPanel();
this.flpResolution = new System.Windows.Forms.FlowLayoutPanel();
this.lblFullscreenResolution = new System.Windows.Forms.Label();
this.cboFullscreenResolution = new System.Windows.Forms.ComboBox();
this.chkUseExclusiveFullscreen = new System.Windows.Forms.CheckBox();
this.lblVideoScale = new System.Windows.Forms.Label();
this.chkVerticalSync = new System.Windows.Forms.CheckBox();
@ -100,12 +103,10 @@
this.mnuPresetSVideo = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPresetRgb = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPresetMonochrome = new System.Windows.Forms.ToolStripMenuItem();
this.flpResolution = new System.Windows.Forms.FlowLayoutPanel();
this.lblFullscreenResolution = new System.Windows.Forms.Label();
this.cboFullscreenResolution = new System.Windows.Forms.ComboBox();
this.tabMain.SuspendLayout();
this.tpgGeneral.SuspendLayout();
this.tlpMain.SuspendLayout();
this.flpResolution.SuspendLayout();
this.flowLayoutPanel6.SuspendLayout();
this.flpRefreshRate.SuspendLayout();
this.tpgPicture.SuspendLayout();
@ -127,7 +128,6 @@
this.tpgAdvanced.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
this.ctxPicturePresets.SuspendLayout();
this.flpResolution.SuspendLayout();
this.SuspendLayout();
//
// baseConfigPanel
@ -192,6 +192,60 @@
this.tlpMain.Size = new System.Drawing.Size(560, 395);
this.tlpMain.TabIndex = 1;
//
// flpResolution
//
this.tlpMain.SetColumnSpan(this.flpResolution, 2);
this.flpResolution.Controls.Add(this.lblFullscreenResolution);
this.flpResolution.Controls.Add(this.cboFullscreenResolution);
this.flpResolution.Dock = System.Windows.Forms.DockStyle.Fill;
this.flpResolution.Location = new System.Drawing.Point(30, 116);
this.flpResolution.Margin = new System.Windows.Forms.Padding(30, 0, 0, 0);
this.flpResolution.Name = "flpResolution";
this.flpResolution.Size = new System.Drawing.Size(530, 27);
this.flpResolution.TabIndex = 28;
this.flpResolution.Visible = false;
//
// lblFullscreenResolution
//
this.lblFullscreenResolution.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.lblFullscreenResolution.AutoSize = true;
this.lblFullscreenResolution.Location = new System.Drawing.Point(3, 7);
this.lblFullscreenResolution.Name = "lblFullscreenResolution";
this.lblFullscreenResolution.Size = new System.Drawing.Size(111, 13);
this.lblFullscreenResolution.TabIndex = 17;
this.lblFullscreenResolution.Text = "Fullscreen Resolution:";
//
// cboFullscreenResolution
//
this.cboFullscreenResolution.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboFullscreenResolution.FormattingEnabled = true;
this.cboFullscreenResolution.Items.AddRange(new object[] {
"3840x2160",
"2560x1440",
"2160x1200",
"1920x1440",
"1920x1200",
"1920x1080",
"1680x1050",
"1600x1200",
"1600x1024",
"1600x900",
"1366x768",
"1360x768",
"1280x1024",
"1280x960",
"1280x800",
"1280x768",
"1280x720",
"1152x864",
"1024x768",
"800x600",
"640x480"});
this.cboFullscreenResolution.Location = new System.Drawing.Point(120, 3);
this.cboFullscreenResolution.Name = "cboFullscreenResolution";
this.cboFullscreenResolution.Size = new System.Drawing.Size(85, 21);
this.cboFullscreenResolution.TabIndex = 25;
//
// chkUseExclusiveFullscreen
//
this.chkUseExclusiveFullscreen.Anchor = System.Windows.Forms.AnchorStyles.Left;
@ -285,12 +339,6 @@
//
this.cboAspectRatio.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboAspectRatio.FormattingEnabled = true;
this.cboAspectRatio.Items.AddRange(new object[] {
"Auto",
"NTSC (8:7)",
"PAL (18:13)",
"Standard (4:3)",
"Widescreen (16:9)"});
this.cboAspectRatio.Location = new System.Drawing.Point(3, 3);
this.cboAspectRatio.Name = "cboAspectRatio";
this.cboAspectRatio.Size = new System.Drawing.Size(197, 21);
@ -1233,60 +1281,6 @@
this.mnuPresetMonochrome.Text = "Monochrome";
this.mnuPresetMonochrome.Click += new System.EventHandler(this.mnuPresetMonochrome_Click);
//
// flpResolution
//
this.tlpMain.SetColumnSpan(this.flpResolution, 2);
this.flpResolution.Controls.Add(this.lblFullscreenResolution);
this.flpResolution.Controls.Add(this.cboFullscreenResolution);
this.flpResolution.Dock = System.Windows.Forms.DockStyle.Fill;
this.flpResolution.Location = new System.Drawing.Point(30, 116);
this.flpResolution.Margin = new System.Windows.Forms.Padding(30, 0, 0, 0);
this.flpResolution.Name = "flpResolution";
this.flpResolution.Size = new System.Drawing.Size(530, 27);
this.flpResolution.TabIndex = 28;
this.flpResolution.Visible = false;
//
// lblFullscreenResolution
//
this.lblFullscreenResolution.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.lblFullscreenResolution.AutoSize = true;
this.lblFullscreenResolution.Location = new System.Drawing.Point(3, 7);
this.lblFullscreenResolution.Name = "lblFullscreenResolution";
this.lblFullscreenResolution.Size = new System.Drawing.Size(111, 13);
this.lblFullscreenResolution.TabIndex = 17;
this.lblFullscreenResolution.Text = "Fullscreen Resolution:";
//
// cboFullscreenResolution
//
this.cboFullscreenResolution.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboFullscreenResolution.FormattingEnabled = true;
this.cboFullscreenResolution.Items.AddRange(new object[] {
"3840x2160",
"2560x1440",
"2160x1200",
"1920x1440",
"1920x1200",
"1920x1080",
"1680x1050",
"1600x1200",
"1600x1024",
"1600x900",
"1366x768",
"1360x768",
"1280x1024",
"1280x960",
"1280x800",
"1280x768",
"1280x720",
"1152x864",
"1024x768",
"800x600",
"640x480"});
this.cboFullscreenResolution.Location = new System.Drawing.Point(120, 3);
this.cboFullscreenResolution.Name = "cboFullscreenResolution";
this.cboFullscreenResolution.Size = new System.Drawing.Size(85, 21);
this.cboFullscreenResolution.TabIndex = 25;
//
// frmVideoConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -1305,6 +1299,8 @@
this.tpgGeneral.ResumeLayout(false);
this.tlpMain.ResumeLayout(false);
this.tlpMain.PerformLayout();
this.flpResolution.ResumeLayout(false);
this.flpResolution.PerformLayout();
this.flowLayoutPanel6.ResumeLayout(false);
this.flowLayoutPanel6.PerformLayout();
this.flpRefreshRate.ResumeLayout(false);
@ -1336,8 +1332,6 @@
this.tpgAdvanced.ResumeLayout(false);
this.tableLayoutPanel2.ResumeLayout(false);
this.ctxPicturePresets.ResumeLayout(false);
this.flpResolution.ResumeLayout(false);
this.flpResolution.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();