Skip to content

Commit

Permalink
UI: When setting base res, use closest output res
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jp9000 committed Aug 16, 2015
1 parent 6bd4f27 commit 59592cf
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion obs/window-basic-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <obs.hpp>
#include <util/util.hpp>
#include <util/lexer.h>
#include <graphics/math-defs.h>
#include <initializer_list>
#include <sstream>
#include <QLineEdit>
Expand Down Expand Up @@ -788,16 +789,25 @@ void OBSBasicSettings::ResetDownscales(uint32_t cx, uint32_t cy,
QString advRescale;
QString advRecRescale;
QString advFFRescale;
QString oldOutputRes;
string bestScale;
int bestPixelDiff = 0x7FFFFFFF;

advRescale = ui->advOutRescale->lineEdit()->text();
advRecRescale = ui->advOutRecRescale->lineEdit()->text();
advFFRescale = ui->advOutFFRescale->lineEdit()->text();
oldOutputRes = ui->outputResolution->lineEdit()->text();

ui->outputResolution->clear();
ui->advOutRescale->clear();
ui->advOutRecRescale->clear();
ui->advOutFFRescale->clear();

if (!out_cx || !out_cy) {
out_cx = cx;
out_cy = cy;
}

for (size_t idx = 0; idx < numVals; idx++) {
uint32_t downscaleCX = uint32_t(double(cx) / vals[idx]);
uint32_t downscaleCY = uint32_t(double(cy) / vals[idx]);
Expand All @@ -815,11 +825,28 @@ void OBSBasicSettings::ResetDownscales(uint32_t cx, uint32_t cy,
ui->advOutRescale->addItem(outRes.c_str());
ui->advOutRecRescale->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);

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())
advRescale = res.c_str();
Expand Down

0 comments on commit 59592cf

Please sign in to comment.