Always ensure we have a profile with valid dimensions

Fixes #30
parent ce1564ef
......@@ -104,12 +104,12 @@ KeyframeImport::KeyframeImport(int in, int out, const QString &animData, std::sh
lay->addWidget(m_outPoint);
// Check what kind of parameters are in our target
for (const QPersistentModelIndex &ix : indexes) {
ParamType type = m_model->data(ix, AssetParameterModel::TypeRole).value<ParamType>();
for (const QPersistentModelIndex &idx : indexes) {
ParamType type = m_model->data(idx, AssetParameterModel::TypeRole).value<ParamType>();
if (type == ParamType::KeyframeParam) {
m_simpleTargets.insert(m_model->data(ix, Qt::DisplayRole).toString(), m_model->data(ix, AssetParameterModel::NameRole).toString());
m_simpleTargets.insert(m_model->data(idx, Qt::DisplayRole).toString(), m_model->data(idx, AssetParameterModel::NameRole).toString());
} else if (type == ParamType::AnimatedRect) {
m_geometryTargets.insert(m_model->data(ix, Qt::DisplayRole).toString(), m_model->data(ix, AssetParameterModel::NameRole).toString());
m_geometryTargets.insert(m_model->data(idx, Qt::DisplayRole).toString(), m_model->data(idx, AssetParameterModel::NameRole).toString());
}
}
......
......@@ -787,6 +787,7 @@ QDockWidget *Bin::clipPropertiesDock()
void Bin::abortOperations()
{
m_infoMessage->hide();
blockSignals(true);
if (m_propertiesPanel) {
for (QWidget *w : m_propertiesPanel->findChildren<ClipPropertiesController *>()) {
......@@ -1114,7 +1115,6 @@ void Bin::setMonitor(Monitor *monitor)
void Bin::setDocument(KdenliveDoc *project)
{
m_infoMessage->hide();
blockSignals(true);
m_proxyModel->selectionModel()->blockSignals(true);
setEnabled(false);
......
......@@ -297,12 +297,24 @@ bool Core::setCurrentProfile(const QString &profilePath)
m_mainWindow->updateRenderWidgetProfile();
if (m_guiConstructed && m_mainWindow->getCurrentTimeline()->controller()->getModel()) {
m_mainWindow->getCurrentTimeline()->controller()->getModel()->updateProfile(&getCurrentProfile()->profile());
checkProfileValidity();
}
return true;
}
return false;
}
void Core::checkProfileValidity()
{
int offset = (getCurrentProfile()->profile().width() % 8) + (getCurrentProfile()->profile().height() % 2);
if (offset > 0) {
// Profile is broken, warn user
if (m_binWidget) {
m_binWidget->displayBinMessage(i18n("Your project profile is invalid, rendering might fail."), KMessageWidget::Warning);
}
}
}
double Core::getCurrentSar() const
{
return getCurrentProfile()->sar();
......
......@@ -197,6 +197,8 @@ private:
QString m_profile;
std::unique_ptr<Mlt::Profile> m_thumbProfile;
bool m_guiConstructed = false;
/** @brief Check that the profile is valid (width is a multiple of 8 and height a multiple of 2 */
void checkProfileValidity();
public slots:
void triggerAction(const QString &name);
......
......@@ -1337,7 +1337,7 @@ void KdenliveDoc::switchProfile(std::unique_ptr<ProfileParam> &profile, const QS
QString matchingProfile = ProfileRepository::get()->findMatchingProfile(profile.get());
if (matchingProfile.isEmpty() && (profile->width() % 8 != 0)) {
// Make sure profile width is a multiple of 8, required by some parts of mlt
profile->adjustWidth();
profile->adjustDimensions();
matchingProfile = ProfileRepository::get()->findMatchingProfile(profile.get());
}
if (!matchingProfile.isEmpty()) {
......
......@@ -171,7 +171,7 @@ void LoadJob::checkProfile(const QString clipId, QDomElement xml, std::shared_pt
blankProfile->from_producer(*producer);
std::unique_ptr<ProfileParam> clipProfile(new ProfileParam(blankProfile.get()));
std::unique_ptr<ProfileParam> projectProfile(new ProfileParam(pCore->getCurrentProfile().get()));
clipProfile->adjustWidth();
clipProfile->adjustDimensions();
if (*clipProfile.get() == *projectProfile.get()) {
if (KdenliveSettings::default_profile().isEmpty()) {
// Confirm default project format
......
......@@ -63,7 +63,7 @@ public:
bool isCompatible(std::unique_ptr<ProfileInfo> &other) const;
bool isCompatible(Mlt::Profile *other) const;
virtual void adjustWidth() = 0;
virtual void adjustDimensions() = 0;
const QString descriptiveString() const;
const QString dialogDescriptiveString() const;
......
......@@ -20,6 +20,7 @@
**************************************************************************/
#include "profilemodel.hpp"
#include "core.h"
#include "kdenlive_debug.h"
#include "kdenlivesettings.h"
#include <KLocalizedString>
......@@ -27,6 +28,7 @@
#include <QDir>
#include <QFile>
#include <KMessageWidget>
ProfileModel::ProfileModel(const QString &path)
: m_path(path)
......@@ -137,12 +139,10 @@ void ProfileModel::set_explicit(int b)
m_profile->set_explicit(b);
}
ProfileParam::ProfileParam(const QDomElement &element)
ProfileParam::ProfileParam(QDomElement element)
: m_description(element.attribute(QStringLiteral("description")))
, m_frame_rate_num(element.attribute(QStringLiteral("frame_rate_num")).toInt())
, m_frame_rate_den(element.attribute(QStringLiteral("frame_rate_den")).toInt())
, m_width(element.attribute(QStringLiteral("width")).toInt())
, m_height(element.attribute(QStringLiteral("height")).toInt())
, m_progressive((element.attribute(QStringLiteral("progressive")).toInt() != 0))
, m_sample_aspect_num(element.attribute(QStringLiteral("sample_aspect_num")).toInt())
, m_sample_aspect_den(element.attribute(QStringLiteral("sample_aspect_den")).toInt())
......@@ -150,6 +150,18 @@ ProfileParam::ProfileParam(const QDomElement &element)
, m_display_aspect_den(element.attribute(QStringLiteral("display_aspect_den")).toInt())
, m_colorspace(element.attribute(QStringLiteral("colorspace")).toInt())
{
// Ensure profile has viable width / height
int width = element.attribute(QStringLiteral("width")).toInt();
int height = element.attribute(QStringLiteral("height")).toInt();
if ((width % 8) + (height % 2) > 0) {
pCore->displayBinMessage(i18n("The project profile is invalid (%1x%2), it was adjusted to %3x%4.", width, height, width + (width % 8), height + (height % 2)), KMessageWidget::Warning);
width += width % 8;
height += height % 2;
element.setAttribute(QStringLiteral("width"), width);
element.setAttribute(QStringLiteral("height"), height);
}
m_width = width;
m_height = height;
m_fps = m_frame_rate_num / m_frame_rate_den;
m_sar = m_sample_aspect_num / m_sample_aspect_den;
m_dar = m_display_aspect_num / m_display_aspect_den;
......@@ -249,9 +261,10 @@ double ProfileParam::sar() const
{
return m_sar;
}
void ProfileParam::adjustWidth()
void ProfileParam::adjustDimensions()
{
m_width = (m_width + 7) / 8 * 8;
m_width += m_width % 8;
m_height += m_height % 2;
}
bool ProfileParam::is_valid() const
......
......@@ -66,7 +66,7 @@ public:
int colorspace() const override;
QString path() const override;
void adjustWidth() override{};
void adjustDimensions() override{};
/* @brief get underlying profile. Use with caution*/
Mlt::Profile &profile() { return *m_profile.get(); };
......@@ -86,7 +86,7 @@ class ProfileParam : public ProfileInfo
public:
ProfileParam() = delete;
ProfileParam(const QDomElement &element);
ProfileParam(QDomElement element);
ProfileParam(ProfileInfo *p);
ProfileParam(Mlt::Profile *p);
......@@ -107,7 +107,7 @@ public:
double dar() const override;
// A profile's width should always be a multiple of 8
void adjustWidth() override;
void adjustDimensions() override;
bool is_valid() const override;
QString m_path;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment