sequence: rather than a static divider in config, default to a heuristically generated one

This commit is contained in:
itsmattkc
2020-06-08 15:18:01 +10:00
parent 430561e2ac
commit 50b4c1e456
8 changed files with 85 additions and 28 deletions
+40
View File
@@ -22,6 +22,8 @@
#include <QtMath>
#include "core.h"
OLIVE_NAMESPACE_ENTER
VideoParams::VideoParams() :
@@ -48,6 +50,44 @@ VideoParams::VideoParams(const int &width, const int &height, const rational &ti
calculate_effective_size();
}
int VideoParams::generate_auto_divider(qint64 width, qint64 height)
{
// Arbitrary pixel count (from 640x360)
const int target_res = 230400;
qint64 megapixels = width * height;
double squared_divider = double(megapixels) / double(target_res);
double divider = qSqrt(squared_divider);
QList<int> supported_dividers = Core::SupportedDividers();
if (divider <= supported_dividers.first()) {
return supported_dividers.first();
} else if (divider >= supported_dividers.last()) {
return supported_dividers.last();
} else {
for (int i=1; i<supported_dividers.size(); i++) {
int prev_divider = supported_dividers.at(i-1);
int next_divider = supported_dividers.at(i);
if (divider >= prev_divider && divider <= next_divider) {
double prev_diff = qAbs(prev_divider - divider);
double next_diff = qAbs(next_divider - divider);
if (prev_diff < next_diff) {
return prev_divider;
} else {
return next_divider;
}
}
}
// "Safe" fallback
return 2;
}
}
bool VideoParams::operator==(const VideoParams &rhs) const
{
return width() == rhs.width()