all repos — mgba @ ec0b206fee166975fdb3667dee22da0ce50a1107

mGBA Game Boy Advance Emulator

Qt: Add ability to manually specify and lock video aspect ratio
Jeffrey Pfau jeffrey@endrift.com
Wed, 12 Nov 2014 02:22:05 -0800
commit

ec0b206fee166975fdb3667dee22da0ce50a1107

parent

72fd09dbc977a2d56ebafdad4c0ffdb9fcfebb9f

3 files changed, 75 insertions(+), 11 deletions(-)

jump to
M src/platform/qt/VideoView.cppsrc/platform/qt/VideoView.cpp

@@ -82,6 +82,9 @@

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.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))); FFmpegEncoderInit(&m_encoder);

@@ -253,8 +256,8 @@ }

void VideoView::setWidth(int width, bool manual) { m_width = width; + updateAspectRatio(width, 0); FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height); - validateSettings(); if (manual) { uncheckIncompatible(); }

@@ -262,8 +265,24 @@ }

void VideoView::setHeight(int height, bool manual) { m_height = height; + updateAspectRatio(0, height); FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height); - validateSettings(); + 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); if (manual) { uncheckIncompatible(); }

@@ -305,6 +324,35 @@

m_ui.start->setEnabled(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() {
M src/platform/qt/VideoView.hsrc/platform/qt/VideoView.h

@@ -54,6 +54,8 @@ void setVideoBitrate(int, bool manual = true);

void setWidth(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);

@@ -61,6 +63,7 @@ void uncheckIncompatible();

private: bool validateSettings(); + void updateAspectRatio(int width, int height, bool force = false); static QString sanitizeCodec(const QString&, const QMap<QString, QString>& mapping); static void safelyCheck(QAbstractButton*, bool set = true); static void safelySet(QSpinBox*, int value);
M src/platform/qt/VideoView.uisrc/platform/qt/VideoView.ui

@@ -431,11 +431,11 @@ </widget>

</item> <item row="1" column="3"> <widget class="QSpinBox" name="hratio"> - <property name="enabled"> - <bool>false</bool> - </property> <property name="minimum"> <number>1</number> + </property> + <property name="maximum"> + <number>9999</number> </property> <property name="value"> <number>2</number>

@@ -444,11 +444,11 @@ </widget>

</item> <item row="1" column="1"> <widget class="QSpinBox" name="wratio"> - <property name="enabled"> - <bool>false</bool> - </property> <property name="minimum"> <number>1</number> + </property> + <property name="maximum"> + <number>9999</number> </property> <property name="value"> <number>3</number>

@@ -457,9 +457,6 @@ </widget>

</item> <item row="1" column="4"> <widget class="QCheckBox" name="lockRatio"> - <property name="enabled"> - <bool>false</bool> - </property> <property name="text"> <string>Lock aspect ratio</string> </property>

@@ -496,9 +493,25 @@ <tabstop>filename</tabstop>

<tabstop>start</tabstop> <tabstop>stop</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>video</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> <resources/> <connections/>