mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Added an optimized subfile block read
This commit is contained in:
parent
d2a1271348
commit
731f2d7e6d
@ -16,9 +16,5 @@ bool HuffmanBuffer::load(const RGNFile *rgn, SubFile::Handle &rgnHdl)
|
||||
};
|
||||
|
||||
resize(recordSize);
|
||||
for (int i = 0; i < QByteArray::size(); i++)
|
||||
if (!rgn->readByte(rgnHdl, (quint8*)(data() + i)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return rgn->read(rgnHdl, (quint8*)data(), recordSize);
|
||||
}
|
||||
|
@ -338,8 +338,7 @@ QImage LBLFile::readImage(Handle &hdl, quint32 id) const
|
||||
return QImage();
|
||||
QByteArray ba;
|
||||
ba.resize(_rasters.at(id).size);
|
||||
for (int i = 0; i < ba.size(); i++)
|
||||
if (!readByte(hdl, (quint8*)(ba.data() + i)))
|
||||
if (!read(hdl, (quint8*)ba.data(), _rasters.at(id).size))
|
||||
return QImage();
|
||||
|
||||
return QImage::fromData(ba);
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <QFile>
|
||||
#include <cstring>
|
||||
#include "img.h"
|
||||
#include "subfile.h"
|
||||
|
||||
@ -115,3 +115,27 @@ bool SubFile::readVBitfield32(Handle &hdl, quint32 &bitfield) const
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubFile::read(Handle &handle, quint8 *buff, quint32 size) const
|
||||
{
|
||||
while (size) {
|
||||
quint32 remaining = handle._data.size() - handle._blockPos;
|
||||
if (size < remaining) {
|
||||
memcpy(buff, handle._data.constData() + handle._blockPos, size);
|
||||
handle._blockPos += size;
|
||||
handle._pos++;
|
||||
return true;
|
||||
} else {
|
||||
memcpy(buff, handle._data.constData() + handle._blockPos,
|
||||
remaining);
|
||||
buff += remaining;
|
||||
size -= remaining;
|
||||
handle._blockPos = 0;
|
||||
handle._pos += remaining;
|
||||
if (!seek(handle, handle._pos))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -60,6 +60,8 @@ public:
|
||||
bool seek(Handle &handle, quint32 pos) const;
|
||||
quint32 pos(Handle &handle) const {return handle._pos;}
|
||||
|
||||
bool read(Handle &handle, quint8 *buff, quint32 size) const;
|
||||
|
||||
bool readByte(Handle &handle, quint8 *val) const
|
||||
{
|
||||
*val = handle._data.at(handle._blockPos++);
|
||||
|
Loading…
Reference in New Issue
Block a user