diff --git a/src/map/IMG/lblfile.cpp b/src/map/IMG/lblfile.cpp index b7a409e5..33247f48 100644 --- a/src/map/IMG/lblfile.cpp +++ b/src/map/IMG/lblfile.cpp @@ -180,8 +180,8 @@ Label LBLFile::str2label(const QVector &str, bool capitalize, Shield(shieldType, _codec.toString(shieldLabel))); } -Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, bool capitalize, - bool convert) const +Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, quint32 size, + bool capitalize, bool convert) const { Shield::Type shieldType = Shield::None; QByteArray label, shieldLabel; @@ -190,7 +190,7 @@ Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, bool capitalize, quint8 b1, b2, b3; int split = -1; - while (true) { + for (quint32 i = 0; i < size; i = i + 3) { if (!(file->readByte(fileHdl, &b1) && file->readByte(fileHdl, &b2) && file->readByte(fileHdl, &b3))) return Label(); @@ -242,29 +242,33 @@ Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, bool capitalize, } } } + + return Label(); } -Label LBLFile::label8b(const SubFile *file, Handle &fileHdl, bool capitalize, - bool convert) const +Label LBLFile::label8b(const SubFile *file, Handle &fileHdl, quint32 size, + bool capitalize, bool convert) const { QVector str; quint8 c; - do { + for (quint32 i = 0; i < size; i++) { if (!file->readByte(fileHdl, &c)) - return Label(); + break; str.append(c); - } while (c); + if (!c) + return str2label(str, capitalize, convert); + } - return str2label(str, capitalize, convert); + return Label(); } Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl, - bool capitalize, bool convert) const + quint32 size, bool capitalize, bool convert) const { QVector str; - if (!_huffmanText->decode(file, fileHdl, 0xFFFFFFFF, str)) + if (!_huffmanText->decode(file, fileHdl, size, str)) return Label(); if (!_table) return str2label(str, capitalize, convert); @@ -319,20 +323,21 @@ Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize, if (!seek(hdl, labelOffset)) return Label(); - return label(hdl, this, hdl, capitalize, convert); + return label(hdl, this, hdl, _offset + _size - labelOffset, capitalize, + convert); } Label LBLFile::label(Handle &hdl, const SubFile *file, Handle &fileHdl, - bool capitalize, bool convert) const + quint32 size, bool capitalize, bool convert) const { switch (_encoding) { case 6: - return label6b(file, fileHdl, capitalize, convert); + return label6b(file, fileHdl, size, capitalize, convert); case 9: case 10: - return label8b(file, fileHdl, capitalize, convert); + return label8b(file, fileHdl, size, capitalize, convert); case 11: - return labelHuffman(hdl, file, fileHdl, capitalize, convert); + return labelHuffman(hdl, file, fileHdl, size, capitalize, convert); default: return Label(); } diff --git a/src/map/IMG/lblfile.h b/src/map/IMG/lblfile.h index f2ecdbe7..4447e327 100644 --- a/src/map/IMG/lblfile.h +++ b/src/map/IMG/lblfile.h @@ -34,7 +34,7 @@ public: Label label(Handle &hdl, quint32 offset, bool poi = false, bool capitalize = true, bool convert = false) const; Label label(Handle &hdl, const SubFile *file, Handle &fileHdl, - bool capitalize = true, bool convert = false) const; + quint32 size, bool capitalize = true, bool convert = false) const; quint8 imageIdSize() const {return _imgOffsetIdSize;} QPixmap image(Handle &hdl, quint32 id) const; @@ -47,12 +47,12 @@ private: Label str2label(const QVector &str, bool capitalize, bool convert) const; - Label label6b(const SubFile *file, Handle &fileHdl, bool capitalize, - bool convert) const; - Label label8b(const SubFile *file, Handle &fileHdl, bool capitalize, - bool convert) const; - Label labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl, + Label label6b(const SubFile *file, Handle &fileHdl, quint32 size, bool capitalize, bool convert) const; + Label label8b(const SubFile *file, Handle &fileHdl, quint32 size, + bool capitalize, bool convert) const; + Label labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl, + quint32 size, bool capitalize, bool convert) const; bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size, quint32 recordSize); diff --git a/src/map/IMG/rgnfile.cpp b/src/map/IMG/rgnfile.cpp index 274102e3..42a0c423 100644 --- a/src/map/IMG/rgnfile.cpp +++ b/src/map/IMG/rgnfile.cpp @@ -64,6 +64,8 @@ bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType, break; } + quint32 off = pos(hdl); + if (poly && Style::isRaster(poly->type) && lbl && lbl->imageIdSize()) { quint32 id; quint32 top, right, bottom, left; @@ -77,20 +79,14 @@ bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType, poly->raster = Raster(lbl, id, QRect(QPoint(left, top), QPoint(right, bottom))); - - rs -= lbl->imageIdSize() + 16; } if (point && (flags & 1) && lbl) { - quint32 p = pos(hdl); - point->label = lbl->label(lblHdl, this, hdl); + point->label = lbl->label(lblHdl, this, hdl, rs); point->classLabel = true; - - Q_ASSERT(pos(hdl) - p <= rs + 4); - seek(hdl, p); } - return seek(hdl, pos(hdl) + rs); + return seek(hdl, off + rs); } bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const