implement RLE decode

This commit is contained in:
2019-02-08 14:44:34 +01:00
parent d8f23adb35
commit 1876207afb
2 changed files with 60 additions and 3 deletions

View File

@@ -85,6 +85,38 @@ public:
skip(bytes);
return ret;
}
std::vector<uint8_t> rrle(size_t encoded_bytes)
{
std::vector<uint8_t> data;
int32_t n;
for (int j = 0; j < encoded_bytes;)
{
n = ri8();
j++;
// force sign
if (n >= 128)
n -= 256; // can this even happen?
// copy the following char -n + 1 times
if (n < 0)
{
// NOP
if (n == -128)
continue;
n = -n + 1;
j++;
for (int c = 0; c < n; c++)
data.push_back(ru8());
}
else
{
// read the following n + 1 chars (no compr)
for (int c = 0; c < n + 1; c++, j++)
data.push_back(ru8());
}
}
return data;
}
protected:
template<typename T> inline T align4(T x) { return ((x - T{1}) & (~(T{3}))) + T{4}; }
template<typename T> T read()