Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 67f4a1f0 authored by Nicolas Carion's avatar Nicolas Carion

Move color-profile related functions to ProfileRepostitory

parent b199b115
......@@ -24,6 +24,7 @@
#include "encodingprofilesdialog.h"
#include "kdenlivesettings.h"
#include "profiles/profilemodel.hpp"
#include "profiles/profilerepository.hpp"
#include "profilesdialog.h"
#include "project/dialogs/profilewidget.h"
#include "renderer.h"
......@@ -1153,7 +1154,7 @@ void KdenliveSettingsDialog::slotUpdatev4lCaptureProfile()
m_configCapture.p_fps->setText(info.at(3) + QLatin1Char('/') + info.at(4));
m_configCapture.p_aspect->setText(QStringLiteral("1/1"));
m_configCapture.p_display->setText(info.at(1) + QLatin1Char('/') + info.at(2));
m_configCapture.p_colorspace->setText(ProfilesDialog::getColorspaceDescription(601));
m_configCapture.p_colorspace->setText(ProfileRepository::getColorspaceDescription(601));
m_configCapture.p_progressive->setText(i18n("Progressive"));
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/profiles/"));
......@@ -1189,7 +1190,7 @@ void KdenliveSettingsDialog::loadCurrentV4lProfileInfo()
m_configCapture.p_fps->setText(QString::number(prof.frame_rate_num) + QLatin1Char('/') + QString::number(prof.frame_rate_den));
m_configCapture.p_aspect->setText(QString::number(prof.sample_aspect_num) + QLatin1Char('/') + QString::number(prof.sample_aspect_den));
m_configCapture.p_display->setText(QString::number(prof.display_aspect_num) + QLatin1Char('/') + QString::number(prof.display_aspect_den));
m_configCapture.p_colorspace->setText(ProfilesDialog::getColorspaceDescription(prof.colorspace));
m_configCapture.p_colorspace->setText(ProfileRepository::getColorspaceDescription(prof.colorspace));
if (prof.progressive) {
m_configCapture.p_progressive->setText(i18n("Progressive"));
}
......@@ -1199,7 +1200,7 @@ void KdenliveSettingsDialog::saveCurrentV4lProfile()
{
MltVideoProfile profile;
profile.description = QStringLiteral("Video4Linux capture");
profile.colorspace = ProfilesDialog::getColorspaceFromDescription(m_configCapture.p_colorspace->text());
profile.colorspace = ProfileRepository::getColorspaceFromDescription(m_configCapture.p_colorspace->text());
profile.width = m_configCapture.p_size->text().section('x', 0, 0).toInt();
profile.height = m_configCapture.p_size->text().section('x', 1, 1).toInt();
profile.sample_aspect_num = m_configCapture.p_aspect->text().section(QLatin1Char('/'), 0, 0).toInt();
......
......@@ -50,10 +50,10 @@ ProfilesDialog::ProfilesDialog(const QString &profileDescription, QWidget *paren
m_infoMessage->hide();
// Fill colorspace list (see mlt_profile.h)
m_view.colorspace->addItem(getColorspaceDescription(601), 601);
m_view.colorspace->addItem(getColorspaceDescription(709), 709);
m_view.colorspace->addItem(getColorspaceDescription(240), 240);
m_view.colorspace->addItem(getColorspaceDescription(0), 0);
m_view.colorspace->addItem(ProfileRepository::getColorspaceDescription(601), 601);
m_view.colorspace->addItem(ProfileRepository::getColorspaceDescription(709), 709);
m_view.colorspace->addItem(ProfileRepository::getColorspaceDescription(240), 240);
m_view.colorspace->addItem(ProfileRepository::getColorspaceDescription(0), 0);
QStringList profilesFilter;
profilesFilter << QStringLiteral("*");
......@@ -103,10 +103,10 @@ ProfilesDialog::ProfilesDialog(const QString &profilePath, bool, QWidget *parent
m_infoMessage->hide();
// Fill colorspace list (see mlt_profile.h)
m_view.colorspace->addItem(getColorspaceDescription(601), 601);
m_view.colorspace->addItem(getColorspaceDescription(709), 709);
m_view.colorspace->addItem(getColorspaceDescription(240), 240);
m_view.colorspace->addItem(getColorspaceDescription(0), 0);
m_view.colorspace->addItem(ProfileRepository::getColorspaceDescription(601), 601);
m_view.colorspace->addItem(ProfileRepository::getColorspaceDescription(709), 709);
m_view.colorspace->addItem(ProfileRepository::getColorspaceDescription(240), 240);
m_view.colorspace->addItem(ProfileRepository::getColorspaceDescription(0), 0);
QStringList profilesFilter;
profilesFilter << QStringLiteral("*");
......@@ -642,32 +642,3 @@ void ProfilesDialog::slotUpdateDisplay(QString currentProfile)
}
m_profileIsModified = false;
}
// static
QString ProfilesDialog::getColorspaceDescription(int colorspace)
{
// TODO: should the descriptions be translated?
switch (colorspace) {
case 601:
return QStringLiteral("ITU-R 601");
case 709:
return QStringLiteral("ITU-R 709");
case 240:
return QStringLiteral("SMPTE240M");
default:
return i18n("Unknown");
}
}
// static
int ProfilesDialog::getColorspaceFromDescription(const QString &description)
{
// TODO: should the descriptions be translated?
if (description == QLatin1String("SMPTE240M")) {
return 240;
}
if (description == QLatin1String("ITU-R 709")) {
return 709;
}
return 601;
}
......@@ -62,16 +62,6 @@ public:
* @return A string list of the matching profiles description */
static QMap<QString, QString> getProfilesFromProperties(int width, int height, double fps, double par, bool useDisplayWidth = false);
/** @brief Get the descriptive text for given colorspace code (defined by MLT)
* @param colorspace An int as defined in mlt_profile.h
* @return The string description */
static QString getColorspaceDescription(int colorspace);
/** @brief Get the colorspace code (defined by MLT) from a descriptive text
* @param desctiption A string description as defined in getColorspaceDescription(int colorspace)
* @return The int code */
static int getColorspaceFromDescription(const QString &description);
/** @brief Build a profile from it's url */
static MltVideoProfile getProfileFromPath(const QString &path, const QString &name);
......
......@@ -661,7 +661,6 @@ EffectsList ClipController::xmlEffectList(Mlt::Profile *profile, Mlt::Service &s
}
for (int i = 0; i < params.count(); ++i) {
QDomElement param = params.item(i).toElement();
// Useless?
Timeline::setParam(param, effect->get(param.attribute(QStringLiteral("name")).toUtf8().constData()));
}
effList.append(currenteffect);
......
......@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "doc/kdenlivedoc.h"
#include "kdenlivesettings.h"
#include "project/projectmanager.h"
#include "profiles/profilerepository.hpp"
#include "timecodedisplay.h"
#include "utils/KoIconUtils.h"
#include "widgets/choosecolorwidget.h"
......@@ -490,9 +491,9 @@ ClipPropertiesController::ClipPropertiesController(ClipController *controller, Q
connect(box, &QCheckBox::stateChanged, this, &ClipPropertiesController::slotEnableForce);
combo = new QComboBox(this);
combo->setObjectName(QStringLiteral("force_colorspace_value"));
combo->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
combo->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
combo->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
combo->addItem(ProfileRepository::getColorspaceDescription(601), 601);
combo->addItem(ProfileRepository::getColorspaceDescription(709), 709);
combo->addItem(ProfileRepository::getColorspaceDescription(240), 240);
int force_colorspace = m_properties.get_int("force_colorspace");
m_originalProperties.insert(QStringLiteral("force_colorspace"), force_colorspace == 0 ? QStringLiteral("-") : QString::number(force_colorspace));
int colorspace = controller->videoCodecProperty(QStringLiteral("colorspace")).toInt();
......@@ -840,7 +841,7 @@ void ClipPropertiesController::fillProperties()
propertyMap.append(QStringList() << i18n("Pixel aspect ratio") << QString::number(par, 'f', 3));
propertyMap.append(QStringList() << i18n("Pixel format") << m_controller->videoCodecProperty(QStringLiteral("pix_fmt")));
int colorspace = m_controller->videoCodecProperty(QStringLiteral("colorspace")).toInt();
propertyMap.append(QStringList() << i18n("Colorspace") << ProfilesDialog::getColorspaceDescription(colorspace));
propertyMap.append(QStringList() << i18n("Colorspace") << ProfileRepository::getColorspaceDescription(colorspace));
}
if (default_audio > -1) {
char property[200];
......
......@@ -33,6 +33,10 @@
std::unique_ptr<ProfileRepository> ProfileRepository::instance;
std::once_flag ProfileRepository::m_onceFlag;
std::vector<std::pair<int, QString>> ProfileRepository::colorProfiles{
{601,QStringLiteral("ITU-R 601")},
{709, QStringLiteral("ITU-R 709")},
{240, QStringLiteral("SMPTE240M")}};
ProfileRepository::ProfileRepository()
{
......@@ -122,16 +126,21 @@ bool ProfileRepository::profileExists(const QString &path) const
QString ProfileRepository::getColorspaceDescription(int colorspace)
{
// TODO: should the descriptions be translated?
switch (colorspace) {
case 601:
return QStringLiteral("ITU-R 601");
case 709:
return QStringLiteral("ITU-R 709");
case 240:
return QStringLiteral("SMPTE240M");
default:
return i18n("Unknown");
for (const auto& cs : colorProfiles) {
if (cs.first == colorspace)
return cs.second;
}
return i18n("Unknown");
}
// static
int ProfileRepository::getColorspaceFromDescription(const QString &description)
{
for (const auto& cs : colorProfiles) {
if (cs.second == description)
return cs.first;
}
return 0;
}
QVector<double> ProfileRepository::getAllFps() const
......
......@@ -65,6 +65,8 @@ public:
* @param colorspace An int as defined in mlt_profile.h
* @return The string description */
static QString getColorspaceDescription(int colorspace);
/* @brief This is the opposite function */
static int getColorspaceFromDescription(const QString &description);
/** @brief Returns all the possible fps of the profiles in the repository*/
QVector<double> getAllFps() const;
......@@ -79,6 +81,8 @@ protected:
static std::unique_ptr<ProfileRepository> instance;
static std::once_flag m_onceFlag; // flag to create the repository only once;
static std::vector<std::pair<int, QString>> colorProfiles;
mutable QReadWriteLock m_mutex;
std::unordered_map<QString, std::unique_ptr<ProfileModel>> m_profiles; // map from the profile path to the instance of the profile. We use unordered_map
......
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