1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 19:55: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 <QtEndian>
#include <QPainter> #include <QPainter>
#include <QFileInfo> #include <QFileInfo>
#include <QPixmapCache>
#include "transform.h" #include "transform.h"
#include "rectd.h" #include "rectd.h"
#include "jnxmap.h" #include "jnxmap.h"
@ -212,18 +213,27 @@ int JNXMap::zoomOut()
QPixmap JNXMap::pixmap(const Tile *tile, QFile *file) QPixmap JNXMap::pixmap(const Tile *tile, QFile *file)
{ {
QByteArray ba; QPixmap pm;
ba.resize(tile->size + 2);
ba[0] = (char)0xFF;
ba[1] = (char)0xD8;
char *data = ba.data() + 2;
if (!file->seek(tile->offset)) QString key = file->fileName() + "-" + QString::number(tile->offset);
return QPixmap(); if (!QPixmapCache::find(key, &pm)) {
if (!file->read(data, tile->size)) QByteArray ba;
return QPixmap(); 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) bool JNXMap::cb(Tile *tile, void *context)