UI: When setting base res, use closest output res

When settings the base resolution, try to find the closest output
resolution to the old output resolution, and use that for its value.  If
the aspect ratio is about the same, then don't modify the value.  If the
aspect ratio is significantly different, then find the closest
approximation while keeping with the new aspect ratio.

This particular issue has been an annoyance for quite some time.
This commit is contained in:
jp9000 2015-08-16 14:38:56 -07:00
parent 6bd4f27fe9
commit 59592cf030

View File

@ -19,6 +19,7 @@
#include <obs.hpp> #include <obs.hpp>
#include <util/util.hpp> #include <util/util.hpp>
#include <util/lexer.h> #include <util/lexer.h>
#include <graphics/math-defs.h>
#include <initializer_list> #include <initializer_list>
#include <sstream> #include <sstream>
#include <QLineEdit> #include <QLineEdit>
@ -788,16 +789,25 @@ void OBSBasicSettings::ResetDownscales(uint32_t cx, uint32_t cy,
QString advRescale; QString advRescale;
QString advRecRescale; QString advRecRescale;
QString advFFRescale; QString advFFRescale;
QString oldOutputRes;
string bestScale;
int bestPixelDiff = 0x7FFFFFFF;
advRescale = ui->advOutRescale->lineEdit()->text(); advRescale = ui->advOutRescale->lineEdit()->text();
advRecRescale = ui->advOutRecRescale->lineEdit()->text(); advRecRescale = ui->advOutRecRescale->lineEdit()->text();
advFFRescale = ui->advOutFFRescale->lineEdit()->text(); advFFRescale = ui->advOutFFRescale->lineEdit()->text();
oldOutputRes = ui->outputResolution->lineEdit()->text();
ui->outputResolution->clear(); ui->outputResolution->clear();
ui->advOutRescale->clear(); ui->advOutRescale->clear();
ui->advOutRecRescale->clear(); ui->advOutRecRescale->clear();
ui->advOutFFRescale->clear(); ui->advOutFFRescale->clear();
if (!out_cx || !out_cy) {
out_cx = cx;
out_cy = cy;
}
for (size_t idx = 0; idx < numVals; idx++) { for (size_t idx = 0; idx < numVals; idx++) {
uint32_t downscaleCX = uint32_t(double(cx) / vals[idx]); uint32_t downscaleCX = uint32_t(double(cx) / vals[idx]);
uint32_t downscaleCY = uint32_t(double(cy) / vals[idx]); uint32_t downscaleCY = uint32_t(double(cy) / vals[idx]);
@ -815,11 +825,28 @@ void OBSBasicSettings::ResetDownscales(uint32_t cx, uint32_t cy,
ui->advOutRescale->addItem(outRes.c_str()); ui->advOutRescale->addItem(outRes.c_str());
ui->advOutRecRescale->addItem(outRes.c_str()); ui->advOutRecRescale->addItem(outRes.c_str());
ui->advOutFFRescale->addItem(outRes.c_str()); ui->advOutFFRescale->addItem(outRes.c_str());
/* always try to find the closest output resolution to the
* previously set output resolution */
int newPixelCount = int(downscaleCX * downscaleCY);
int oldPixelCount = int(out_cx * out_cy);
int diff = abs(newPixelCount - oldPixelCount);
if (diff < bestPixelDiff) {
bestScale = res;
bestPixelDiff = diff;
}
} }
string res = ResString(cx, cy); string res = ResString(cx, cy);
ui->outputResolution->lineEdit()->setText(res.c_str()); float baseAspect = float(cx) / float(cy);
float outputAspect = float(out_cx) / float(out_cy);
if (close_float(baseAspect, outputAspect, 0.01f))
ui->outputResolution->lineEdit()->setText(oldOutputRes);
else
ui->outputResolution->lineEdit()->setText(bestScale.c_str());
if (advRescale.isEmpty()) if (advRescale.isEmpty())
advRescale = res.c_str(); advRescale = res.c_str();