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

Code cleanup

This commit is contained in:
Martin Tůma 2022-03-25 19:28:32 +01:00
parent 80dbb99091
commit 1385482689
13 changed files with 183 additions and 187 deletions

View File

@ -113,6 +113,7 @@ HEADERS += src/common/config.h \
src/GUI/timezoneinfo.h \ src/GUI/timezoneinfo.h \
src/GUI/passwordedit.h \ src/GUI/passwordedit.h \
src/data/twonavparser.h \ src/data/twonavparser.h \
src/map/IMG/section.h \
src/map/proj/polyconic.h \ src/map/proj/polyconic.h \
src/map/proj/webmercator.h \ src/map/proj/webmercator.h \
src/map/proj/transversemercator.h \ src/map/proj/transversemercator.h \

View File

@ -5,7 +5,7 @@ using namespace IMG;
bool HuffmanBuffer::load(const RGNFile *rgn, SubFile::Handle &rgnHdl) bool HuffmanBuffer::load(const RGNFile *rgn, SubFile::Handle &rgnHdl)
{ {
quint32 recordSize, recordOffset = rgn->dictOffset(); quint32 recordSize, recordOffset = rgn->dict().offset;
for (int i = 0; i <= _id; i++) { for (int i = 0; i <= _id; i++) {
if (!rgn->seek(rgnHdl, recordOffset)) if (!rgn->seek(rgnHdl, recordOffset))
@ -13,7 +13,7 @@ bool HuffmanBuffer::load(const RGNFile *rgn, SubFile::Handle &rgnHdl)
if (!rgn->readVUInt32(rgnHdl, recordSize)) if (!rgn->readVUInt32(rgnHdl, recordSize))
return false; return false;
recordOffset = rgn->pos(rgnHdl) + recordSize; recordOffset = rgn->pos(rgnHdl) + recordSize;
if (recordOffset > rgn->dictOffset() + rgn->dictSize()) if (recordOffset > rgn->dict().offset + rgn->dict().size)
return false; return false;
}; };

View File

@ -77,11 +77,11 @@ bool LBLFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
quint16 hdrLen, codepage; quint16 hdrLen, codepage;
if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen) if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen)
&& seek(hdl, _gmpOffset + 0x15) && readUInt32(hdl, _offset) && seek(hdl, _gmpOffset + 0x15) && readUInt32(hdl, _base.offset)
&& readUInt32(hdl, _size) && readByte(hdl, &_multiplier) && readUInt32(hdl, _base.size) && readByte(hdl, &_shift)
&& readByte(hdl, &_encoding) && seek(hdl, _gmpOffset + 0x57) && readByte(hdl, &_encoding) && seek(hdl, _gmpOffset + 0x57)
&& readUInt32(hdl, _poiOffset) && readUInt32(hdl, _poiSize) && readUInt32(hdl, _poi.offset) && readUInt32(hdl, _poi.size)
&& readByte(hdl, &_poiMultiplier) && seek(hdl, _gmpOffset + 0xAA) && readByte(hdl, &_poiShift) && seek(hdl, _gmpOffset + 0xAA)
&& readUInt16(hdl, codepage))) && readUInt16(hdl, codepage)))
return false; return false;
@ -107,8 +107,8 @@ bool LBLFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
quint32 offset, recordSize, size, flags; quint32 offset, recordSize, size, flags;
if (!(seek(hdl, _gmpOffset + 0x184) && readUInt32(hdl, offset) if (!(seek(hdl, _gmpOffset + 0x184) && readUInt32(hdl, offset)
&& readUInt32(hdl, size) && readUInt16(hdl, recordSize) && readUInt32(hdl, size) && readUInt16(hdl, recordSize)
&& readUInt32(hdl, flags) && readUInt32(hdl, _imgOffset) && readUInt32(hdl, flags) && readUInt32(hdl, _img.offset)
&& readUInt32(hdl, _imgSize))) && readUInt32(hdl, _img.size)))
return false; return false;
if (size && recordSize) if (size && recordSize)
@ -278,7 +278,7 @@ Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl,
for (int i = 0; i < str.size(); i++) { for (int i = 0; i < str.size(); i++) {
quint32 val = _table[str.at(i)]; quint32 val = _table[str.at(i)];
if (val) { if (val) {
quint32 off = _offset + ((val & 0x7fffff) << _multiplier); quint32 off = _base.offset + ((val & 0x7fffff) << _shift);
if (!seek(hdl, off)) if (!seek(hdl, off))
return Label(); return Label();
@ -287,7 +287,8 @@ Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl,
else if (str2.size()) else if (str2.size())
str2.append(' '); str2.append(' ');
if (!_huffmanText->decode(this, hdl, _offset + _size - off, str2)) if (!_huffmanText->decode(this, hdl, _base.offset + _base.size - off,
str2))
return Label(); return Label();
} else { } else {
if (str.at(i) == 7) { if (str.at(i) == 7) {
@ -309,21 +310,21 @@ Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize,
quint32 labelOffset; quint32 labelOffset;
if (poi) { if (poi) {
quint32 poiOffset; quint32 poiOffset;
if (!(_poiSize >= (offset << _poiMultiplier) if (!(_poi.size >= (offset << _poiShift)
&& seek(hdl, _poiOffset + (offset << _poiMultiplier)) && seek(hdl, _poi.offset + (offset << _poiShift))
&& readUInt24(hdl, poiOffset) && (poiOffset & 0x3FFFFF))) && readUInt24(hdl, poiOffset) && (poiOffset & 0x3FFFFF)))
return Label(); return Label();
labelOffset = _offset + ((poiOffset & 0x3FFFFF) << _multiplier); labelOffset = _base.offset + ((poiOffset & 0x3FFFFF) << _shift);
} else } else
labelOffset = _offset + (offset << _multiplier); labelOffset = _base.offset + (offset << _shift);
if (labelOffset > _offset + _size) if (labelOffset > _base.offset + _base.size)
return Label(); return Label();
if (!seek(hdl, labelOffset)) if (!seek(hdl, labelOffset))
return Label(); return Label();
return label(hdl, this, hdl, _offset + _size - labelOffset, capitalize, return label(hdl, this, hdl, _base.offset + _base.size - labelOffset,
convert); capitalize, convert);
} }
Label LBLFile::label(Handle &hdl, const SubFile *file, Handle &fileHdl, Label LBLFile::label(Handle &hdl, const SubFile *file, Handle &fileHdl,
@ -348,7 +349,7 @@ bool LBLFile::loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
quint32 prev, cur; quint32 prev, cur;
_imgCount = size / recordSize; _imgCount = size / recordSize;
_imgOffsetIdSize = byteSize(_imgCount - 1); _imgIdSize = byteSize(_imgCount - 1);
_rasters = new Image[_imgCount]; _rasters = new Image[_imgCount];
if (!(seek(hdl, offset) && readVUInt32(hdl, recordSize, prev))) if (!(seek(hdl, offset) && readVUInt32(hdl, recordSize, prev)))
@ -365,7 +366,7 @@ bool LBLFile::loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
} }
_rasters[_imgCount-1].offset = prev; _rasters[_imgCount-1].offset = prev;
_rasters[_imgCount-1].size = _imgSize - prev; _rasters[_imgCount-1].size = _img.size - prev;
return true; return true;
} }
@ -377,7 +378,7 @@ QPixmap LBLFile::image(Handle &hdl, quint32 id) const
if (id >= _imgCount) if (id >= _imgCount)
return pm; return pm;
if (!seek(hdl, _imgOffset + _rasters[id].offset)) if (!seek(hdl, _img.offset + _rasters[id].offset))
return pm; return pm;
QByteArray ba; QByteArray ba;
ba.resize(_rasters[id].size); ba.resize(_rasters[id].size);

View File

@ -3,6 +3,7 @@
#include <QPixmap> #include <QPixmap>
#include "common/textcodec.h" #include "common/textcodec.h"
#include "section.h"
#include "subfile.h" #include "subfile.h"
#include "label.h" #include "label.h"
@ -15,17 +16,14 @@ class LBLFile : public SubFile
{ {
public: public:
LBLFile(const IMGData *img) LBLFile(const IMGData *img)
: SubFile(img), _huffmanText(0), _table(0), _rasters(0), _offset(0), : SubFile(img), _huffmanText(0), _table(0), _rasters(0), _imgIdSize(0),
_size(0), _poiOffset(0), _poiSize(0), _imgOffsetIdSize(0), _poiShift(0), _shift(0), _encoding(0) {}
_poiMultiplier(0), _multiplier(0), _encoding(0) {}
LBLFile(const QString *path) LBLFile(const QString *path)
: SubFile(path), _huffmanText(0), _table(0), _rasters(0), _offset(0), : SubFile(path), _huffmanText(0), _table(0), _rasters(0), _imgIdSize(0),
_size(0), _poiOffset(0), _poiSize(0), _imgOffsetIdSize(0), _poiShift(0), _shift(0), _encoding(0) {}
_poiMultiplier(0), _multiplier(0), _encoding(0) {} LBLFile(const SubFile *gmp, quint32 offset)
LBLFile(const SubFile *gmp, quint32 offset) : SubFile(gmp, offset), : SubFile(gmp, offset), _huffmanText(0), _table(0), _rasters(0),
_huffmanText(0), _table(0), _rasters(0), _offset(0), _size(0), _imgIdSize(0), _poiShift(0), _shift(0), _encoding(0) {}
_poiOffset(0), _poiSize(0), _imgOffsetIdSize(0), _poiMultiplier(0),
_multiplier(0), _encoding(0) {}
~LBLFile(); ~LBLFile();
bool load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl); bool load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl);
@ -36,7 +34,7 @@ public:
Label label(Handle &hdl, const SubFile *file, Handle &fileHdl, Label label(Handle &hdl, const SubFile *file, Handle &fileHdl,
quint32 size, bool capitalize = true, bool convert = false) const; quint32 size, bool capitalize = true, bool convert = false) const;
quint8 imageIdSize() const {return _imgOffsetIdSize;} quint8 imageIdSize() const {return _imgIdSize;}
QPixmap image(Handle &hdl, quint32 id) const; QPixmap image(Handle &hdl, quint32 id) const;
private: private:
@ -60,16 +58,11 @@ private:
quint32 *_table; quint32 *_table;
Image *_rasters; Image *_rasters;
TextCodec _codec; TextCodec _codec;
quint32 _offset; Section _base, _poi, _img;
quint32 _size;
quint32 _poiOffset;
quint32 _poiSize;
quint32 _imgOffset;
quint32 _imgSize;
quint32 _imgCount; quint32 _imgCount;
quint8 _imgOffsetIdSize; quint8 _imgIdSize;
quint8 _poiMultiplier; quint8 _poiShift;
quint8 _multiplier; quint8 _shift;
quint8 _encoding; quint8 _encoding;
}; };

