mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 19:52:09 +01:00
Improved image/tiles info fetching
This commit is contained in:
parent
ac4ef0631e
commit
bd23120c2c
@ -5,6 +5,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QImageReader>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "rd.h"
|
#include "rd.h"
|
||||||
@ -160,10 +161,11 @@ bool OfflineMap::getImageInfo(const QString &path)
|
|||||||
QFileInfo ii(_imgPath);
|
QFileInfo ii(_imgPath);
|
||||||
if (ii.isRelative())
|
if (ii.isRelative())
|
||||||
_imgPath = path + "/" + _imgPath;
|
_imgPath = path + "/" + _imgPath;
|
||||||
ii = QFileInfo(_imgPath);
|
|
||||||
|
|
||||||
if (!ii.exists()) {
|
QImageReader img(_imgPath);
|
||||||
qWarning("%s: %s: no such image", qPrintable(_name),
|
_size = img.size();
|
||||||
|
if (!_size.isValid()) {
|
||||||
|
qWarning("%s: %s: error reading map image", qPrintable(_name),
|
||||||
qPrintable(ii.absoluteFilePath()));
|
qPrintable(ii.absoluteFilePath()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -173,6 +175,11 @@ bool OfflineMap::getImageInfo(const QString &path)
|
|||||||
|
|
||||||
bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
||||||
{
|
{
|
||||||
|
if (!_size.isValid()) {
|
||||||
|
qWarning("%s: missing total image size (IWH)", qPrintable(_name));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (tiles.isEmpty()) {
|
if (tiles.isEmpty()) {
|
||||||
qWarning("%s: empty tile set", qPrintable(_name));
|
qWarning("%s: empty tile set", qPrintable(_name));
|
||||||
return false;
|
return false;
|
||||||
@ -183,29 +190,21 @@ bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
|||||||
if (tiles.at(i).contains(rx)) {
|
if (tiles.at(i).contains(rx)) {
|
||||||
_tileName = QString(tiles.at(i)).replace(rx, "_%1_%2.");
|
_tileName = QString(tiles.at(i)).replace(rx, "_%1_%2.");
|
||||||
|
|
||||||
QImage tile;
|
|
||||||
if (_tar.isOpen()) {
|
if (_tar.isOpen()) {
|
||||||
QByteArray ba = _tar.file(tiles.at(i));
|
QByteArray ba = _tar.file(tiles.at(i));
|
||||||
tile = QImage::fromData(ba);
|
QBuffer buffer(&ba);
|
||||||
|
_tileSize = QImageReader(&buffer).size();
|
||||||
} else {
|
} else {
|
||||||
_tileName = path + "/" + _tileName;
|
_tileName = path + "/" + _tileName;
|
||||||
tile = QImage(path + "/" + tiles.at(i));
|
_tileSize = QImageReader(path + "/" + tiles.at(i)).size();
|
||||||
}
|
}
|
||||||
if (tile.isNull()) {
|
if (!_tileSize.isValid()) {
|
||||||
qWarning("%s: error retrieving tile size: %s: invalid image",
|
qWarning("%s: error retrieving tile size: %s: invalid image",
|
||||||
qPrintable(_name), qPrintable(QFileInfo(tiles.at(i))
|
qPrintable(_name), qPrintable(QFileInfo(tiles.at(i))
|
||||||
.fileName()));
|
.fileName()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tileSize = tile.size();
|
|
||||||
|
|
||||||
if (!_size.isValid()) {
|
|
||||||
qWarning("%s: missing or invalid image size (IWH)",
|
|
||||||
qPrintable(_name));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,11 +292,8 @@ void OfflineMap::load()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_img = new QImage(_imgPath);
|
_img = new QImage(_imgPath);
|
||||||
if (!_img->isNull()) {
|
if (_img->isNull())
|
||||||
if (!_size.isValid())
|
qWarning("%s: error loading map image", qPrintable(_imgPath));
|
||||||
_size = _img->size();
|
|
||||||
} else
|
|
||||||
qWarning("%s: error loading map image", qPrintable(_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OfflineMap::unload()
|
void OfflineMap::unload()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user