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:
parent
bbc1d43290
commit
0a9077545b
@ -1,9 +1,12 @@
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
#include "config.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);
|
||||
|
||||
if (flags & Map::OpenGL) {
|
||||
QImage img(_img.copy(sr.toRect()));
|
||||
painter->drawImage(rect.topLeft(), img);
|
||||
for (int i = sr.left()/TILE_SIZE; i <= sr.right()/TILE_SIZE; i++) {
|
||||
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
|
||||
painter->drawImage(rect.topLeft(), _img, sr);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ public:
|
||||
|
||||
private:
|
||||
QImage _img;
|
||||
QString _fileName;
|
||||
};
|
||||
|
||||
#endif // IMAGE_H
|
||||
|
Loading…
Reference in New Issue
Block a user