28 #include "vfs/raw/rawdata.h"
29 #include "util/base/exception.h"
31 #include "lzssdecoder.h"
43 m_outlen = outputsize;
45 while (m_outindex < outputsize) {
47 uint16_t bytesToRead = blockdesc & 0x7fff;
49 if (blockdesc & 0x8000) {
50 input->
readInto(output + m_outindex, bytesToRead);
51 m_outindex += bytesToRead;
55 std::vector<uint8_t> indata(bytesToRead + 2);
56 input->
readInto(&indata[0], bytesToRead);
57 LZSSDecode(&indata[0], bytesToRead, output);
64 void LZSSDecoder::LZSSDecode(uint8_t* in , int64_t len, uint8_t* out) {
65 const int64_t c_nRingBufferSize = 4096;
66 const int64_t c_nMatchLengthUpperLimit = 18;
67 const int64_t c_nThreshold = 2;
69 char buffer[c_nRingBufferSize + c_nMatchLengthUpperLimit - 1];
80 for (i = 0; i < c_nRingBufferSize - c_nMatchLengthUpperLimit; i++) {
84 r = c_nRingBufferSize - c_nMatchLengthUpperLimit;
86 while ( ibuf < len ) {
87 if (((flags >>= 1) & 256) == 0) {
94 out[m_outindex++] = c;
97 r &= (c_nRingBufferSize - 1);
102 i |= ((j & 0xf0) << 4);
103 j = (j & 0x0f) + c_nThreshold;
105 for (k = 0; k <= j; k++) {
106 c = buffer[(i + k) & (c_nRingBufferSize - 1)];
108 out[m_outindex++] = c;
111 r &= (c_nRingBufferSize - 1);