1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Added missing pixmap caching

This commit is contained in:
Martin Tůma 2018-05-30 22:10:35 +02:00
parent 2c816a509b
commit ca7016176f

View File

@ -1,6 +1,7 @@
#include <QtEndian>
#include <QPainter>
#include <QFileInfo>
#include <QPixmapCache>
#include "transform.h"
#include "rectd.h"
#include "jnxmap.h"
@ -212,18 +213,27 @@ int JNXMap::zoomOut()
QPixmap JNXMap::pixmap(const Tile *tile, QFile *file)
{
QByteArray ba;
ba.resize(tile->size + 2);
ba[0] = (char)0xFF;
ba[1] = (char)0xD8;
char *data = ba.data() + 2;
QPixmap pm;
if (!file->seek(tile->offset))
return QPixmap();
if (!file->read(data, tile->size))
return QPixmap();
QString key = file->fileName() + "-" + QString::number(tile->offset);
if (!QPixmapCache::find(key, &pm)) {
QByteArray ba;
ba.resize(tile->size + 2);
ba[0] = (char)0xFF;
ba[1] = (char)0xD8;
char *data = ba.data() + 2;
return QPixmap::fromImage(QImage::fromData(ba));
if (!file->seek(tile->offset))
return QPixmap();
if (!file->read(data, tile->size))
return QPixmap();
pm = QPixmap::fromImage(QImage::fromData(ba));
if (!pm.isNull())
QPixmapCache::insert(key, pm);
}
return pm;
}
bool JNXMap::cb(Tile *tile, void *context)