1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Make huge images work under OpenGL (at least memory-ineficient)

This commit is contained in:
Martin Tůma 2018-08-24 12:26:32 +02:00
parent bbc1d43290
commit 0a9077545b
2 changed files with 24 additions and 3 deletions

View File

@ -1,9 +1,12 @@
#include <QPainter> #include <QPainter>
#include <QPixmapCache>
#include "config.h" #include "config.h"
#include "image.h" #include "image.h"
Image::Image(const QString &fileName) : _img(fileName) #define TILE_SIZE 256
Image::Image(const QString &fileName) : _img(fileName), _fileName(fileName)
{ {
} }
@ -17,8 +20,25 @@ void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags)
QRectF sr(rect.topLeft() * ratio, rect.size() * ratio); QRectF sr(rect.topLeft() * ratio, rect.size() * ratio);
if (flags & Map::OpenGL) { if (flags & Map::OpenGL) {
QImage img(_img.copy(sr.toRect())); for (int i = sr.left()/TILE_SIZE; i <= sr.right()/TILE_SIZE; i++) {
painter->drawImage(rect.topLeft(), img); for (int j = sr.top()/TILE_SIZE; j <= sr.bottom()/TILE_SIZE; j++) {
QString key = _fileName + "-" + QString::number(i) + "_"
+ QString::number(j);
QPoint tl(i * TILE_SIZE, j * TILE_SIZE);
QPixmap pm;
if (!QPixmapCache::find(key, &pm)) {
QRect tile(tl, QSize(TILE_SIZE, TILE_SIZE));
pm = QPixmap::fromImage(_img.copy(tile));
if (!pm.isNull())
QPixmapCache::insert(key, pm);
}
#ifdef ENABLE_HIDPI
pm.setDevicePixelRatio(ratio);
#endif // ENABLE_HIDPI
painter->drawPixmap(tl/ratio, pm);
}
}
} else } else
painter->drawImage(rect.topLeft(), _img, sr); painter->drawImage(rect.topLeft(), _img, sr);
} }

View File

@ -16,6 +16,7 @@ public:
private: private:
QImage _img; QImage _img;
QString _fileName;
}; };
#endif // IMAGE_H #endif // IMAGE_H