Skip to content

Commit

Permalink
MythDisplay: Assume 'square pixels' for default display aspect ratio
Browse files Browse the repository at this point in the history
calculation

- the default (for new installations) now assumes display pixels are
square (i.e. have an aspect ratio of 1) - which means we can calculate
the display aspect ratio from the resolution (which was previously a
fallback).
- behaviour for existing installations will be unchanged
- square pixels are now the norm for the vast majority of displays and
using the screen resolution to calculate the aspect ratio avoids small
rounding errors from using the EDID and incorrect aspect ratios from
broken/misleading EDIDs.
- refs #13548
  • Loading branch information
mark-kendall committed Jun 18, 2020
1 parent aaf6829 commit 33fa19e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
31 changes: 16 additions & 15 deletions mythtv/libs/libmythui/mythdisplay.cpp
Expand Up @@ -794,9 +794,10 @@ double MythDisplay::GetAspectRatio(QString &Source, bool IgnoreModeOverride)
}

// General override for invalid/misleading EDIDs or multiscreen setups
// New default of -1.0 equates to square pixels for modern displays
bool multiscreen = MythDisplay::SpanAllScreens() && GetScreenCount() > 1;
double override = gCoreContext->GetFloatSettingOnHost("XineramaMonitorAspectRatio",
gCoreContext->GetHostName(), 0.0);
gCoreContext->GetHostName(), -1.0);

// Zero (not valid) indicates auto
if (valid(override))
Expand All @@ -816,26 +817,26 @@ double MythDisplay::GetAspectRatio(QString &Source, bool IgnoreModeOverride)
}
}

// Based on actual physical size if available
if (!m_physicalSize.isEmpty())
double calculated = m_resolution.isEmpty() ? 0.0 :
static_cast<double>(m_resolution.width()) / m_resolution.height();
double detected = m_physicalSize.isEmpty() ? 0.0 :
static_cast<double>(m_physicalSize.width()) / m_physicalSize.height();

// Assume pixel aspect ratio is 1 (square pixels)
if (valid(calculated))
{
double aspect = static_cast<double>(m_physicalSize.width()) / m_physicalSize.height();
if (valid(aspect))
if ((override < 0.0) || !valid(detected))
{
Source = tr("Detected");
return aspect;
Source = tr("Square pixels");
return calculated;
}
}

// Assume pixel aspect ratio is 1 (square pixels)
if (!m_resolution.isEmpty())
// Based on actual physical size if available
if (valid(detected))
{
double aspect = static_cast<double>(m_resolution.width()) / m_resolution.height();
if (valid(aspect))
{
Source = tr("Fallback");
return aspect;
}
Source = tr("Detected");
return detected;
}

// the aspect ratio of last resort
Expand Down
9 changes: 6 additions & 3 deletions mythtv/programs/mythfrontend/globalsettings.cpp
Expand Up @@ -2086,7 +2086,8 @@ static HostComboBoxSetting *ScreenAspectRatio()
auto *gc = new HostComboBoxSetting("XineramaMonitorAspectRatio");

gc->setLabel(AppearanceSettings::tr("Screen aspect ratio"));
gc->addSelection(AppearanceSettings::tr("Auto"), "0.0");
gc->addSelection(AppearanceSettings::tr("Auto (Assume square pixels)"), "-1.0");
gc->addSelection(AppearanceSettings::tr("Auto (Detect from display)"), "0.0");
gc->addSelection(AppearanceSettings::tr("16:9"), "1.7777");
gc->addSelection(AppearanceSettings::tr("16:10"), "1.6");
gc->addSelection(AppearanceSettings::tr("21:9"), "2.3704"); // N.B. Actually 64:27
Expand All @@ -2099,8 +2100,10 @@ static HostComboBoxSetting *ScreenAspectRatio()
gc->addSelection(AppearanceSettings::tr("32:10 (16:10 Side by side)"), "3.2");
gc->addSelection(AppearanceSettings::tr("16:20 (16:10 Above and below)"), "0.8");
gc->setHelpText(AppearanceSettings::tr(
"The aspect ratio of the screen (or screens) is usually automatically detected "
"from the connected display ('Auto'). If automatic detection fails, the correct "
"Most modern displays have square pixels and the aspect ratio of the screen can be "
"computed from the resolution (default). "
"The aspect ratio can also be automatically detected from the connected display "
"- though this may be slightly less accurate. If automatic detection fails, the correct "
"aspect ratio can be specified here. Note: Some values (e.g 32:10) are "
"primarily intended for multiscreen setups."));
return gc;
Expand Down

0 comments on commit 33fa19e

Please sign in to comment.