1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2020-09-29 18:53:49 +02:00
parent 398eb152f6
commit 0f8859dd20
3 changed files with 41 additions and 34 deletions

View File

@ -217,7 +217,7 @@ static bool readShape(NODFile *nod, SubFile::Handle &nodHdl,
poly.points.append(QPointF(c.lon(), c.lat())); poly.points.append(QPointF(c.lon(), c.lat()));
poly.boundingRect = poly.boundingRect.united(c); poly.boundingRect = poly.boundingRect.united(c);
while (!(adj.flags & 1)) { while (!adj.eog) {
int ret = nod->nextNode(nodHdl, adj); int ret = nod->nextNode(nodHdl, adj);
if (ret < 0) if (ret < 0)
return false; return false;
@ -299,7 +299,7 @@ static bool readShape(NODFile *nod, SubFile::Handle &nodHdl,
steps = 0; steps = 0;
startWithStream = false; startWithStream = false;
if (adj.flags & 1) if (adj.eog)
eos = 0; eos = 0;
} }
@ -330,7 +330,7 @@ static bool readShape(NODFile *nod, SubFile::Handle &nodHdl,
poly.points.append(QPointF(c.lon(), c.lat())); poly.points.append(QPointF(c.lon(), c.lat()));
poly.boundingRect = poly.boundingRect.united(c); poly.boundingRect = poly.boundingRect.united(c);
pos = adj.nodeInfo.pos; pos = adj.nodeInfo.pos;
} while (!(adj.flags & 1) && nodes < cnt); } while (!adj.eog && nodes < cnt);
if (nodes == cnt) if (nodes == cnt)
break; break;

View File

@ -5,7 +5,8 @@
#define ARRAY_SIZE(array) \ #define ARRAY_SIZE(array) \
(sizeof(array) / sizeof(array[0])) (sizeof(array) / sizeof(array[0]))
static const struct { static const struct
{
quint8 lon; quint8 lon;
quint8 lat; quint8 lat;
} LLBITS[] = { } LLBITS[] = {
@ -13,12 +14,16 @@ static const struct {
{0x14, 0xc}, {0x14, 0x14} {0x14, 0xc}, {0x14, 0x14}
}; };
union NodeShift { struct NodeOffset
qint32 offset; {
quint8 id; bool ext;
union {
qint32 offset;
quint8 id;
} u;
}; };
static bool adjDistInfo(BitStream1 &bs, bool extraBit, quint8 &flags) static bool adjDistInfo(BitStream1 &bs, bool extraBit, bool &eog)
{ {
quint32 data, cnt; quint32 data, cnt;
@ -26,7 +31,7 @@ static bool adjDistInfo(BitStream1 &bs, bool extraBit, quint8 &flags)
return false; return false;
data <<= !extraBit; data <<= !extraBit;
flags |= (quint8)data & 1; eog |= (quint8)data & 1;
data >>= 1; data >>= 1;
for (cnt = 0; (data >> cnt) & 1; cnt++) { for (cnt = 0; (data >> cnt) & 1; cnt++) {
@ -39,8 +44,7 @@ static bool adjDistInfo(BitStream1 &bs, bool extraBit, quint8 &flags)
return true; return true;
} }
static bool adjNodeInfo(BitStream1 &bs, bool extraBit, NodeShift &shift, static bool adjNodeInfo(BitStream1 &bs, bool extraBit, NodeOffset &offset)
quint8 &flags)
{ {
quint32 data; quint32 data;
@ -49,19 +53,20 @@ static bool adjNodeInfo(BitStream1 &bs, bool extraBit, NodeShift &shift,
data <<= !extraBit; data <<= !extraBit;
if (data & 1) if (data & 1) {
shift.id = data >> 1; offset.ext = true;
else { offset.u.id = data >> 1;
} else {
quint32 bits = (data >> 1) & 7; quint32 bits = (data >> 1) & 7;
quint32 data2; quint32 data2;
flags |= 2;
if (!bs.read(bits + extraBit + 1, data2)) if (!bs.read(bits + extraBit + 1, data2))
return false; return false;
data = data2 << (6 - extraBit) | data >> 4; data = data2 << (6 - extraBit) | data >> 4;
bits = 0x19 - bits; bits = 0x19 - bits;
shift.offset = ((qint32)(data << bits) >> bits); offset.ext = false;
offset.u.offset = ((qint32)(data << bits) >> bits);
} }
return true; return true;
@ -306,9 +311,10 @@ bool NODFile::absAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
bool extraBit = (adj.nodeInfo.flags >> 6) & 1; bool extraBit = (adj.nodeInfo.flags >> 6) & 1;
bool linkIdValid = true; bool linkIdValid = true;
bool firstLoop = true; bool firstLoop = true;
NodeOffset offset;
do { do {
adj.flags = 0; adj.eog = false;
if (!bs.read(8, flags)) if (!bs.read(8, flags))
return false; return false;
@ -336,15 +342,15 @@ bool NODFile::absAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
} }
if (!(flags & 0x10)) { if (!(flags & 0x10)) {
if (!adjDistInfo(bs, (m2 == 1 && linkIdValid), adj.flags)) if (!adjDistInfo(bs, (m2 == 1 && linkIdValid), adj.eog))
return false; return false;
NodeShift shift; if (!adjNodeInfo(bs, extraBit, offset))
if (!adjNodeInfo(bs, extraBit, shift, adj.flags))
return false; return false;
if (adj.flags & 2) if (!offset.ext)
nextOffset = adj.nodeOffset + shift.offset; nextOffset = adj.nodeOffset + offset.u.offset;
else if (!nodeOffset(adj.extHdl, adj.blockInfo, shift.id, nextOffset)) else if (!nodeOffset(adj.extHdl, adj.blockInfo, offset.u.id,
nextOffset))
return false; return false;
m2p = m2; m2p = m2;
@ -373,7 +379,7 @@ bool NODFile::absAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
if ((adj.linkOffset == li.linkOffset) || (adj.linkId == linkId)) { if ((adj.linkOffset == li.linkOffset) || (adj.linkId == linkId)) {
adj.nodeOffset = nextOffset; adj.nodeOffset = nextOffset;
if (!(adj.flags & 2)) { if (offset.ext) {
adj.linkId = 0xFFFFFFFF; adj.linkId = 0xFFFFFFFF;
return nodeBlock(hdl, adj.nodeOffset << _nodeShift, return nodeBlock(hdl, adj.nodeOffset << _nodeShift,
adj.blockInfo); adj.blockInfo);
@ -406,12 +412,13 @@ bool NODFile::relAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
quint32 flagsBits = 8; quint32 flagsBits = 8;
quint32 flags; quint32 flags;
quint32 nextOffset = 0xFFFFFFFF; quint32 nextOffset = 0xFFFFFFFF;
NodeOffset offset;
bool extraBit = (adj.nodeInfo.flags >> 6) & 1; bool extraBit = (adj.nodeInfo.flags >> 6) & 1;
bool linkIdValid = true; bool linkIdValid = true;
bool firstLoop = true; bool firstLoop = true;
do { do {
adj.flags = 0; adj.eog = false;
if (!bs.read(flagsBits, flags)) if (!bs.read(flagsBits, flags))
return false; return false;
@ -442,17 +449,17 @@ bool NODFile::relAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
} }
if ((flags & 0x50) == 0x50) { if ((flags & 0x50) == 0x50) {
if (!adjDistInfo(bs, false, adj.flags)) if (!adjDistInfo(bs, false, adj.eog))
return false; return false;
adj.flags |= 1; adj.eog = true;
} }
if ((flags >> 6) & 1) { if ((flags >> 6) & 1) {
NodeShift shift; if (!adjNodeInfo(bs, extraBit, offset))
if (!adjNodeInfo(bs, extraBit, shift, adj.flags))
return false; return false;
if (adj.flags & 2) if (!offset.ext)
nextOffset = adj.nodeOffset + shift.offset; nextOffset = adj.nodeOffset + offset.u.offset;
else if (!nodeOffset(adj.extHdl, adj.blockInfo, shift.id, nextOffset)) else if (!nodeOffset(adj.extHdl, adj.blockInfo, offset.u.id,
nextOffset))
return false; return false;
} }
@ -469,7 +476,7 @@ bool NODFile::relAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
if ((adj.linkOffset == li.linkOffset) || (adj.linkId == linkId)) { if ((adj.linkOffset == li.linkOffset) || (adj.linkId == linkId)) {
adj.nodeOffset = nextOffset; adj.nodeOffset = nextOffset;
if (!(adj.flags & 2)) { if (offset.ext) {
adj.linkId = 0xFFFFFFFF; adj.linkId = 0xFFFFFFFF;
return nodeBlock(hdl, adj.nodeOffset << _nodeShift, return nodeBlock(hdl, adj.nodeOffset << _nodeShift,
adj.blockInfo); adj.blockInfo);

View File

@ -51,7 +51,7 @@ public:
quint32 nodeOffset; quint32 nodeOffset;
quint32 linkOffset; quint32 linkOffset;
quint32 linkId; quint32 linkId;
quint8 flags; bool eog;
}; };
NODFile(IMG *img) : SubFile(img), _indexOffset(0), _indexSize(0), NODFile(IMG *img) : SubFile(img), _indexOffset(0), _indexSize(0),