1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-02-20 09:40:49 +01:00

A much more sane raster tabel load...

This commit is contained in:
Martin Tůma 2021-02-10 21:26:26 +01:00
parent af3b41cc92
commit a2390ae26f
2 changed files with 50 additions and 44 deletions

View File

@ -55,11 +55,24 @@ static QString capitalized(const QString &str)
return ret; return ret;
} }
static quint8 byteSize(quint32 val)
{
quint8 ret = 0;
do {
ret++;
val = val >> 8;
} while (val != 0);
return ret;
}
LBLFile::~LBLFile() LBLFile::~LBLFile()
{ {
delete _huffmanText; delete _huffmanText;
delete[] _table; delete[] _table;
delete[] _rasters;
} }
bool LBLFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl) bool LBLFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
@ -101,19 +114,10 @@ bool LBLFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
&& readUInt32(hdl, _imgSize))) && readUInt32(hdl, _imgSize)))
return false; return false;
if (size && recordSize) { if (size && recordSize)
quint32 count = size / recordSize; if (!loadRasterTable(hdl, offset, size, recordSize))
quint32 maxId = count - 1;
_imgOffsetIdSize = 0;
do {
_imgOffsetIdSize++;
maxId = maxId >> 8;
} while (maxId != 0);
if (!loadFiles(hdl, count, offset, recordSize))
return false; return false;
} }
}
if (_encoding == 11) { if (_encoding == 11) {
_huffmanText = new HuffmanText(); _huffmanText = new HuffmanText();
@ -130,8 +134,10 @@ void LBLFile::clear()
{ {
delete _huffmanText; delete _huffmanText;
delete[] _table; delete[] _table;
delete[] _rasters;
_huffmanText = 0; _huffmanText = 0;
_table = 0; _table = 0;
_rasters = 0;
} }
Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize) const Label LBLFile::label6b(Handle &hdl, quint32 offset, bool capitalize) const
@ -306,41 +312,44 @@ Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize) con
} }
} }
bool LBLFile::loadFiles(Handle &hdl, quint32 count, quint32 offset, bool LBLFile::loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
quint32 recordSize) quint32 recordSize)
{ {
_rasters.resize(count); quint32 prev, cur;
for (quint32 i = 0; i < count; i++) { _imgCount = size / recordSize;
quint32 currentOffset, nextOffset, size; _imgOffsetIdSize = byteSize(_imgCount - 1);
_rasters = new Image[_imgCount];
if (!(seek(hdl, offset + i * recordSize) if (!(seek(hdl, offset) && readVUInt32(hdl, recordSize, prev)))
&& readVUInt32(hdl, recordSize, currentOffset)))
return false; return false;
if (i == count - 1)
nextOffset = _imgSize;
else {
if (!readVUInt32(hdl, recordSize, nextOffset))
return false;
}
size = nextOffset - currentOffset;
_rasters[i] = File(currentOffset, size); for (quint32 i = 1; i < _imgCount; i++) {
if (!readVUInt32(hdl, recordSize, cur))
return false;
_rasters[i-1].offset = prev;
_rasters[i-1].size = cur - prev;
prev = cur;
} }
_rasters[_imgCount-1].offset = prev;
_rasters[_imgCount-1].size = _imgSize - prev;
return true; return true;
} }
QImage LBLFile::readImage(Handle &hdl, quint32 id) const QImage LBLFile::readImage(Handle &hdl, quint32 id) const
{ {
if (id >= (quint32)_rasters.size()) if (id >= _imgCount)
return QImage(); return QImage();
if (!seek(hdl, _imgOffset + _rasters.at(id).offset)) if (!seek(hdl, _imgOffset + _rasters[id].offset))
return QImage(); return QImage();
QByteArray ba; QByteArray ba;
ba.resize(_rasters.at(id).size); ba.resize(_rasters[id].size);
if (!read(hdl, ba.data(), _rasters.at(id).size)) if (!read(hdl, ba.data(), _rasters[id].size))
return QImage(); return QImage();
return QImage::fromData(ba); return QImage::fromData(ba);

View File

@ -13,17 +13,17 @@ class LBLFile : public SubFile
{ {
public: public:
LBLFile(const IMG *img) LBLFile(const IMG *img)
: SubFile(img), _huffmanText(0), _table(0), _offset(0), _size(0), : SubFile(img), _huffmanText(0), _table(0), _rasters(0), _offset(0),
_poiOffset(0), _poiSize(0), _imgOffsetIdSize(0), _poiMultiplier(0), _size(0), _poiOffset(0), _poiSize(0), _imgOffsetIdSize(0),
_multiplier(0), _encoding(0) {} _poiMultiplier(0), _multiplier(0), _encoding(0) {}
LBLFile(const QString *path) LBLFile(const QString *path)
: SubFile(path), _huffmanText(0), _table(0), _offset(0), _size(0), : SubFile(path), _huffmanText(0), _table(0), _rasters(0), _offset(0),
_size(0), _poiOffset(0), _poiSize(0), _imgOffsetIdSize(0),
_poiMultiplier(0), _multiplier(0), _encoding(0) {}
LBLFile(const SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
_huffmanText(0), _table(0), _rasters(0), _offset(0), _size(0),
_poiOffset(0), _poiSize(0), _imgOffsetIdSize(0), _poiMultiplier(0), _poiOffset(0), _poiSize(0), _imgOffsetIdSize(0), _poiMultiplier(0),
_multiplier(0), _encoding(0) {} _multiplier(0), _encoding(0) {}
LBLFile(const SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
_huffmanText(0), _table(0), _offset(0), _size(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,10 +36,7 @@ public:
QImage readImage(Handle &hdl, quint32 id) const; QImage readImage(Handle &hdl, quint32 id) const;
private: private:
struct File { struct Image {
File() : offset(0), size(0) {}
File(quint32 offset, quint32 size) : offset(offset), size(size) {}
quint32 offset; quint32 offset;
quint32 size; quint32 size;
}; };
@ -48,11 +45,12 @@ private:
Label label6b(Handle &hdl, quint32 offset, bool capitalize) const; Label label6b(Handle &hdl, quint32 offset, bool capitalize) const;
Label label8b(Handle &hdl, quint32 offset, bool capitalize) const; Label label8b(Handle &hdl, quint32 offset, bool capitalize) const;
Label labelHuffman(Handle &hdl, quint32 offset, bool capitalize) const; Label labelHuffman(Handle &hdl, quint32 offset, bool capitalize) const;
bool loadFiles(Handle &hdl, quint32 count, quint32 offset, bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
quint32 recordSize); quint32 recordSize);
HuffmanText *_huffmanText; HuffmanText *_huffmanText;
quint32 *_table; quint32 *_table;
Image *_rasters;
TextCodec _codec; TextCodec _codec;
quint32 _offset; quint32 _offset;
quint32 _size; quint32 _size;
@ -60,12 +58,11 @@ private:
quint32 _poiSize; quint32 _poiSize;
quint32 _imgOffset; quint32 _imgOffset;
quint32 _imgSize; quint32 _imgSize;
quint32 _imgCount;
quint8 _imgOffsetIdSize; quint8 _imgOffsetIdSize;
quint8 _poiMultiplier; quint8 _poiMultiplier;
quint8 _multiplier; quint8 _multiplier;
quint8 _encoding; quint8 _encoding;
QVector<File> _rasters;
}; };
#endif // LBLFILE_H #endif // LBLFILE_H