36 return decompress(data.constData(), data.size(), max);
41 int curResult=0, sizeAlloc=max+10;
42 quint16 curBuff=4078, adresse, premOctet=0, i, length;
43 const quint8 *fileData = (
const quint8 *)data;
44 const quint8 *endFileData = fileData + fileSize;
47 if(quint64(sizeAlloc) > 2000 * quint64(fileSize)) {
48 qWarning() <<
"LZS::decompress impossible ratio case" << sizeAlloc << 2000 * quint64(fileSize);
53 if(
result.size() < sizeAlloc) {
56 }
catch(std::bad_alloc) {
66 if(((premOctet >>= 1) & 256) == 0) {
67 premOctet = *fileData++ | 0xff00;
70 if(fileData >= endFileData || curResult >= max) {
71 result.truncate(curResult);
78 curBuff = (curBuff + 1) & 4095;
88 adresse = *fileData++;
90 adresse |= (length & 0xF0) << 4;
91 length = (length & 0xF) + 2 + adresse;
93 for(i=adresse ; i<=length ; ++i)
96 curBuff = (curBuff + 1) & 4095;
110 int curResult=0, sizeAlloc=fileSize*5;
111 quint16 curBuff=4078, adresse, premOctet=0, i, length;
112 const quint8 *fileData = (
const quint8 *)data;
113 const quint8 *endFileData = fileData + fileSize;
115 if(
result.size() < sizeAlloc) {
118 }
catch(std::bad_alloc) {
128 if(((premOctet >>= 1) & 256) == 0) {
129 premOctet = *fileData++ | 0xff00;
132 if(fileData >= endFileData) {
133 result.truncate(curResult);
140 curBuff = (curBuff + 1) & 4095;
150 adresse = *fileData++;
151 length = *fileData++;
152 adresse |= (length & 0xF0) << 4;
153 length = (length & 0xF) + 2 + adresse;
155 for(i=adresse ; i<=length ; ++i)
158 curBuff = (curBuff + 1) & 4095;
178 memcpy(&lzsSize, data, 4);
180 if (lzsSize != size - 4) {
233 for(i=1 ; i<18 ; i++)
235 if((cmp = key[i] -
text_buf[p + i]) != 0)
break;
252 if(rson[
dad[p]] == p)
266 if(
dad[p] == 4096)
return;
272 else if(
lson[p] == 4096)
285 while(
rson[q] != 4096);
288 dad[
lson[q]] = dad[q];
316 quint32 lzsSize =
result.size();
317 result.prepend((
char *)&lzsSize, 4);
323 return compress(fileData.constData(), fileData.size());
328 int i, c, len, r, s, code_buf_ptr,
329 curResult = 0, sizeAlloc = sizeData / 2;
330 unsigned char code_buf[17], mask;
331 const char *dataEnd = data + sizeData;
333 if(
result.size() < sizeAlloc) {
346 for(i=4097 ; i<=4352 ; ++i)
rson[i] = 4096;
347 for(i=0 ; i<4096 ; ++i)
dad[i] = 4096;
351 code_buf_ptr = mask = 1;
360 for(len=0 ; len<18 && data<dataEnd ; ++len)
367 for(i=1 ; i<=18 ; ++i)
381 code_buf[code_buf_ptr++] =
text_buf[r];
389 if((mask <<= 1) == 0)
393 result.replace(curResult, code_buf_ptr, (
char *)code_buf, code_buf_ptr);
394 curResult += code_buf_ptr;
396 code_buf_ptr = mask = 1;
400 for(i=0 ; i < last_match_length && data<dataEnd ; ++i)
409 s = (s + 1) & (4095);
410 r = (r + 1) & (4095);
415 while(i++ < last_match_length)
418 s = (s + 1) & (4095);
419 r = (r + 1) & (4095);
431 result.replace(curResult, code_buf_ptr, (
char *)code_buf, code_buf_ptr);
432 curResult += code_buf_ptr;
434 result.truncate(curResult);
static const QByteArray & decompressAllWithHeader(const QByteArray &data)
static unsigned char text_buf[4113]
static void DeleteNode(qint32 p)
static qint32 match_position
static void InsertNode(qint32 r)
static const QByteArray & compressWithHeader(const QByteArray &fileData)
static const QByteArray & decompress(const QByteArray &data, int max)
static qint32 match_length
static const QByteArray & compress(const QByteArray &fileData)
static const QByteArray & decompressAll(const QByteArray &data)