From 3924c945d17931703cab58fd6f928a6ceda18d35 Mon Sep 17 00:00:00 2001 From: Vladimir Belyavsky Date: Thu, 14 Mar 2024 20:44:15 +0300 Subject: [PATCH] QMovie: allow only one dimension to be used for scaledSize In 4c21f728374605ff529aa53c63c3d59517098435 we did this for QImageReader. So, to support the same for QMovie, we just need to remove the custom (and very inefficient) scaling for frames. This should be safe since the underlying QImageReader must ensure that the returned image matches the scaled size. [ChangeLog][QtGui][QMovie] Allow only one dimension (width or height) to be set for the scaled size. In this case, the other will be calculated automatically based on the original movie size and maintaining the aspect ratio. Fixes: QTBUG-115039 Change-Id: I50979a75970c79647dbb8c8b4b121266ba033a63 Reviewed-by: Eirik Aavitsland --- src/gui/image/qmovie.cpp | 6 +---- tests/auto/gui/image/qmovie/tst_qmovie.cpp | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp index f5fdc2a0ea..435f1dced9 100644 --- a/src/gui/image/qmovie.cpp +++ b/src/gui/image/qmovie.cpp @@ -449,11 +449,7 @@ bool QMoviePrivate::next() } // Image and delay OK, update internal state currentFrameNumber = nextFrameNumber++; - QSize scaledSize = reader->scaledSize(); - if (scaledSize.isValid() && (scaledSize != info.pixmap.size())) - currentPixmap = QPixmap::fromImage( info.pixmap.toImage().scaled(scaledSize) ); - else - currentPixmap = info.pixmap; + currentPixmap = info.pixmap; if (!speed) return true; diff --git a/tests/auto/gui/image/qmovie/tst_qmovie.cpp b/tests/auto/gui/image/qmovie/tst_qmovie.cpp index fc81063281..c2171d4209 100644 --- a/tests/auto/gui/image/qmovie/tst_qmovie.cpp +++ b/tests/auto/gui/image/qmovie/tst_qmovie.cpp @@ -46,6 +46,9 @@ private slots: #ifndef QT_NO_ICO void multiFrameImage(); #endif + + void setScaledSize_data(); + void setScaledSize(); }; // Testing get/set functions @@ -289,5 +292,33 @@ void tst_QMovie::multiFrameImage() } #endif +void tst_QMovie::setScaledSize_data() +{ + QTest::addColumn("fileName"); + QTest::addColumn("scaledSize"); + QTest::addColumn("expectedSize"); + + QTest::newRow("trolltech (50, 50)") << QString("animations/trolltech.gif") << QSize(50, 50) << QSize(50, 50); + QTest::newRow("trolltech (400, 400)") << QString("animations/trolltech.gif") << QSize(400, 400) << QSize(400, 400); + QTest::newRow("trolltech (50, 0)") << QString("animations/trolltech.gif") << QSize(50, 0) << QSize(50, 25); + QTest::newRow("trolltech (50, -1)") << QString("animations/trolltech.gif") << QSize(50, -1) << QSize(50, 25); + QTest::newRow("trolltech (0, 50)") << QString("animations/trolltech.gif") << QSize(0, 50) << QSize(100, 50); + QTest::newRow("trolltech (-1, 50)") << QString("animations/trolltech.gif") << QSize(-1, 50) << QSize(100, 50); +} + +void tst_QMovie::setScaledSize() +{ + QFETCH(QString, fileName); + QFETCH(QSize, scaledSize); + QFETCH(QSize, expectedSize); + + QMovie movie(QFINDTESTDATA(fileName)); + movie.setScaledSize(scaledSize); + + movie.start(); + QCOMPARE(movie.currentFrameNumber(), 0); + QCOMPARE(movie.currentImage().size(), expectedSize); +} + QTEST_MAIN(tst_QMovie) #include "tst_qmovie.moc"