mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
A much more sane raster tabel load...
This commit is contained in:
parent
af3b41cc92
commit
a2390ae26f
@ -55,11 +55,24 @@ static QString capitalized(const QString &str)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static quint8 byteSize(quint32 val)
|
||||
{
|
||||
quint8 ret = 0;
|
||||
|
||||
do {
|
||||
ret++;
|
||||
val = val >> 8;
|
||||
} while (val != 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
LBLFile::~LBLFile()
|
||||
{
|
||||
delete _huffmanText;
|
||||
delete[] _table;
|
||||
delete[] _rasters;
|
||||
}
|
||||
|
||||
bool LBLFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
|
||||
@ -101,18 +114,9 @@ bool LBLFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
|
||||
&& readUInt32(hdl, _imgSize)))
|
||||
return false;
|
||||
|
||||
if (size && recordSize) {
|
||||
quint32 count = size / recordSize;
|
||||
quint32 maxId = count - 1;
|
||||
_imgOffsetIdSize = 0;
|
||||
do {
|
||||
_imgOffsetIdSize++;
|
||||
maxId = maxId >> 8;
|
||||
} while (maxId != 0);
|
||||
|
||||
if (!loadFiles(hdl, count, offset, recordSize))
|
||||
if (size && recordSize)
|
||||
if (!loadRasterTable(hdl, offset, size, recordSize))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (_encoding == 11) {
|
||||
@ -130,8 +134,10 @@ void LBLFile::clear()
|
||||
{
|
||||
delete _huffmanText;
|
||||
delete[] _table;
|
||||
delete[] _rasters;
|
||||
_huffmanText = 0;
|
||||
_table = 0;
|
||||
_rasters = 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_rasters.resize(count);
|
||||
quint32 prev, cur;
|
||||
|
||||
for (quint32 i = 0; i < count; i++) {
|
||||
quint32 currentOffset, nextOffset, size;
|
||||
_imgCount = size / recordSize;
|
||||
_imgOffsetIdSize = byteSize(_imgCount - 1);
|
||||
_rasters = new Image[_imgCount];
|
||||
|
||||
if (!(seek(hdl, offset + i * recordSize)
|
||||
&& readVUInt32(hdl, recordSize, currentOffset)))
|
||||
if (!(seek(hdl, offset) && readVUInt32(hdl, recordSize, prev)))
|
||||
return false;
|
||||
|
||||
for (quint32 i = 1; i < _imgCount; i++) {
|
||||
if (!readVUInt32(hdl, recordSize, cur))
|
||||
return false;
|
||||
if (i == count - 1)
|
||||
nextOffset = _imgSize;
|
||||
else {
|
||||
if (!readVUInt32(hdl, recordSize, nextOffset))
|
||||
return false;
|
||||
}
|
||||
size = nextOffset - currentOffset;
|
||||
|
||||
_rasters[i] = File(currentOffset, size);
|
||||
_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;
|
||||
}
|
||||
|
||||
QImage LBLFile::readImage(Handle &hdl, quint32 id) const
|
||||
{
|
||||
if (id >= (quint32)_rasters.size())
|
||||
if (id >= _imgCount)
|
||||
return QImage();
|
||||
|
||||
if (!seek(hdl, _imgOffset + _rasters.at(id).offset))
|
||||
if (!seek(hdl, _imgOffset + _rasters[id].offset))
|
||||
return QImage();
|
||||
QByteArray ba;
|
||||
ba.resize(_rasters.at(id).size);
|
||||
if (!read(hdl, ba.data(), _rasters.at(id).size))
|
||||
ba.resize(_rasters[id].size);
|
||||
if (!read(hdl, ba.data(), _rasters[id].size))
|
||||
return QImage();
|
||||
|
||||
return QImage::fromData(ba);
|
||||
|
@ -13,17 +13,17 @@ class LBLFile : public SubFile
|
||||
{
|
||||
public:
|
||||
LBLFile(const IMG *img)
|
||||
: SubFile(img), _huffmanText(0), _table(0), _offset(0), _size(0),
|
||||
_poiOffset(0), _poiSize(0), _imgOffsetIdSize(0), _poiMultiplier(0),
|
||||
_multiplier(0), _encoding(0) {}
|
||||
: SubFile(img), _huffmanText(0), _table(0), _rasters(0), _offset(0),
|
||||
_size(0), _poiOffset(0), _poiSize(0), _imgOffsetIdSize(0),
|
||||
_poiMultiplier(0), _multiplier(0), _encoding(0) {}
|
||||
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),
|
||||
_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();
|
||||
|
||||
bool load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl);
|
||||
@ -36,10 +36,7 @@ public:
|
||||
QImage readImage(Handle &hdl, quint32 id) const;
|
||||
|
||||
private:
|
||||
struct File {
|
||||
File() : offset(0), size(0) {}
|
||||
File(quint32 offset, quint32 size) : offset(offset), size(size) {}
|
||||
|
||||
struct Image {
|
||||
quint32 offset;
|
||||
quint32 size;
|
||||
};
|
||||
@ -48,11 +45,12 @@ private:
|
||||
Label label6b(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;
|
||||
bool loadFiles(Handle &hdl, quint32 count, quint32 offset,
|
||||
bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
|
||||
quint32 recordSize);
|
||||
|
||||
HuffmanText *_huffmanText;
|
||||
quint32 *_table;
|
||||
Image *_rasters;
|
||||
TextCodec _codec;
|
||||
quint32 _offset;
|
||||
quint32 _size;
|
||||
@ -60,12 +58,11 @@ private:
|
||||
quint32 _poiSize;
|
||||
quint32 _imgOffset;
|
||||
quint32 _imgSize;
|
||||
quint32 _imgCount;
|
||||
quint8 _imgOffsetIdSize;
|
||||
quint8 _poiMultiplier;
|
||||
quint8 _multiplier;
|
||||
quint8 _encoding;
|
||||
|
||||
QVector<File> _rasters;
|
||||
};
|
||||
|
||||
#endif // LBLFILE_H
|
||||
|
Loading…
Reference in New Issue
Block a user