mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
A little bit more sane subfile interface
This commit is contained in:
parent
5343a1a922
commit
0b5d01a1f6
@ -32,7 +32,7 @@ bool BitStream1::read(int bits, quint32 &val)
|
|||||||
|
|
||||||
bool BitStream1::flush()
|
bool BitStream1::flush()
|
||||||
{
|
{
|
||||||
if (_length && !_file.seek(_hdl, _hdl.pos() + _length))
|
if (_length && !_file.seek(_hdl, _file.pos(_hdl) + _length))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_length = 0;
|
_length = 0;
|
||||||
@ -43,7 +43,7 @@ bool BitStream1::flush()
|
|||||||
|
|
||||||
bool BitStream4::flush()
|
bool BitStream4::flush()
|
||||||
{
|
{
|
||||||
if (_length && !_file.seek(_hdl, _hdl.pos() + _length))
|
if (_length && !_file.seek(_hdl, _file.pos(_hdl) + _length))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_length = 0;
|
_length = 0;
|
||||||
@ -82,7 +82,7 @@ bool BitStream4F::read(int bits, quint32 &val)
|
|||||||
BitStream4R::BitStream4R(const SubFile &file, SubFile::Handle &hdl,
|
BitStream4R::BitStream4R(const SubFile &file, SubFile::Handle &hdl,
|
||||||
quint32 length) : BitStream4(file, hdl, length)
|
quint32 length) : BitStream4(file, hdl, length)
|
||||||
{
|
{
|
||||||
_file.seek(_hdl, _hdl.pos() - 4);
|
_file.seek(_hdl, _file.pos(_hdl) - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BitStream4R::readBytes(int bytes, quint32 &val)
|
bool BitStream4R::readBytes(int bytes, quint32 &val)
|
||||||
@ -169,14 +169,14 @@ bool BitStream4R::skip(quint32 bytes)
|
|||||||
else {
|
else {
|
||||||
quint32 seek = ((bytes - ab)/4)*4;
|
quint32 seek = ((bytes - ab)/4)*4;
|
||||||
quint32 read = (bytes - ab)%4;
|
quint32 read = (bytes - ab)%4;
|
||||||
if (seek && !_file.seek(_hdl, _hdl.pos() - seek))
|
if (seek && !_file.seek(_hdl, _file.pos(_hdl) - seek))
|
||||||
return false;
|
return false;
|
||||||
_length -= seek;
|
_length -= seek;
|
||||||
if (read) {
|
if (read) {
|
||||||
quint32 rb = qMin(_length, 4U);
|
quint32 rb = qMin(_length, 4U);
|
||||||
if (!_file.readUInt32(_hdl, _data))
|
if (!_file.readUInt32(_hdl, _data))
|
||||||
return false;
|
return false;
|
||||||
if (!_file.seek(_hdl, _hdl.pos() - 8))
|
if (!_file.seek(_hdl, _file.pos(_hdl) - 8))
|
||||||
return false;
|
return false;
|
||||||
_length -= rb;
|
_length -= rb;
|
||||||
_unused = (4 - rb) * 8;
|
_unused = (4 - rb) * 8;
|
||||||
|
@ -73,7 +73,7 @@ bool BitStream4R::read(int bits, T &val)
|
|||||||
|
|
||||||
if (!_file.readUInt32(_hdl, _data))
|
if (!_file.readUInt32(_hdl, _data))
|
||||||
return false;
|
return false;
|
||||||
if (!_file.seek(_hdl, _hdl.pos() - 8))
|
if (!_file.seek(_hdl, _file.pos(_hdl) - 8))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_length -= bytes;
|
_length -= bytes;
|
||||||
|
@ -57,7 +57,7 @@ bool HuffmanTable::getBuffer(const SubFile &file, SubFile::Handle &hdl,
|
|||||||
return false;
|
return false;
|
||||||
if (!file.readVUInt32(hdl, recordSize))
|
if (!file.readVUInt32(hdl, recordSize))
|
||||||
return false;
|
return false;
|
||||||
recordOffset = hdl.pos() + recordSize;
|
recordOffset = file.pos(hdl) + recordSize;
|
||||||
if (recordOffset > offset + size)
|
if (recordOffset > offset + size)
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -51,7 +51,7 @@ bool RGNFile::skipClassFields(Handle &hdl) const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return seek(hdl, hdl.pos() + rs);
|
return seek(hdl, pos(hdl) + rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const
|
bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const
|
||||||
@ -73,7 +73,7 @@ bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const
|
|||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
skip = m + 1;
|
skip = m + 1;
|
||||||
if (!seek(hdl, hdl.pos() + skip))
|
if (!seek(hdl, pos(hdl) + skip))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bitfield >>= 1;
|
bitfield >>= 1;
|
||||||
@ -93,7 +93,7 @@ bool RGNFile::skipGblFields(Handle &hdl, quint32 flags) const
|
|||||||
flags = flags >> 2;
|
flags = flags >> 2;
|
||||||
} while (flags != 0);
|
} while (flags != 0);
|
||||||
|
|
||||||
return seek(hdl, hdl.pos() + cnt);
|
return seek(hdl, pos(hdl) + cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RGNFile::init(Handle &hdl)
|
bool RGNFile::init(Handle &hdl)
|
||||||
@ -158,7 +158,7 @@ bool RGNFile::polyObjects(Handle &hdl, const SubDiv *subdiv,
|
|||||||
qint16 lon, lat;
|
qint16 lon, lat;
|
||||||
quint16 len;
|
quint16 len;
|
||||||
|
|
||||||
while (hdl.pos() < (int)segment.end()) {
|
while (pos(hdl) < segment.end()) {
|
||||||
IMG::Poly poly;
|
IMG::Poly poly;
|
||||||
|
|
||||||
if (!(readUInt8(hdl, type) && readUInt24(hdl, labelPtr)
|
if (!(readUInt8(hdl, type) && readUInt24(hdl, labelPtr)
|
||||||
@ -233,7 +233,7 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
|
|||||||
if (!seek(hdl, segment.offset()))
|
if (!seek(hdl, segment.offset()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (hdl.pos() < (int)segment.end()) {
|
while (pos(hdl) < segment.end()) {
|
||||||
IMG::Poly poly;
|
IMG::Poly poly;
|
||||||
QPoint pos;
|
QPoint pos;
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
|
|||||||
&& readInt16(hdl, lon) && readInt16(hdl, lat)
|
&& readInt16(hdl, lon) && readInt16(hdl, lat)
|
||||||
&& readVUInt32(hdl, len)))
|
&& readVUInt32(hdl, len)))
|
||||||
return false;
|
return false;
|
||||||
Q_ASSERT(hdl.pos() + len <= segment.end());
|
Q_ASSERT(SubFile::pos(hdl) + len <= segment.end());
|
||||||
|
|
||||||
poly.type = 0x10000 | (quint16(type)<<8) | (subtype & 0x1F);
|
poly.type = 0x10000 | (quint16(type)<<8) | (subtype & 0x1F);
|
||||||
labelPtr = 0;
|
labelPtr = 0;
|
||||||
@ -341,7 +341,7 @@ bool RGNFile::pointObjects(Handle &hdl, const SubDiv *subdiv,
|
|||||||
if (!seek(hdl, segment.offset()))
|
if (!seek(hdl, segment.offset()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (hdl.pos() < (int)segment.end()) {
|
while (pos(hdl) < segment.end()) {
|
||||||
IMG::Point point;
|
IMG::Point point;
|
||||||
quint8 type, subtype;
|
quint8 type, subtype;
|
||||||
qint16 lon, lat;
|
qint16 lon, lat;
|
||||||
@ -384,7 +384,7 @@ bool RGNFile::extPointObjects(Handle &hdl, const SubDiv *subdiv, LBLFile *lbl,
|
|||||||
if (!seek(hdl, segment.offset()))
|
if (!seek(hdl, segment.offset()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (hdl.pos() < (int)segment.end()) {
|
while (pos(hdl) < segment.end()) {
|
||||||
IMG::Point point;
|
IMG::Point point;
|
||||||
qint16 lon, lat;
|
qint16 lon, lat;
|
||||||
quint8 type, subtype;
|
quint8 type, subtype;
|
||||||
@ -441,11 +441,11 @@ bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, NETFile *net,
|
|||||||
if (!(blockIndexIdSize = nod->indexIdSize(nodHdl)))
|
if (!(blockIndexIdSize = nod->indexIdSize(nodHdl)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (hdl.pos() < (int)segment.end()) {
|
while (pos(hdl) < segment.end()) {
|
||||||
if (!readVUInt32(hdl, size))
|
if (!readVUInt32(hdl, size))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int pos = hdl.pos();
|
quint32 pos = SubFile::pos(hdl);
|
||||||
|
|
||||||
if (!(readUInt8(hdl, flags) && readVUInt32(hdl, blockIndexIdSize,
|
if (!(readUInt8(hdl, flags) && readVUInt32(hdl, blockIndexIdSize,
|
||||||
blockIndexId)))
|
blockIndexId)))
|
||||||
@ -482,7 +482,7 @@ bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, NETFile *net,
|
|||||||
lineId = (((v16 >> shift) >> 8) & 3) + 1;
|
lineId = (((v16 >> shift) >> 8) & 3) + 1;
|
||||||
|
|
||||||
if (shift < 6 && i < b8 + b10 + b16 - 1)
|
if (shift < 6 && i < b8 + b10 + b16 - 1)
|
||||||
seek(hdl, hdl.pos() - 1);
|
seek(hdl, SubFile::pos(hdl) - 1);
|
||||||
} else {
|
} else {
|
||||||
linkId = (quint8)v16;
|
linkId = (quint8)v16;
|
||||||
lineId = v16 >> 8;
|
lineId = v16 >> 8;
|
||||||
@ -498,7 +498,7 @@ bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, NETFile *net,
|
|||||||
_huffmanTable, lines);
|
_huffmanTable, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(pos + (int)size == hdl.pos());
|
Q_ASSERT(pos + size == SubFile::pos(hdl));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -359,7 +359,7 @@ static bool skipLocalization(SubFile *file, SubFile::Handle &hdl)
|
|||||||
len = len >> 2;
|
len = len >> 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file->seek(hdl, hdl.pos() + len))
|
if (!file->seek(hdl, file->pos(hdl) + len))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -28,8 +28,6 @@ public:
|
|||||||
}
|
}
|
||||||
~Handle() {delete _file;}
|
~Handle() {delete _file;}
|
||||||
|
|
||||||
int pos() const {return _pos;}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class SubFile;
|
friend class SubFile;
|
||||||
|
|
||||||
@ -57,6 +55,7 @@ public:
|
|||||||
void addBlock(quint16 block) {_blocks->append(block);}
|
void addBlock(quint16 block) {_blocks->append(block);}
|
||||||
|
|
||||||
bool seek(Handle &handle, quint32 pos) const;
|
bool seek(Handle &handle, quint32 pos) const;
|
||||||
|
quint32 pos(Handle &handle) const {return handle._pos;}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool readUInt8(Handle &handle, T &val) const
|
bool readUInt8(Handle &handle, T &val) const
|
||||||
|
@ -233,7 +233,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, hdl.pos() + _extended.itemSize - rb))
|
if (!seek(hdl, pos(hdl) + _extended.itemSize - rb))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user