Skip to content
This repository has been archived by the owner on Mar 6, 2022. It is now read-only.

Commit

Permalink
add comments in decodeRAC and decodeLZSS
Browse files Browse the repository at this point in the history
Both functions handle LZSS compressed data, yet, have subtitle
differences which makes factorisation less straightfoward.
  • Loading branch information
cyxx committed Mar 27, 2017
1 parent c391128 commit b570c94
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions decoder.cpp
Expand Up @@ -13,12 +13,13 @@ void decodeLZSS(const uint8_t *src, uint8_t *dst, int decodedSize) {
*dst++ = *src++;
--decodedSize;
} else {
// LE16 - offset,count - bits == 4
const int offset = (src[1] << 4) | (src[0] >> 4);
int size = (src[0] & 15) + 2;
assert(decodedSize >= size);
int count = (src[0] & 15) + 2;
assert(decodedSize >= count);
src += 2;
decodedSize -= size;
while (size-- != 0) {
decodedSize -= count;
while (count-- != 0) {
*dst = *(dst - offset - 1);
++dst;
}
Expand All @@ -36,18 +37,19 @@ void decodeRAC(const uint8_t *src, uint8_t *dst, int decodedSize) {
*dst++ = *src++;
--decodedSize;
} else {
// LE16 - count,offset - bits == 10
int offset = READ_LE_UINT16(src); src += 2;
const int count = (offset >> bits) + 2;
int count = (offset >> bits) + 2;
offset &= (1 << bits) - 1;
if (offset == 0) {
return;
}
assert(decodedSize >= count);
for (int j = 0; j < count; ++j) {
dst[j] = dst[j - offset];
}
dst += count;
decodedSize -= count;
while (count-- != 0) {
*dst = *(dst - offset);
++dst;
}
}
}
}
Expand Down

0 comments on commit b570c94

Please sign in to comment.