From c301d995c646c70f8f943e2e4fc293a3e2d29edf Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 21 Jul 2009 17:21:49 +1000 Subject: Add some (disabled) test code for limiting image size. QFxImage et al could benefit from a limit feature, especially for remote images. --- src/declarative/fx/qfxpixmap.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxpixmap.cpp b/src/declarative/fx/qfxpixmap.cpp index ac8a701..e4d79f4 100644 --- a/src/declarative/fx/qfxpixmap.cpp +++ b/src/declarative/fx/qfxpixmap.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qfxpixmap.h" +#include #include #include #include @@ -124,8 +125,30 @@ QFxPixmap::QFxPixmap(const QUrl &url) if ((*iter)->reply->error()) { qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); } else { + QImageReader imgio((*iter)->reply); + +//#define QT_TEST_SCALED_SIZE +#ifdef QT_TEST_SCALED_SIZE + /* + Some mechanism is needed for loading images at a limited size, especially + for remote images. Loading only thumbnails of remote progressive JPEG + images can be efficient. (Qt jpeg handler does not do so currently) + */ + + QSize limit(60,60); + QSize sz = imgio.size(); + if (sz.width() > limit.width() || sz.height() > limit.height()) { + sz.scale(limit,Qt::KeepAspectRatio); + imgio.setScaledSize(sz); + } +#endif + QImage img; - if (img.load((*iter)->reply, 0)) { + if (imgio.read(&img)) { +#ifdef QT_TEST_SCALED_SIZE + if (!sz.isValid()) + img = img.scaled(limit,Qt::KeepAspectRatio); +#endif d->pixmap = QPixmap::fromImage(img); QPixmapCache::insert(key, d->pixmap); } else { -- cgit v0.12