View File

@ -330,7 +330,7 @@ bool NETFile::linkLabel(Handle &hdl, quint32 offset,
{ {
if (!seek(hdl, offset)) if (!seek(hdl, offset))
return false; return false;
BitStream1 bs(*this, hdl, _linksSize - (offset - _linksOffset)); BitStream1 bs(*this, hdl, _links.size - (offset - _links.offset));
quint32 flags, labelPtr; quint32 flags, labelPtr;
if (!bs.read(8, flags)) if (!bs.read(8, flags))
@ -351,20 +351,20 @@ bool NETFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
quint16 hdrLen; quint16 hdrLen;
if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen) if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen)
&& seek(hdl, _gmpOffset + 0x15) && readUInt32(hdl, _offset) && seek(hdl, _gmpOffset + 0x15) && readUInt32(hdl, _base.offset)
&& readUInt32(hdl, _size) && readByte(hdl, &_shift))) && readUInt32(hdl, _base.size) && readByte(hdl, &_netShift)))
return false; return false;
if (hdrLen >= 0x4C) { if (hdrLen >= 0x4C) {
quint32 info; quint32 info;
if (!(seek(hdl, _gmpOffset + 0x37) && readUInt32(hdl, info))) if (!(seek(hdl, _gmpOffset + 0x37) && readUInt32(hdl, info)))
return false; return false;
if (!(seek(hdl, _gmpOffset + 0x43) && readUInt32(hdl, _linksOffset) if (!(seek(hdl, _gmpOffset + 0x43) && readUInt32(hdl, _links.offset)
&& readUInt32(hdl, _linksSize) && readByte(hdl, &_linksShift))) && readUInt32(hdl, _links.size) && readByte(hdl, &_linksShift)))
return false; return false;
quint8 tableId = ((info >> 2) & 0x0F); quint8 tableId = ((info >> 2) & 0x0F);
if (_linksSize && (!rgn->huffmanTable() || rgn->huffmanTable()->id() if (_links.size && (!rgn->huffmanTable() || rgn->huffmanTable()->id()
!= tableId)) { != tableId)) {
_huffmanTable = new HuffmanTable(tableId); _huffmanTable = new HuffmanTable(tableId);
if (!_huffmanTable->load(rgn, rgnHdl)) if (!_huffmanTable->load(rgn, rgnHdl))
@ -401,12 +401,12 @@ bool NETFile::link(const SubDiv *subdiv, quint32 shift, Handle &hdl,
if (!nod->linkInfo(nodHdl, blockInfo, linkId, linkInfo)) if (!nod->linkInfo(nodHdl, blockInfo, linkId, linkInfo))
return false; return false;
quint32 linkOffset = _linksOffset + (linkInfo.linkOffset << _linksShift); quint32 linkOffset = _links.offset + (linkInfo.linkOffset << _linksShift);
if (linkOffset > _linksOffset + _linksSize) if (linkOffset > _links.offset + _links.size)
return false; return false;
if (!seek(hdl, linkOffset)) if (!seek(hdl, linkOffset))
return false; return false;
BitStream4R bs(*this, hdl, linkOffset - _linksOffset); BitStream4R bs(*this, hdl, linkOffset - _links.offset);
QVector<quint16> ca; QVector<quint16> ca;
quint16 mask = 0; quint16 mask = 0;
quint32 size; quint32 size;
@ -484,7 +484,7 @@ bool NETFile::link(const SubDiv *subdiv, quint32 shift, Handle &hdl,
bool NETFile::lblOffset(Handle &hdl, quint32 netOffset, quint32 &lblOffset) const bool NETFile::lblOffset(Handle &hdl, quint32 netOffset, quint32 &lblOffset) const
{ {
if (!(seek(hdl, _offset + (netOffset << _shift)) if (!(seek(hdl, _base.offset + (netOffset << _netShift))
&& readUInt24(hdl, lblOffset))) && readUInt24(hdl, lblOffset)))
return false; return false;

View File

@ -1,6 +1,7 @@
#ifndef IMG_NETFILE_H #ifndef IMG_NETFILE_H
#define IMG_NETFILE_H #define IMG_NETFILE_H
#include "section.h"
#include "subfile.h" #include "subfile.h"
#include "nodfile.h" #include "nodfile.h"
@ -15,15 +16,13 @@ class BitStream4R;
class NETFile : public SubFile class NETFile : public SubFile
{ {
public: public:
NETFile(const IMGData *img) : SubFile(img), _huffmanTable(0), _tp(0), NETFile(const IMGData *img)
_offset(0), _size(0), _linksOffset(0), _linksSize(0), _shift(0), : SubFile(img), _huffmanTable(0), _tp(0), _netShift(0), _linksShift(0) {}
NETFile(const QString *path)
: SubFile(path), _huffmanTable(0), _tp(0), _netShift(0), _linksShift(0) {}
NETFile(const SubFile *gmp, quint32 offset)
: SubFile(gmp, offset), _huffmanTable(0), _tp(0), _netShift(0),
_linksShift(0) {} _linksShift(0) {}
NETFile(const QString *path) : SubFile(path), _huffmanTable(0), _tp(0),
_offset(0), _size(0), _linksOffset(0), _linksSize(0), _shift(0),
_linksShift(0) {}
NETFile(const SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
_huffmanTable(0), _tp(0), _offset(0), _size(0), _linksOffset(0),
_linksSize(0), _shift(0), _linksShift(0) {}
~NETFile(); ~NETFile();
bool load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl); bool load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl);
@ -34,7 +33,7 @@ public:
const NODFile *nod, Handle &nodHdl2, Handle &nodHdl, const LBLFile *lbl, const NODFile *nod, Handle &nodHdl2, Handle &nodHdl, const LBLFile *lbl,
Handle &lblHdl, const NODFile::BlockInfo &blockInfo, quint8 linkId, Handle &lblHdl, const NODFile::BlockInfo &blockInfo, quint8 linkId,
quint8 lineId, QList<MapData::Poly> *lines) const; quint8 lineId, QList<MapData::Poly> *lines) const;
bool hasLinks() const {return (_linksSize > 0);} bool hasLinks() const {return (_links.size > 0);}
private: private:
bool linkLabel(Handle &hdl, quint32 offset, const LBLFile *lbl, bool linkLabel(Handle &hdl, quint32 offset, const LBLFile *lbl,
@ -47,8 +46,8 @@ private:
HuffmanTable *_huffmanTable; HuffmanTable *_huffmanTable;
const HuffmanTable *_tp; const HuffmanTable *_tp;
quint32 _offset, _size, _linksOffset, _linksSize; Section _base, _links;
quint8 _shift, _linksShift; quint8 _netShift, _linksShift;
}; };
} }

View File

@ -96,15 +96,15 @@ bool NODFile::load(Handle &hdl)
&& readByte(hdl, &_blockShift) && readByte(hdl, &_nodeShift))) && readByte(hdl, &_blockShift) && readByte(hdl, &_nodeShift)))
return false; return false;
if (!(seek(hdl, _gmpOffset + 0x67) && readUInt32(hdl, _blockOffset) if (!(seek(hdl, _gmpOffset + 0x67) && readUInt32(hdl, _block.offset)
&& readUInt32(hdl, _blockSize) && readUInt16(hdl, _blockRecordSize) && readUInt32(hdl, _block.size) && readUInt16(hdl, _blockRecordSize)
&& readUInt32(hdl, _indexOffset) && readUInt32(hdl, _indexSize) && readUInt32(hdl, _index.offset) && readUInt32(hdl, _index.size)
&& readUInt16(hdl, _indexRecordSize) && readUInt32(hdl, _indexFlags))) && readUInt16(hdl, _indexRecordSize) && readUInt32(hdl, _indexFlags)))
return false; return false;
if (!_indexRecordSize || _indexSize < _indexRecordSize) if (!_indexRecordSize || _index.size < _indexRecordSize)
return false; return false;
quint32 indexCount = _indexSize / _indexRecordSize; quint32 indexCount = _index.size / _indexRecordSize;
_indexIdSize = byteSize(indexCount - 1); _indexIdSize = byteSize(indexCount - 1);
} }
@ -116,7 +116,7 @@ bool NODFile::readBlock(Handle &hdl, quint32 blockOffset,
{ {
blockInfo.offset = blockOffset; blockInfo.offset = blockOffset;
return (seek(hdl, blockInfo.offset + _blockOffset) return (seek(hdl, blockInfo.offset + _block.offset)
&& readUInt16(hdl, blockInfo.hdr.flags) && readUInt16(hdl, blockInfo.hdr.flags)
&& readUInt32(hdl, blockInfo.hdr.nodeLonBase) && readUInt32(hdl, blockInfo.hdr.nodeLonBase)
&& readUInt32(hdl, blockInfo.hdr.nodeLatBase) && readUInt32(hdl, blockInfo.hdr.nodeLatBase)
@ -130,10 +130,10 @@ bool NODFile::readBlock(Handle &hdl, quint32 blockOffset,
bool NODFile::blockInfo(Handle &hdl, quint32 blockId, BlockInfo &blockInfo) const bool NODFile::blockInfo(Handle &hdl, quint32 blockId, BlockInfo &blockInfo) const
{ {
quint32 blockOffset; quint32 blockOffset;
quint32 offset = _indexRecordSize * blockId + _indexOffset; quint32 offset = _indexRecordSize * blockId + _index.offset;
quint32 offsetSize = (_indexFlags & 3) + 1; quint32 offsetSize = (_indexFlags & 3) + 1;
if (offset > _indexOffset + _indexSize) if (offset > _index.offset + _index.size)
return false; return false;
if (!(seek(hdl, offset) && readVUInt32(hdl, offsetSize, blockOffset))) if (!(seek(hdl, offset) && readVUInt32(hdl, offsetSize, blockOffset)))
return false; return false;
@ -147,19 +147,19 @@ bool NODFile::linkInfo(Handle &hdl, const BlockInfo &blockInfo, quint32 linkId,
if (linkId >= blockInfo.hdr.linksCount) if (linkId >= blockInfo.hdr.linksCount)
return false; return false;
quint32 infoOffset = _blockOffset + blockInfo.offset + blockInfo.hdr.size() quint32 infoOffset = _block.offset + blockInfo.offset + blockInfo.hdr.size()
+ ((blockInfo.hdr.linkInfoSize * linkId) >> 3); + ((blockInfo.hdr.linkInfoSize * linkId) >> 3);
quint32 s1 = ((blockInfo.hdr.flags >> 2) & 0x1f) + 8; quint32 s1 = ((blockInfo.hdr.flags >> 2) & 0x1f) + 8;
quint32 s2 = (blockInfo.hdr.flags >> 7) & 0xf; quint32 s2 = (blockInfo.hdr.flags >> 7) & 0xf;
quint32 skip = (blockInfo.hdr.linkInfoSize * linkId) & 7; quint32 skip = (blockInfo.hdr.linkInfoSize * linkId) & 7;
if (infoOffset > _blockOffset + _blockSize || infoOffset < blockInfo.offset) if (infoOffset > _block.offset + _block.size || infoOffset < blockInfo.offset)
return false; return false;
if (!seek(hdl, infoOffset)) if (!seek(hdl, infoOffset))
return false; return false;
quint32 padding; quint32 padding;
BitStream1 bs(*this, hdl, _blockOffset + _blockSize - infoOffset); BitStream1 bs(*this, hdl, _block.offset + _block.size - infoOffset);
if (!(bs.read(skip, padding) && bs.read(0xc, linkInfo.flags))) if (!(bs.read(skip, padding) && bs.read(0xc, linkInfo.flags)))
return false; return false;
@ -183,13 +183,13 @@ bool NODFile::linkInfo(Handle &hdl, const BlockInfo &blockInfo, quint32 linkId,
bool NODFile::nodeInfo(Handle &hdl, const BlockInfo &blockInfo, bool NODFile::nodeInfo(Handle &hdl, const BlockInfo &blockInfo,
quint32 nodeOffset, NodeInfo &nodeInfo) const quint32 nodeOffset, NodeInfo &nodeInfo) const
{ {
quint32 infoOffset = (nodeOffset << _nodeShift) + _blockOffset; quint32 infoOffset = (nodeOffset << _nodeShift) + _block.offset;
if (infoOffset > _blockOffset + _blockSize || infoOffset < blockInfo.offset) if (infoOffset > _block.offset + _block.size || infoOffset < blockInfo.offset)
return false; return false;
if (!seek(hdl, infoOffset)) if (!seek(hdl, infoOffset))
return false; return false;
BitStream1 bs(*this, hdl, _blockOffset + _blockSize - infoOffset); BitStream1 bs(*this, hdl, _block.offset + _block.size - infoOffset);
if (!bs.read(8, nodeInfo.flags)) if (!bs.read(8, nodeInfo.flags))
return false; return false;
@ -234,7 +234,7 @@ bool NODFile::nodeOffset(Handle &hdl, const BlockInfo &blockInfo,
if (nodeId >= blockInfo.hdr.nodesCount) if (nodeId >= blockInfo.hdr.nodesCount)
return false; return false;
quint32 offset = _blockOffset + blockInfo.offset + blockInfo.hdr.size() quint32 offset = _block.offset + blockInfo.offset + blockInfo.hdr.size()
+ bs(blockInfo.hdr.linksCount * blockInfo.hdr.linkInfoSize) + bs(blockInfo.hdr.linksCount * blockInfo.hdr.linkInfoSize)
+ nodeId * 3; + nodeId * 3;
@ -245,12 +245,12 @@ bool NODFile::nodeBlock(Handle &hdl, quint32 nodeOffset,
BlockInfo &blockInfo) const BlockInfo &blockInfo) const
{ {
int low = 0; int low = 0;
int high = _indexSize / _indexRecordSize - 1; int high = _index.size / _indexRecordSize - 1;
quint32 offsetSize = (_indexFlags & 3) + 1; quint32 offsetSize = (_indexFlags & 3) + 1;
while (low <= high) { while (low <= high) {
int m = ((low + high) / 2); int m = ((low + high) / 2);
quint32 offset = _indexRecordSize * m + _indexOffset; quint32 offset = _indexRecordSize * m + _index.offset;
quint32 blockOffset, prevBlockOffset; quint32 blockOffset, prevBlockOffset;
if (m > 0) { if (m > 0) {
@ -282,11 +282,11 @@ bool NODFile::nodeBlock(Handle &hdl, quint32 nodeOffset,
bool NODFile::absAdjInfo(Handle &hdl, AdjacencyInfo &adj) const bool NODFile::absAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
{ {
quint32 infoOffset = (adj.nodeOffset << _nodeShift) + _blockOffset quint32 infoOffset = (adj.nodeOffset << _nodeShift) + _block.offset
+ adj.nodeInfo.bytes; + adj.nodeInfo.bytes;
if (!seek(hdl, infoOffset)) if (!seek(hdl, infoOffset))
return false; return false;
BitStream1 bs(*this, hdl, _blockOffset + _blockSize - infoOffset); BitStream1 bs(*this, hdl, _block.offset + _block.size - infoOffset);
quint8 linkId = adj.blockInfo.hdr.linksCount; quint8 linkId = adj.blockInfo.hdr.linksCount;
quint32 m2p = 2; quint32 m2p = 2;
@ -386,12 +386,12 @@ bool NODFile::absAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
bool NODFile::relAdjInfo(Handle &hdl, AdjacencyInfo &adj) const bool NODFile::relAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
{ {
quint32 infoOffset = (adj.nodeOffset << _nodeShift) + _blockOffset quint32 infoOffset = (adj.nodeOffset << _nodeShift) + _block.offset
+ adj.nodeInfo.bytes; + adj.nodeInfo.bytes;
if (!seek(hdl, infoOffset)) if (!seek(hdl, infoOffset))
return false; return false;
BitStream1 bs(*this, hdl, _blockOffset + _blockSize - infoOffset); BitStream1 bs(*this, hdl, _block.offset + _block.size - infoOffset);
quint32 linkId = adj.blockInfo.hdr.linksCount; quint32 linkId = adj.blockInfo.hdr.linksCount;
quint32 skip = 8; quint32 skip = 8;
@ -485,8 +485,7 @@ int NODFile::nextNode(Handle &hdl, AdjacencyInfo &adjInfo) const
if (adjInfo.nodeOffset == 0xFFFFFFFF) if (adjInfo.nodeOffset == 0xFFFFFFFF)
return 1; return 1;
if (!nodeInfo(hdl, adjInfo.blockInfo, adjInfo.nodeOffset, if (!nodeInfo(hdl, adjInfo.blockInfo, adjInfo.nodeOffset, adjInfo.nodeInfo))
adjInfo.nodeInfo))
return -1; return -1;
if (!adjacencyInfo(hdl, adjInfo)) if (!adjacencyInfo(hdl, adjInfo))
return -1; return -1;
@ -497,7 +496,7 @@ int NODFile::nextNode(Handle &hdl, AdjacencyInfo &adjInfo) const
bool NODFile::linkType(Handle &hdl, const BlockInfo &blockInfo, quint8 linkId, bool NODFile::linkType(Handle &hdl, const BlockInfo &blockInfo, quint8 linkId,
quint32 &type) const quint32 &type) const
{ {
quint32 offset = _blockOffset + blockInfo.offset + blockInfo.hdr.size() quint32 offset = _block.offset + blockInfo.offset + blockInfo.hdr.size()
+ bs(blockInfo.hdr.linksCount * blockInfo.hdr.linkInfoSize) + bs(blockInfo.hdr.linksCount * blockInfo.hdr.linkInfoSize)
+ blockInfo.hdr.nodesCount * 3; + blockInfo.hdr.nodesCount * 3;
int low = 0; int low = 0;

View File

@ -1,6 +1,7 @@
#ifndef IMG_NODFILE_H #ifndef IMG_NODFILE_H
#define IMG_NODFILE_H #define IMG_NODFILE_H
#include "section.h"
#include "subfile.h" #include "subfile.h"
namespace IMG { namespace IMG {
@ -59,16 +60,15 @@ public:
bool eog; bool eog;
}; };
NODFile(const IMGData *img) : SubFile(img), _indexOffset(0), _indexSize(0), NODFile(const IMGData *img)
_indexFlags(0), _blockOffset(0), _blockSize(0), _indexRecordSize(0), : SubFile(img), _indexFlags(0), _indexRecordSize(0), _blockRecordSize(0),
_blockShift(0), _nodeShift(0), _indexIdSize(0) {}
NODFile(const QString *path)
: SubFile(path), _indexFlags(0), _indexRecordSize(0), _blockRecordSize(0),
_blockShift(0), _nodeShift(0), _indexIdSize(0) {}
NODFile(const SubFile *gmp, quint32 offset)
: SubFile(gmp, offset), _indexFlags(0), _indexRecordSize(0),
_blockRecordSize(0), _blockShift(0), _nodeShift(0), _indexIdSize(0) {} _blockRecordSize(0), _blockShift(0), _nodeShift(0), _indexIdSize(0) {}
NODFile(const QString *path) : SubFile(path), _indexOffset(0), _indexSize(0),
_indexFlags(0), _blockOffset(0), _blockSize(0), _indexRecordSize(0),
_blockRecordSize(0), _blockShift(0), _nodeShift(0), _indexIdSize(0) {}
NODFile(const SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
_indexOffset(0), _indexSize(0), _indexFlags(0), _blockOffset(0),
_blockSize(0), _indexRecordSize(0), _blockRecordSize(0), _blockShift(0),
_nodeShift(0), _indexIdSize(0) {}
bool load(Handle &hdl); bool load(Handle &hdl);
@ -95,8 +95,8 @@ private:
bool nodeBlock(Handle &hdl, quint32 nodeOffset, BlockInfo &blockInfo) const; bool nodeBlock(Handle &hdl, quint32 nodeOffset, BlockInfo &blockInfo) const;
bool readBlock(Handle &hdl, quint32 blockOffset, BlockInfo &blockInfo) const; bool readBlock(Handle &hdl, quint32 blockOffset, BlockInfo &blockInfo) const;
quint32 _flags, _indexOffset, _indexSize, _indexFlags, _blockOffset, Section _block, _index;
_blockSize; quint32 _flags, _indexFlags;
quint16 _indexRecordSize, _blockRecordSize; quint16 _indexRecordSize, _blockRecordSize;
quint8 _blockShift, _nodeShift, _indexIdSize; quint8 _blockShift, _nodeShift, _indexIdSize;
}; };

View File

@ -136,22 +136,22 @@ bool RGNFile::load(Handle &hdl)
quint16 hdrLen; quint16 hdrLen;
if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen) if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen)
&& seek(hdl, _gmpOffset + 0x15) && readUInt32(hdl, _offset) && seek(hdl, _gmpOffset + 0x15) && readUInt32(hdl, _base.offset)
&& readUInt32(hdl, _size))) && readUInt32(hdl, _base.size)))
return false; return false;
if (hdrLen >= 0x68) { if (hdrLen >= 0x68) {
if (!(readUInt32(hdl, _polygonsOffset) && readUInt32(hdl, _polygonsSize) if (!(readUInt32(hdl, _polygons.offset) && readUInt32(hdl, _polygons.size)
&& seek(hdl, _gmpOffset + 0x29) && readUInt32(hdl, _polygonsGblFlags) && seek(hdl, _gmpOffset + 0x29) && readUInt32(hdl, _polygonsGblFlags)
&& readUInt32(hdl, _polygonsLclFlags[0]) && readUInt32(hdl, _polygonsLclFlags[0])
&& readUInt32(hdl, _polygonsLclFlags[1]) && readUInt32(hdl, _polygonsLclFlags[1])
&& readUInt32(hdl, _polygonsLclFlags[2]) && readUInt32(hdl, _polygonsLclFlags[2])
&& readUInt32(hdl, _linesOffset) && readUInt32(hdl, _linesSize) && readUInt32(hdl, _lines.offset) && readUInt32(hdl, _lines.size)
&& seek(hdl, _gmpOffset + 0x45) && readUInt32(hdl, _linesGblFlags) && seek(hdl, _gmpOffset + 0x45) && readUInt32(hdl, _linesGblFlags)
&& readUInt32(hdl, _linesLclFlags[0]) && readUInt32(hdl, _linesLclFlags[0])
&& readUInt32(hdl, _linesLclFlags[1]) && readUInt32(hdl, _linesLclFlags[1])
&& readUInt32(hdl, _linesLclFlags[2]) && readUInt32(hdl, _linesLclFlags[2])
&& readUInt32(hdl, _pointsOffset) && readUInt32(hdl, _pointsSize) && readUInt32(hdl, _points.offset) && readUInt32(hdl, _points.size)
&& seek(hdl, _gmpOffset + 0x61) && readUInt32(hdl, _pointsGblFlags) && seek(hdl, _gmpOffset + 0x61) && readUInt32(hdl, _pointsGblFlags)
&& readUInt32(hdl, _pointsLclFlags[0]) && readUInt32(hdl, _pointsLclFlags[0])
&& readUInt32(hdl, _pointsLclFlags[1]) && readUInt32(hdl, _pointsLclFlags[1])
@ -161,11 +161,11 @@ bool RGNFile::load(Handle &hdl)
if (hdrLen >= 0x7D) { if (hdrLen >= 0x7D) {
quint32 info; quint32 info;
if (!(seek(hdl, _gmpOffset + 0x71) && readUInt32(hdl, _dictOffset) if (!(seek(hdl, _gmpOffset + 0x71) && readUInt32(hdl, _dict.offset)
&& readUInt32(hdl, _dictSize) && readUInt32(hdl, info))) && readUInt32(hdl, _dict.size) && readUInt32(hdl, info)))
return false; return false;
if (_dictSize && _dictOffset && (info & 0x1E)) { if (_dict.size && _dict.offset && (info & 0x1E)) {
_huffmanTable = new HuffmanTable(((info >> 1) & 0xF) - 1); _huffmanTable = new HuffmanTable(((info >> 1) & 0xF) - 1);
if (!_huffmanTable->load(this, hdl)) if (!_huffmanTable->load(this, hdl))
return false; return false;
@ -556,7 +556,7 @@ bool RGNFile::segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) cons
if (subdiv->offset() == subdiv->end() || !(subdiv->objects() & 0x1F)) if (subdiv->offset() == subdiv->end() || !(subdiv->objects() & 0x1F))
return true; return true;
quint32 offset = _offset + subdiv->offset(); quint32 offset = _base.offset + subdiv->offset();
if (!seek(hdl, offset)) if (!seek(hdl, offset))
return false; return false;
@ -585,7 +585,7 @@ bool RGNFile::segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) cons
} }
seg[lt] = SubDiv::Segment(ls, seg[lt] = SubDiv::Segment(ls,
subdiv->end() ? _offset + subdiv->end() : _offset + _size); subdiv->end() ? _base.offset + subdiv->end() : _base.offset + _base.size);
return true; return true;
} }
@ -598,24 +598,24 @@ bool RGNFile::subdivInit(Handle &hdl, SubDiv *subdiv) const
return false; return false;
if (subdiv->extPointsOffset() != subdiv->extPointsEnd()) { if (subdiv->extPointsOffset() != subdiv->extPointsEnd()) {
quint32 start = _pointsOffset + subdiv->extPointsOffset(); quint32 start = _points.offset + subdiv->extPointsOffset();
quint32 end = subdiv->extPointsEnd() quint32 end = subdiv->extPointsEnd()
? _pointsOffset + subdiv->extPointsEnd() ? _points.offset + subdiv->extPointsEnd()
: _pointsOffset + _pointsSize; : _points.offset + _points.size;
extPoints = SubDiv::Segment(start, end); extPoints = SubDiv::Segment(start, end);
} }
if (subdiv->extPolygonsOffset() != subdiv->extPolygonsEnd()) { if (subdiv->extPolygonsOffset() != subdiv->extPolygonsEnd()) {
quint32 start = _polygonsOffset + subdiv->extPolygonsOffset(); quint32 start = _polygons.offset + subdiv->extPolygonsOffset();
quint32 end = subdiv->extPolygonsEnd() quint32 end = subdiv->extPolygonsEnd()
? _polygonsOffset + subdiv->extPolygonsEnd() ? _polygons.offset + subdiv->extPolygonsEnd()
: _polygonsOffset + _polygonsSize; : _polygons.offset + _polygons.size;
extPolygons = SubDiv::Segment(start, end); extPolygons = SubDiv::Segment(start, end);
} }
if (subdiv->extLinesOffset() != subdiv->extLinesEnd()) { if (subdiv->extLinesOffset() != subdiv->extLinesEnd()) {
quint32 start = _linesOffset + subdiv->extLinesOffset(); quint32 start = _lines.offset + subdiv->extLinesOffset();
quint32 end = subdiv->extLinesEnd() quint32 end = subdiv->extLinesEnd()
? _linesOffset + subdiv->extLinesEnd() ? _lines.offset + subdiv->extLinesEnd()
: _linesOffset + _linesSize; : _lines.offset + _lines.size;
extLines = SubDiv::Segment(start, end); extLines = SubDiv::Segment(start, end);
} }

View File

@ -1,6 +1,7 @@
#ifndef IMG_RGNFILE_H #ifndef IMG_RGNFILE_H
#define IMG_RGNFILE_H #define IMG_RGNFILE_H
#include "section.h"
#include "subfile.h" #include "subfile.h"
#include "subdiv.h" #include "subdiv.h"
@ -22,18 +23,10 @@ public:
RoadReference RoadReference
}; };
RGNFile(const IMGData *img) RGNFile(const IMGData *img) : SubFile(img), _huffmanTable(0) {}
: SubFile(img), _huffmanTable(0), _offset(0), _size(0), _polygonsOffset(0), RGNFile(const QString *path) : SubFile(path), _huffmanTable(0) {}
_polygonsSize(0), _linesOffset(0), _linesSize(0), _pointsOffset(0), RGNFile(const SubFile *gmp, quint32 offset)
_pointsSize(0) {} : SubFile(gmp, offset), _huffmanTable(0) {}
RGNFile(const QString *path)
: SubFile(path), _huffmanTable(0), _offset(0), _size(0), _polygonsOffset(0),
_polygonsSize(0), _linesOffset(0), _linesSize(0), _pointsOffset(0),
_pointsSize(0) {}
RGNFile(const SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
_huffmanTable(0), _offset(0), _size(0), _polygonsOffset(0),
_polygonsSize(0), _linesOffset(0), _linesSize(0), _pointsOffset(0),
_pointsSize(0) {}
~RGNFile(); ~RGNFile();
void clear(); void clear();
@ -57,8 +50,7 @@ public:
bool subdivInit(Handle &hdl, SubDiv *subdiv) const; bool subdivInit(Handle &hdl, SubDiv *subdiv) const;
const HuffmanTable *huffmanTable() const {return _huffmanTable;} const HuffmanTable *huffmanTable() const {return _huffmanTable;}
quint32 dictOffset() const {return _dictOffset;} const Section &dict() const {return _dict;}
quint32 dictSize() const {return _dictSize;}
private: private:
bool segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) const; bool segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) const;
@ -68,24 +60,9 @@ private:
bool skipGblFields(Handle &hdl, quint32 flags) const; bool skipGblFields(Handle &hdl, quint32 flags) const;
HuffmanTable *_huffmanTable; HuffmanTable *_huffmanTable;
Section _base, _dict, _polygons, _lines, _points;
quint32 _offset; quint32 _polygonsGblFlags, _linesGblFlags, _pointsGblFlags;
quint32 _size; quint32 _polygonsLclFlags[3], _linesLclFlags[3], _pointsLclFlags[3];
quint32 _dictOffset;
quint32 _dictSize;
quint32 _polygonsOffset;
quint32 _polygonsSize;
quint32 _polygonsLclFlags[3];
quint32 _polygonsGblFlags;
quint32 _linesOffset;
quint32 _linesSize;
quint32 _linesLclFlags[3];
quint32 _linesGblFlags;
quint32 _pointsOffset;
quint32 _pointsSize;
quint32 _pointsLclFlags[3];
quint32 _pointsGblFlags;
}; };
} }

17
src/map/IMG/section.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef SECTION_H
#define SECTION_H
#include <QtGlobal>
namespace IMG {
struct Section {
quint32 offset;
quint32 size;
Section() : offset(0), size(0) {}
};
}
#endif // SECTION_H

View File

@ -52,8 +52,11 @@ TREFile::~TREFile()
bool TREFile::init() bool TREFile::init()
{ {
Handle hdl(this); Handle hdl(this);
quint8 locked; quint8 locked, levels[64];
quint16 hdrLen; quint16 hdrLen;
qint32 north, east, south, west;
quint32 levelsCount;
Section levelSec;
if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen) if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen)
@ -61,7 +64,6 @@ bool TREFile::init()
return false; return false;
// Tile bounds // Tile bounds
qint32 north, east, south, west;
if (!(seek(hdl, _gmpOffset + 0x15) && readInt24(hdl, north) if (!(seek(hdl, _gmpOffset + 0x15) && readInt24(hdl, north)
&& readInt24(hdl, east) && readInt24(hdl, south) && readInt24(hdl, west))) && readInt24(hdl, east) && readInt24(hdl, south) && readInt24(hdl, west)))
return false; return false;
@ -71,39 +73,35 @@ bool TREFile::init()
return false; return false;
// Levels & subdivs info // Levels & subdivs info
quint32 levelsOffset, levelsSize, subdivSize; if (!(readUInt32(hdl, levelSec.offset) && readUInt32(hdl, levelSec.size)
if (!(readUInt32(hdl, levelsOffset) && readUInt32(hdl, levelsSize) && readUInt32(hdl, _subdivSec.offset) && readUInt32(hdl, _subdivSec.size)))
&& readUInt32(hdl, _subdivOffset) && readUInt32(hdl, subdivSize)))
return false; return false;
// Extended objects (TRE7) info
if (hdrLen > 0x9A) { if (hdrLen > 0x9A) {
// Extended objects (TRE7) info if (!(seek(hdl, _gmpOffset + 0x7C) && readUInt32(hdl, _extSec.offset)
if (!(seek(hdl, _gmpOffset + 0x7C) && readUInt32(hdl, _extended.offset) && readUInt32(hdl, _extSec.size) && readUInt16(hdl, _extItemSize)
&& readUInt32(hdl, _extended.size) && readUInt32(hdl, _flags)))
&& readUInt16(hdl, _extended.itemSize) && readUInt32(hdl, _flags)))
return false; return false;
} else {
_extended.offset = 0;
_extended.size = 0;
_extended.itemSize = 0;
_flags = 0;
} }
// Tile levels // Tile levels
quint8 levels[64]; if (levelSec.size > 64)
if (levelsSize > 64 || !(seek(hdl, levelsOffset) return false;
&& read(hdl, (char*)levels, levelsSize))) if (!(seek(hdl, levelSec.offset) && read(hdl, (char*)levels, levelSec.size)))
return false; return false;
if (locked) { if (locked) {
quint32 key; quint32 key;
if (hdrLen < 0xAE || !(seek(hdl, _gmpOffset + 0xAA)
&& readUInt32(hdl, key))) if (hdrLen < 0xAE)
return false; return false;
demangle(levels, levelsSize, key); if (!(seek(hdl, _gmpOffset + 0xAA) && readUInt32(hdl, key)))
return false;
demangle(levels, levelSec.size, key);
} }
quint32 levelsCount = levelsSize / 4; levelsCount = levelSec.size / 4;
_levels = QVector<MapLevel>(levelsCount); _levels = QVector<MapLevel>(levelsCount);
for (quint32 i = 0; i < levelsCount; i++) { for (quint32 i = 0; i < levelsCount; i++) {
@ -166,14 +164,13 @@ bool TREFile::load(int idx)
SubDivTree *tree = new SubDivTree(); SubDivTree *tree = new SubDivTree();
const MapLevel &level = _levels.at(idx); const MapLevel &level = _levels.at(idx);
_subdivs.insert(level.bits, tree); _subdivs.insert(level.bits, tree);
quint32 skip = 0; quint32 skip = 0;
for (int i = 0; i < idx; i++) for (int i = 0; i < idx; i++)
skip += _levels.at(i).subdivs; skip += _levels.at(i).subdivs;
if (!seek(hdl, _subdivOffset + skip * 16)) if (!seek(hdl, _subdivSec.offset + skip * 16))
return false; return false;
for (int j = 0; j < level.subdivs; j++) { for (int j = 0; j < level.subdivs; j++) {
@ -229,16 +226,16 @@ bool TREFile::load(int idx)
// Objects with extended types (TRE7) // Objects with extended types (TRE7)
if (_extended.size && _extended.itemSize) { if (_extSec.size && _extItemSize) {
quint32 totalSubdivs = 0; quint32 totalSubdivs = 0;
for (int i = 0; i < _levels.size(); i++) for (int i = 0; i < _levels.size(); i++)
totalSubdivs += _levels.at(i).subdivs; totalSubdivs += _levels.at(i).subdivs;
quint32 extendedSubdivs = _extended.size / _extended.itemSize; quint32 extendedSubdivs = _extSec.size / _extItemSize;
quint32 diff = totalSubdivs - extendedSubdivs + 1; quint32 diff = totalSubdivs - extendedSubdivs + 1;
if (skip < diff) if (skip < diff)
return true; return true;
if (!seek(hdl, _extended.offset + (skip - diff) * _extended.itemSize)) if (!seek(hdl, _extSec.offset + (skip - diff) * _extItemSize))
goto error; goto error;
quint32 polygons, lines, points; quint32 polygons, lines, points;
@ -251,7 +248,7 @@ bool TREFile::load(int idx)
if (i) if (i)
sl.at(i-1)->setExtEnds(polygons, lines, points); sl.at(i-1)->setExtEnds(polygons, lines, points);
if (!seek(hdl, pos(hdl) + _extended.itemSize - rb)) if (!seek(hdl, pos(hdl) + _extItemSize - rb))
goto error; goto error;
} }
@ -333,3 +330,13 @@ QList<SubDiv*> TREFile::subdivs(const RectC &rect, int bits, bool baseMap)
return list; return list;
} }
#ifndef QT_NO_DEBUG
QDebug IMG::operator<<(QDebug dbg, const TREFile::MapLevel &level)
{
dbg.nospace() << "MapLevel(" << level.level << "," << level.bits << ", "
<< level.subdivs << ")";
return dbg.space();
}
#endif // QT_NO_DEBUG

View File

@ -6,6 +6,7 @@
#include <QRect> #include <QRect>
#include "common/rectc.h" #include "common/rectc.h"
#include "common/rtree.h" #include "common/rtree.h"
#include "section.h"
#include "subfile.h" #include "subfile.h"
namespace IMG { namespace IMG {
@ -15,9 +16,12 @@ class SubDiv;
class TREFile : public SubFile class TREFile : public SubFile
{ {
public: public:
TREFile(const IMGData *img) : SubFile(img) {} TREFile(const IMGData *img)
TREFile(const QString *path) : SubFile(path) {} : SubFile(img), _flags(0), _extItemSize(0) {}
TREFile(const SubFile *gmp, quint32 offset) : SubFile(gmp, offset) {} TREFile(const QString *path)
: SubFile(path), _flags(0), _extItemSize(0) {}
TREFile(const SubFile *gmp, quint32 offset)
: SubFile(gmp, offset), _flags(0), _extItemSize(0) {}
~TREFile(); ~TREFile();
bool init(); bool init();
@ -37,15 +41,10 @@ private:
quint8 bits; quint8 bits;
quint16 subdivs; quint16 subdivs;
}; };
struct Extended {
quint32 offset;
quint32 size;
quint16 itemSize;
Extended() : offset(0), size(0), itemSize(0) {}
};
typedef RTree<SubDiv*, double, 2> SubDivTree; typedef RTree<SubDiv*, double, 2> SubDivTree;
friend QDebug operator<<(QDebug dbg, const MapLevel &level);
bool load(int idx); bool load(int idx);
int level(int bits, bool baseMap); int level(int bits, bool baseMap);
int readExtEntry(Handle &hdl, quint32 &polygons, quint32 &lines, int readExtEntry(Handle &hdl, quint32 &polygons, quint32 &lines,
@ -53,15 +52,18 @@ private:
RectC _bounds; RectC _bounds;
QVector<MapLevel> _levels; QVector<MapLevel> _levels;
quint32 _subdivOffset; Section _subdivSec, _extSec;
Extended _extended;
int _firstLevel;
quint32 _flags; quint32 _flags;
quint16 _extItemSize;
int _firstLevel;
bool _isBaseMap; bool _isBaseMap;
QMap<int, SubDivTree*> _subdivs; QMap<int, SubDivTree*> _subdivs;
}; };
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const TREFile::MapLevel &level);
#endif // QT_NO_DEBUG
} }
#endif // IMG_TREFILE_H #endif // IMG_TREFILE_H