summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-12-23 09:16:41 +1000
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-12-23 09:16:41 +1000
commitbe2acbcd6cfbaa75b502157061c385129e8f0b35 (patch)
tree5b6f36690c5cb357e816c51387aa4d795528ec9d
parent0eabf288f6b05c788f547f761c6e7874856d2703 (diff)
downloadqt4-tools-be2acbcd6cfbaa75b502157061c385129e8f0b35.tar.gz
Use libjpeg's builtin scaler for implementing setScaledSize()
The libjpeg library has builtin support for scaling to 1/2, 1/4, and 1/8 the original size very quickly. Use this in the implementation of setScaledSize() to get close to the desired size and then scale with QImageSmoothScaler the rest of the way. Task-number: QT-2023 Reviewed-by: Daniel Pope
-rw-r--r--src/plugins/imageformats/jpeg/qjpeghandler.cpp5
-rw-r--r--tests/auto/qimagereader/tst_qimagereader.cpp10
2 files changed, 11 insertions, 4 deletions
diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp
index aa239ecb92..8da6610b6b 100644
--- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp
+++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp
@@ -758,10 +758,9 @@ static bool read_jpeg_image(QIODevice *device, QImage *outImage,
quality = 75;
#ifndef QT_NO_IMAGE_SMOOTHSCALE
- // If high quality not required, shrink image during decompression
- if (scaledSize.isValid() && !scaledSize.isEmpty() && quality < HIGH_QUALITY_THRESHOLD) {
+ if (!scaledSize.isEmpty()) {
cinfo.scale_denom = qMin(cinfo.image_width / scaledSize.width(),
- cinfo.image_width / scaledSize.height());
+ cinfo.image_height / scaledSize.height());
if (cinfo.scale_denom < 2) {
cinfo.scale_denom = 1;
} else if (cinfo.scale_denom < 4) {
diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp
index 15b1c1c540..630cc034a3 100644
--- a/tests/auto/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/qimagereader/tst_qimagereader.cpp
@@ -322,7 +322,15 @@ void tst_QImageReader::setScaledSize_data()
QTest::newRow("PPM: test") << "test.ppm" << QSize(10, 10) << QByteArray("ppm");
QTest::newRow("XBM: gnus") << "gnus" << QSize(200, 200) << QByteArray("xbm");
#ifdef QTEST_HAVE_JPEG
- QTest::newRow("JPEG: beavis") << "beavis" << QSize(200, 200) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis A") << "beavis" << QSize(200, 200) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis B") << "beavis" << QSize(175, 175) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis C") << "beavis" << QSize(100, 100) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis D") << "beavis" << QSize(100, 200) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis E") << "beavis" << QSize(200, 100) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis F") << "beavis" << QSize(87, 87) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis G") << "beavis" << QSize(50, 45) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis H") << "beavis" << QSize(43, 43) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis I") << "beavis" << QSize(25, 25) << QByteArray("jpeg");
#endif // QTEST_HAVE_JPEG
#ifdef QTEST_HAVE_GIF
QTest::newRow("GIF: earth") << "earth" << QSize(200, 200) << QByteArray("gif");