Commit daa0386a authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Fix several aspect ratio issues including #569

parent 3e7912b2
Pipeline #15283 passed with stage
in 18 minutes and 24 seconds
......@@ -343,17 +343,19 @@ bool Core::setCurrentProfile(const QString &profilePath)
m_currentProfile = profilePath;
m_thumbProfile.reset();
if (m_projectProfile) {
m_projectProfile->set_width(getCurrentProfile()->width());
m_projectProfile->set_height(getCurrentProfile()->height());
m_projectProfile->set_display_aspect(getCurrentProfile()->display_aspect_num(), getCurrentProfile()->display_aspect_den());
m_projectProfile->set_sample_aspect(getCurrentProfile()->sample_aspect_num(), getCurrentProfile()->sample_aspect_den());
m_projectProfile->set_frame_rate(getCurrentProfile()->frame_rate_num(), getCurrentProfile()->frame_rate_den());
m_projectProfile->set_colorspace(getCurrentProfile()->colorspace());
m_projectProfile->set_frame_rate(getCurrentProfile()->frame_rate_num(), getCurrentProfile()->frame_rate_den());
m_projectProfile->set_height(getCurrentProfile()->height());
m_projectProfile->set_progressive(getCurrentProfile()->progressive());
m_projectProfile->set_sample_aspect(getCurrentProfile()->sample_aspect_num(), getCurrentProfile()->sample_aspect_den());
m_projectProfile->set_display_aspect(getCurrentProfile()->display_aspect_num(), getCurrentProfile()->display_aspect_den());
m_projectProfile->set_width(getCurrentProfile()->width());
m_projectProfile->set_explicit(true);
}
// inform render widget
profileChanged();
m_mainWindow->updateRenderWidgetProfile();
pCore->monitorManager()->updatePreviewScaling();
if (m_guiConstructed && m_mainWindow->getCurrentTimeline()->controller()->getModel()) {
m_mainWindow->getCurrentTimeline()->controller()->getModel()->updateProfile(getProjectProfile());
checkProfileValidity();
......@@ -746,12 +748,13 @@ Mlt::Profile *Core::thumbProfile()
QMutexLocker lck(&m_thumbProfileMutex);
if (!m_thumbProfile) {
m_thumbProfile = std::make_unique<Mlt::Profile>(m_currentProfile.toStdString().c_str());
/*double factor = 144. / m_thumbProfile->height();
m_thumbProfile->set_height(144);
int width = 144 * m_thumbProfile->dar() + 0.5;
if (width % 8 > 0) {
width += 8 - width % 8;
int width = m_thumbProfile->width() * factor + 0.5;
if (width % 2 > 0) {
width ++;
}
m_thumbProfile->set_width(width);
m_thumbProfile->set_width(width);*/
}
return m_thumbProfile.get();
}
......
......@@ -101,20 +101,23 @@ QImage KThumb::getFrame(Mlt::Producer &producer, int framepos, int displayWidth,
}
// static
QImage KThumb::getFrame(Mlt::Frame *frame, int width, int height, bool forceRescale)
QImage KThumb::getFrame(Mlt::Frame *frame, int width, int height, int scaledWidth)
{
if (frame == nullptr || !frame->is_valid()) {
qDebug() << "* * * *INVALID FRAME";
return QImage();
}
int ow = forceRescale ? 0 : width;
int oh = forceRescale ? 0 : height;
int ow = width;
int oh = height;
mlt_image_format format = mlt_image_rgb24a;
const uchar *imagedata = frame->get_image(format, ow, oh);
if (imagedata) {
QImage temp(ow, oh, QImage::Format_ARGB32);
memcpy(temp.scanLine(0), imagedata, (unsigned)(ow * oh * 4));
return temp.rgbSwapped();
if (scaledWidth == 0 || scaledWidth == width) {
return temp.rgbSwapped();
}
return temp.rgbSwapped().scaled(scaledWidth, height);
}
return QImage();
}
......
......@@ -35,7 +35,7 @@ QPixmap getImage(const QUrl &url, int width, int height = -1);
QPixmap getImage(const QUrl &url, int frame, int width, int height = -1);
QImage getFrame(Mlt::Producer *producer, int framepos, int displayWidth, int height);
QImage getFrame(Mlt::Producer &producer, int framepos, int displayWidth, int height);
QImage getFrame(Mlt::Frame *frame, int width = 0, int height = 0, bool forceRescale = false);
QImage getFrame(Mlt::Frame *frame, int width = 0, int height = 0, int scaledWidth = 0);
/** @brief Calculates image variance, useful to know if a thumbnail is interesting.
* @return an integer between 0 and 100. 0 means no variance, eg. black image while bigger values mean contrasted image
* */
......
......@@ -36,16 +36,17 @@
CacheJob::CacheJob(const QString &binId, int imageHeight, int thumbsCount, int inPoint, int outPoint)
: AbstractClipJob(CACHEJOB, binId)
, m_fullWidth(imageHeight * pCore->getCurrentDar() + 0.5)
, m_imageHeight(imageHeight)
, m_imageHeight(pCore->thumbProfile()->height())
, m_imageWidth(pCore->thumbProfile()->width())
, m_fullWidth(m_imageHeight * pCore->getCurrentDar() + 0.5)
, m_done(false)
, m_thumbsCount(thumbsCount)
, m_inPoint(inPoint)
, m_outPoint(outPoint)
{
if (m_fullWidth % 8 > 0) {
m_fullWidth += 8 - m_fullWidth % 8;
if (m_fullWidth % 2 > 0) {
m_fullWidth ++;
}
m_imageHeight += m_imageHeight % 2;
auto item = pCore->projectItemModel()->getItemByBinId(binId);
......@@ -104,7 +105,7 @@ bool CacheJob::startJob()
frame->set("top_field_first", -1);
frame->set("rescale.interp", "nearest");
if (frame != nullptr && frame->is_valid()) {
QImage result = KThumb::getFrame(frame.data());
QImage result = KThumb::getFrame(frame.data(), m_imageWidth, m_imageHeight, m_fullWidth);
ThumbnailCache::get()->storeThumbnail(m_clipId, i, result, true);
}
}
......
......@@ -53,8 +53,9 @@ public:
bool commitResult(Fun &undo, Fun &redo) override;
private:
int m_fullWidth;
int m_imageHeight;
int m_imageWidth;
int m_fullWidth;
std::shared_ptr<ProjectClip> m_binClip;
std::shared_ptr<Mlt::Producer> m_prod;
......
......@@ -35,14 +35,15 @@
ThumbJob::ThumbJob(const QString &binId, int imageHeight, int frameNumber, bool persistent, bool reloadAllThumbs)
: AbstractClipJob(THUMBJOB, binId)
, m_frameNumber(frameNumber)
, m_fullWidth(imageHeight * pCore->getCurrentDar() + 0.5)
, m_imageHeight(imageHeight)
, m_imageHeight(pCore->thumbProfile()->height())
, m_imageWidth(pCore->thumbProfile()->width())
, m_fullWidth(m_imageHeight * pCore->getCurrentDar() + 0.5)
, m_persistent(persistent)
, m_reloadAll(reloadAllThumbs)
{
if (m_fullWidth % 8 > 0) {
m_fullWidth += 8 - m_fullWidth % 8;
if (m_fullWidth % 2 > 0) {
m_fullWidth ++;
}
m_imageHeight += m_imageHeight % 2;
auto item = pCore->projectItemModel()->getItemByBinId(binId);
......@@ -103,7 +104,7 @@ bool ThumbJob::startJob()
frame->set("top_field_first", -1);
frame->set("rescale.interp", "nearest");
if ((frame != nullptr) && frame->is_valid()) {
m_result = KThumb::getFrame(frame.data());
m_result = KThumb::getFrame(frame.data(), m_imageWidth, m_imageHeight, m_fullWidth);
m_done = true;
}
return m_done;
......
......@@ -55,8 +55,9 @@ public:
private:
int m_frameNumber;
int m_fullWidth;
int m_imageHeight;
int m_imageWidth;
int m_fullWidth;
std::shared_ptr<ProjectClip> m_binClip;
std::shared_ptr<Mlt::Producer> m_prod;
......
......@@ -232,7 +232,7 @@ void GLWidget::resizeGL(int width, int height)
w = width;
h = width / m_dar;
} else {
w = height / m_dar;
w = height * m_dar;
h = height;
}
x = (width - w) / 2;
......@@ -242,9 +242,7 @@ void GLWidget::resizeGL(int width, int height)
if (rootQml) {
QSize s = pCore->getCurrentFrameSize();
double scalex = (double)m_rect.width() / s.width() * m_zoom;
double scaley = (double)m_rect.width() /
((double)s.height() * m_dar / s.width()) /
s.width() * m_zoom;
double scaley = (double)m_rect.height() / s.height() * m_zoom;
rootQml->setProperty("center", m_rect.center());
rootQml->setProperty("scalex", scalex);
rootQml->setProperty("scaley", scaley);
......@@ -506,8 +504,8 @@ bool GLWidget::initGPUAccelSync()
void GLWidget::paintGL()
{
QOpenGLFunctions *f = openglContext()->functions();
int width = this->width() * devicePixelRatio();
int height = this->height() * devicePixelRatio();
float width = this->width() * devicePixelRatio();
float height = this->height() * devicePixelRatio();
f->glDisable(GL_BLEND);
f->glDisable(GL_DEPTH_TEST);
......@@ -534,7 +532,7 @@ void GLWidget::paintGL()
// Setup an orthographic projection.
QMatrix4x4 projection;
projection.scale(2.0f / (float)width, 2.0f / (float)height);
projection.scale(2.0f / width, 2.0f / height);
m_shader->setUniformValue(m_projectionLocation, projection);
check_error(f);
......@@ -551,10 +549,10 @@ void GLWidget::paintGL()
QVector<QVector2D> vertices;
width = m_rect.width() * devicePixelRatio();
height = m_rect.height() * devicePixelRatio();
vertices << QVector2D(float(-width) / 2.0f, float(-height) / 2.0f);
vertices << QVector2D(float(-width) / 2.0f, float(height) / 2.0f);
vertices << QVector2D(float(width) / 2.0f, float(-height) / 2.0f);
vertices << QVector2D(float(width) / 2.0f, float(height) / 2.0f);
vertices << QVector2D(-width / 2.0f, -height / 2.0f);
vertices << QVector2D(-width / 2.0f, height / 2.0f);
vertices << QVector2D(width / 2.0f, -height / 2.0f);
vertices << QVector2D(width / 2.0f, height / 2.0f);
m_shader->enableAttributeArray(m_vertexLocation);
check_error(f);
m_shader->setAttributeArray(m_vertexLocation, vertices.constData());
......@@ -1594,10 +1592,7 @@ void GLWidget::refreshSceneLayout()
QSize s = pCore->getCurrentFrameSize();
rootObject()->setProperty("profile", s);
rootObject()->setProperty("scalex", (double)m_rect.width() / s.width() * m_zoom);
rootObject()->setProperty("scaley",
(double)m_rect.width() /
(((double)s.height() * m_dar / s.width())) /
s.width() * m_zoom);
rootObject()->setProperty("scaley", (double)m_rect.height() / s.height() * m_zoom);
}
void GLWidget::switchPlay(bool play, double speed)
......@@ -1808,8 +1803,7 @@ void GLWidget::setConsumerProperty(const QString &name, const QString &value)
void GLWidget::updateScaling()
{
#if LIBMLT_VERSION_INT >= MLT_VERSION_PREVIEW_SCALE
QSize profileSize = pCore->getCurrentFrameSize();
int previewHeight = profileSize.height();
int previewHeight = pCore->getCurrentFrameSize().height();
switch (KdenliveSettings::previewScaling()) {
case 2:
previewHeight = qMin(previewHeight, 720);
......@@ -1826,20 +1820,25 @@ void GLWidget::updateScaling()
default:
break;
}
if (previewHeight == profileSize.height()) {
m_profileSize = profileSize;
} else {
int width = previewHeight * pCore->getCurrentDar() / pCore->getCurrentSar();
if (width % 2 > 0) {
width ++;
}
m_profileSize = QSize(width, previewHeight);
int pWidth = previewHeight * pCore->getCurrentDar() / pCore->getCurrentSar();
if (pWidth% 2 > 0) {
pWidth ++;
}
qDebug()<<"==== SWITCHED PROFILE WIDTH TO : "<<m_profileSize.width()<<" = "<<profileSize.width();
m_profileSize = QSize(pWidth, previewHeight);
if (m_consumer) {
m_consumer->set("width", m_profileSize.width());
m_consumer->set("height", m_profileSize.height());
resizeGL(width(), height());
}
#else
int previewHeight = pCore->getCurrentFrameSize().height();
int pWidth = previewHeight * pCore->getCurrentDar() / pCore->getCurrentSar();
if (pWidth% 2 > 0) {
pWidth ++;
}
m_profileSize = QSize(pWidth, previewHeight);
if (m_consumer) {
resizeGL(width(), height());
}
#endif
}
......@@ -57,9 +57,7 @@ void QmlManager::setScene(Kdenlive::MonitorId id, MonitorSceneType type, QSize p
const QFont ft = QFontDatabase::systemFont(QFontDatabase::FixedFont);
m_view->rootContext()->setContextProperty("fixedFont", ft);
double scalex = (double)displayRect.width() / profile.width() * zoom;
double scaley = displayRect.width() /
((double)profile.height() * profileStretch / profile.width()) /
profile.width() * zoom;
double scaley = (double)displayRect.height() / profile.height() * zoom;
switch (type) {
case MonitorSceneGeometry:
m_view->setSource(QUrl(QStringLiteral("qrc:/qml/kdenlivemonitoreffectscene.qml")));
......
......@@ -21,6 +21,7 @@
#include "bin/projectitemmodel.h"
#include "core.h"
#include "utils/thumbnailcache.hpp"
#include "doc/kthumb.h"
#include <QCryptographicHash>
#include <QDebug>
......@@ -87,14 +88,9 @@ QImage ThumbnailProvider::makeThumbnail(const std::shared_ptr<Mlt::Producer> &pr
if (frame == nullptr || !frame->is_valid()) {
return QImage();
}
int ow = 0;
int oh = 0;
mlt_image_format format = mlt_image_rgb24a;
const uchar *image = frame->get_image(format, ow, oh);
if (image) {
QImage temp(ow, oh, QImage::Format_ARGB32);
memcpy(temp.scanLine(0), image, (unsigned)(ow * oh * 4));
return temp.rgbSwapped();
}
return QImage();
// TODO: cache these values ?
int imageHeight = pCore->thumbProfile()->height();
int imageWidth = pCore->thumbProfile()->width();
int fullWidth = imageHeight * pCore->getCurrentDar() + 0.5;
return KThumb::getFrame(frame.data(), imageWidth, imageHeight, fullWidth);
}
......@@ -183,7 +183,7 @@ void ThumbnailCache::storeThumbnail(const QString &binId, int pos, const QImage
QDir thumbFolder = getDir(false, &ok);
if (ok) {
if (!img.save(thumbFolder.absoluteFilePath(key))) {
qDebug() << ".............\nAAAAAAAAAAAARGH ERROR SAVING THUMB";
qDebug() << ".............\n!!!!!!!! ERROR SAVING THUMB in: "<<thumbFolder.absoluteFilePath(key);
}
m_storedOnDisk[binId].push_back(pos);
// if volatile cache also contains this entry, update it
......
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