File indexing completed on 2024-12-22 04:36:19
0001 /* 0002 SPDX-FileCopyrightText: 2018 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 This file is part of Kdenlive. See www.kdenlive.org. 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "rotohelper.hpp" 0009 #include "assets/keyframes/model/keyframemodellist.hpp" 0010 #include "core.h" 0011 #include "monitor/monitor.h" 0012 #include "utils/gentime.h" 0013 0014 #include <QSize> 0015 #include <utility> 0016 RotoHelper::RotoHelper(Monitor *monitor, std::shared_ptr<AssetParameterModel> model, QPersistentModelIndex index, QObject *parent) 0017 : KeyframeMonitorHelper(monitor, std::move(model), index, parent) 0018 { 0019 } 0020 0021 void RotoHelper::slotUpdateFromMonitorData(const QVariantList &v) 0022 { 0023 const QVariant res = RotoHelper::getSpline(QVariant(v), pCore->getCurrentFrameSize()); 0024 Q_EMIT updateKeyframeData(m_indexes.first(), res); 0025 } 0026 0027 QVariant RotoHelper::getSpline(const QVariant &value, const QSize frame) 0028 { 0029 QList<BPoint> bPoints; 0030 const QVariantList points = value.toList(); 0031 for (int i = 0; i < points.size() / 3; i++) { 0032 BPoint b(points.at(3 * i).toPointF(), points.at(3 * i + 1).toPointF(), points.at(3 * i + 2).toPointF()); 0033 bPoints << b; 0034 } 0035 QList<QVariant> vlist; 0036 for (const BPoint &point : bPoints) { 0037 QList<QVariant> pl; 0038 for (int i = 0; i < 3; ++i) { 0039 pl << QVariant(QList<QVariant>() << QVariant(point[i].x() / frame.width()) << QVariant(point[i].y() / frame.height())); 0040 } 0041 vlist << QVariant(pl); 0042 } 0043 return vlist; 0044 } 0045 0046 void RotoHelper::refreshParams(int pos) 0047 { 0048 QVariantList centerPoints; 0049 QVariantList controlPoints; 0050 std::shared_ptr<KeyframeModelList> keyframes = m_model->getKeyframeModel(); 0051 if (!keyframes->isEmpty()) { 0052 QVariant splineData = keyframes->getInterpolatedValue(pos, m_indexes.first()); 0053 QList<BPoint> p = getPoints(splineData, pCore->getCurrentFrameSize()); 0054 for (const auto &i : qAsConst(p)) { 0055 centerPoints << QVariant(i.p); 0056 controlPoints << QVariant(i.h1); 0057 controlPoints << QVariant(i.h2); 0058 } 0059 } 0060 if (m_monitor) { 0061 m_monitor->setUpEffectGeometry(QRect(), centerPoints, controlPoints); 0062 } 0063 } 0064 0065 QList<BPoint> RotoHelper::getPoints(const QVariant &value, const QSize frame) 0066 { 0067 QList<BPoint> points; 0068 QList<QVariant> data = value.toList(); 0069 0070 // skip tracking flag 0071 if (data.count() && data.at(0).canConvert<QString>()) { 0072 data.removeFirst(); 0073 } 0074 0075 for (const QVariant &bpoint : data) { 0076 QList<QVariant> l = bpoint.toList(); 0077 BPoint p; 0078 for (int i = 0; i < 3; ++i) { 0079 p[i] = QPointF(l.at(i).toList().at(0).toDouble() * frame.width(), l.at(i).toList().at(1).toDouble() * frame.height()); 0080 } 0081 points << p; 0082 } 0083 return points; 0084 }