mirror of https://github.com/mgba-emu/mgba.git
Qt: Add ability to manually specify and lock video aspect ratio
This commit is contained in:
parent
72fd09dbc9
commit
ec0b206fee
|
@ -82,6 +82,9 @@ VideoView::VideoView(QWidget* parent)
|
||||||
connect(m_ui.width, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
|
connect(m_ui.width, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
|
||||||
connect(m_ui.height, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
|
connect(m_ui.height, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
|
||||||
|
|
||||||
|
connect(m_ui.wratio, SIGNAL(valueChanged(int)), this, SLOT(setAspectWidth(int)));
|
||||||
|
connect(m_ui.hratio, SIGNAL(valueChanged(int)), this, SLOT(setAspectHeight(int)));
|
||||||
|
|
||||||
connect(m_ui.showAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced(bool)));
|
connect(m_ui.showAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced(bool)));
|
||||||
|
|
||||||
FFmpegEncoderInit(&m_encoder);
|
FFmpegEncoderInit(&m_encoder);
|
||||||
|
@ -253,8 +256,8 @@ void VideoView::setVideoBitrate(int br, bool manual) {
|
||||||
|
|
||||||
void VideoView::setWidth(int width, bool manual) {
|
void VideoView::setWidth(int width, bool manual) {
|
||||||
m_width = width;
|
m_width = width;
|
||||||
|
updateAspectRatio(width, 0);
|
||||||
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
|
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
|
||||||
validateSettings();
|
|
||||||
if (manual) {
|
if (manual) {
|
||||||
uncheckIncompatible();
|
uncheckIncompatible();
|
||||||
}
|
}
|
||||||
|
@ -262,8 +265,24 @@ void VideoView::setWidth(int width, bool manual) {
|
||||||
|
|
||||||
void VideoView::setHeight(int height, bool manual) {
|
void VideoView::setHeight(int height, bool manual) {
|
||||||
m_height = height;
|
m_height = height;
|
||||||
|
updateAspectRatio(0, height);
|
||||||
|
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
|
||||||
|
if (manual) {
|
||||||
|
uncheckIncompatible();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoView::setAspectWidth(int, bool manual) {
|
||||||
|
updateAspectRatio(0, m_height, true);
|
||||||
|
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
|
||||||
|
if (manual) {
|
||||||
|
uncheckIncompatible();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoView::setAspectHeight(int, bool manual) {
|
||||||
|
updateAspectRatio(m_width, 0, true);
|
||||||
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
|
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
|
||||||
validateSettings();
|
|
||||||
if (manual) {
|
if (manual) {
|
||||||
uncheckIncompatible();
|
uncheckIncompatible();
|
||||||
}
|
}
|
||||||
|
@ -307,6 +326,35 @@ bool VideoView::validateSettings() {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoView::updateAspectRatio(int width, int height, bool force) {
|
||||||
|
if (m_ui.lockRatio->isChecked() || force) {
|
||||||
|
if (width) {
|
||||||
|
height = m_ui.hratio->value() * width / m_ui.wratio->value();
|
||||||
|
} else if (height) {
|
||||||
|
width = m_ui.wratio->value() * height / m_ui.hratio->value();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_width = width;
|
||||||
|
m_height = height;
|
||||||
|
safelySet(m_ui.width, m_width);
|
||||||
|
safelySet(m_ui.height, m_height);
|
||||||
|
} else {
|
||||||
|
int w = m_width;
|
||||||
|
int h = m_height;
|
||||||
|
// Get greatest common divisor
|
||||||
|
while (w != 0) {
|
||||||
|
int temp = h % w;
|
||||||
|
h = w;
|
||||||
|
w = temp;
|
||||||
|
}
|
||||||
|
int gcd = h;
|
||||||
|
w = m_width / gcd;
|
||||||
|
h = m_height / gcd;
|
||||||
|
safelySet(m_ui.wratio, w);
|
||||||
|
safelySet(m_ui.hratio, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VideoView::uncheckIncompatible() {
|
void VideoView::uncheckIncompatible() {
|
||||||
Preset current = {
|
Preset current = {
|
||||||
.container = m_container,
|
.container = m_container,
|
||||||
|
|
|
@ -54,6 +54,8 @@ private slots:
|
||||||
|
|
||||||
void setWidth(int, bool manual = true);
|
void setWidth(int, bool manual = true);
|
||||||
void setHeight(int, bool manual = true);
|
void setHeight(int, bool manual = true);
|
||||||
|
void setAspectWidth(int, bool manual = true);
|
||||||
|
void setAspectHeight(int, bool manual = true);
|
||||||
|
|
||||||
void showAdvanced(bool);
|
void showAdvanced(bool);
|
||||||
|
|
||||||
|
@ -61,6 +63,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool validateSettings();
|
bool validateSettings();
|
||||||
|
void updateAspectRatio(int width, int height, bool force = false);
|
||||||
static QString sanitizeCodec(const QString&, const QMap<QString, QString>& mapping);
|
static QString sanitizeCodec(const QString&, const QMap<QString, QString>& mapping);
|
||||||
static void safelyCheck(QAbstractButton*, bool set = true);
|
static void safelyCheck(QAbstractButton*, bool set = true);
|
||||||
static void safelySet(QSpinBox*, int value);
|
static void safelySet(QSpinBox*, int value);
|
||||||
|
|
|
@ -431,12 +431,12 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="3">
|
<item row="1" column="3">
|
||||||
<widget class="QSpinBox" name="hratio">
|
<widget class="QSpinBox" name="hratio">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>9999</number>
|
||||||
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>2</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -444,12 +444,12 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QSpinBox" name="wratio">
|
<widget class="QSpinBox" name="wratio">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>9999</number>
|
||||||
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>3</number>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -457,9 +457,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="4">
|
<item row="1" column="4">
|
||||||
<widget class="QCheckBox" name="lockRatio">
|
<widget class="QCheckBox" name="lockRatio">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Lock aspect ratio</string>
|
<string>Lock aspect ratio</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -496,9 +493,25 @@
|
||||||
<tabstop>start</tabstop>
|
<tabstop>start</tabstop>
|
||||||
<tabstop>stop</tabstop>
|
<tabstop>stop</tabstop>
|
||||||
<tabstop>selectFile</tabstop>
|
<tabstop>selectFile</tabstop>
|
||||||
|
<tabstop>presetHQ</tabstop>
|
||||||
|
<tabstop>presetYoutube</tabstop>
|
||||||
|
<tabstop>presetWebM</tabstop>
|
||||||
|
<tabstop>presetLossless</tabstop>
|
||||||
|
<tabstop>preset1080</tabstop>
|
||||||
|
<tabstop>preset720</tabstop>
|
||||||
|
<tabstop>preset480</tabstop>
|
||||||
|
<tabstop>preset160</tabstop>
|
||||||
<tabstop>container</tabstop>
|
<tabstop>container</tabstop>
|
||||||
<tabstop>video</tabstop>
|
<tabstop>video</tabstop>
|
||||||
<tabstop>audio</tabstop>
|
<tabstop>audio</tabstop>
|
||||||
|
<tabstop>vbr</tabstop>
|
||||||
|
<tabstop>abr</tabstop>
|
||||||
|
<tabstop>width</tabstop>
|
||||||
|
<tabstop>height</tabstop>
|
||||||
|
<tabstop>wratio</tabstop>
|
||||||
|
<tabstop>hratio</tabstop>
|
||||||
|
<tabstop>lockRatio</tabstop>
|
||||||
|
<tabstop>showAdvanced</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
Loading…
Reference in New Issue