2020-11-10 00:58:19 +01:00
|
|
|
#include "subfile.h"
|
2021-11-02 21:15:22 +01:00
|
|
|
#include "huffmanstream.h"
|
2020-11-10 00:58:19 +01:00
|
|
|
#include "huffmantext.h"
|
|
|
|
|
2021-04-10 15:27:40 +02:00
|
|
|
using namespace IMG;
|
2020-11-10 00:58:19 +01:00
|
|
|
|
2021-11-02 21:15:22 +01:00
|
|
|
bool HuffmanText::load(const RGNFile *rgn, SubFile::Handle &rgnHdl)
|
2020-11-10 00:58:19 +01:00
|
|
|
{
|
2021-11-02 21:15:22 +01:00
|
|
|
if (!_table.load(rgn, rgnHdl))
|
|
|
|
return false;
|
2020-11-10 00:58:19 +01:00
|
|
|
|
2021-11-02 21:15:22 +01:00
|
|
|
Q_ASSERT(!(_table.symbolBits() & 7));
|
|
|
|
return !(_table.symbolBits() & 7);
|
2020-11-10 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HuffmanText::decode(const SubFile *file, SubFile::Handle &hdl,
|
2021-11-02 21:15:22 +01:00
|
|
|
quint32 size, QVector<quint8> &str) const
|
2020-11-10 00:58:19 +01:00
|
|
|
{
|
2021-11-02 21:15:22 +01:00
|
|
|
BitStream4F bs(*file, hdl, size);
|
|
|
|
HuffmanStream<BitStream4F> hs(bs, _table);
|
|
|
|
quint32 sym;
|
|
|
|
|
|
|
|
while (hs.readSymbol(sym)) {
|
|
|
|
for (quint32 i = 0; i < (_table.symbolBits() >> 3); i++) {
|
|
|
|
str.append((quint8)sym);
|
|
|
|
if (((quint8)sym == '\0'))
|
|
|
|
return true;
|
|
|
|
sym = sym >> 8;
|
2020-11-10 00:58:19 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-02 21:15:22 +01:00
|
|
|
|
|
|
|
return false;
|
2020-11-10 00:58:19 +01:00
|
|
|
}
|