Added support for uncompressed PBF files

This commit is contained in:
Martin Tůma 2018-11-10 00:14:36 +01:00
parent 678439cf52
commit 71895813ab

View File

@ -9,6 +9,9 @@
#define TILE_SIZE 256 #define TILE_SIZE 256
#define GZIP_MAGIC 0x1F8B0800 #define GZIP_MAGIC 0x1F8B0800
#define GZIP_MAGIC_MASK 0xFFFFFF00
#define PBF_MAGIC 0x1A000000
#define PBF_MAGIC_MASK 0xFF000000
bool PBFHandler::canRead() const bool PBFHandler::canRead() const
{ {
@ -19,13 +22,30 @@ bool PBFHandler::canRead(QIODevice *device)
{ {
quint32 magic; quint32 magic;
qint64 size = device->peek((char*)&magic, sizeof(magic)); qint64 size = device->peek((char*)&magic, sizeof(magic));
return (size == sizeof(magic) if (size != sizeof(magic))
&& (qFromBigEndian(magic) & 0xFFFFFF00) == GZIP_MAGIC); return false;
if ((qFromBigEndian(magic) & GZIP_MAGIC_MASK) == GZIP_MAGIC)
return true;
if ((qFromBigEndian(magic) & PBF_MAGIC_MASK) == PBF_MAGIC)
return true;
return false;
} }
bool PBFHandler::read(QImage *image) bool PBFHandler::read(QImage *image)
{ {
QByteArray ba = Gzip::uncompress(device()->readAll()); quint32 magic;
qint64 size = device()->peek((char*)&magic, sizeof(magic));
if (size != sizeof(magic))
return false;
QByteArray ba;
if ((qFromBigEndian(magic) & GZIP_MAGIC_MASK) == GZIP_MAGIC)
ba = Gzip::uncompress(device()->readAll());
else if ((qFromBigEndian(magic) & PBF_MAGIC_MASK) == PBF_MAGIC)
ba = device()->readAll();
if (ba.isNull()) if (ba.isNull())
return false; return false;