mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add util::Buffer, rle::encode16, rle::decode16
This commit is contained in:
parent
728795f0f3
commit
c15abfa715
7 changed files with 144 additions and 31 deletions
|
|
@ -35,6 +35,45 @@ size_t rle::encode(const ubyte* src, size_t srclen, ubyte* dst) {
|
|||
return offset;
|
||||
}
|
||||
|
||||
size_t rle::decode16(const ubyte* src, size_t srclen, ubyte* dst) {
|
||||
auto src16 = reinterpret_cast<const uint16_t*>(src);
|
||||
auto dst16 = reinterpret_cast<uint16_t*>(dst);
|
||||
size_t offset = 0;
|
||||
for (size_t i = 0; i < srclen / 2;) {
|
||||
uint16_t len = src16[i++];
|
||||
uint16_t c = src16[i++];
|
||||
for (size_t j = 0; j <= len; j++) {
|
||||
dst16[offset++] = c;
|
||||
}
|
||||
}
|
||||
return offset * 2;
|
||||
}
|
||||
|
||||
size_t rle::encode16(const ubyte* src, size_t srclen, ubyte* dst) {
|
||||
if (srclen == 0) {
|
||||
return 0;
|
||||
}
|
||||
auto src16 = reinterpret_cast<const uint16_t*>(src);
|
||||
auto dst16 = reinterpret_cast<uint16_t*>(dst);
|
||||
size_t offset = 0;
|
||||
uint16_t counter = 0;
|
||||
uint16_t c = src16[0];
|
||||
for (size_t i = 1; i < srclen / 2; i++) {
|
||||
uint16_t cnext = src16[i];
|
||||
if (cnext != c || counter == 0xFFFF) {
|
||||
dst16[offset++] = counter;
|
||||
dst16[offset++] = c;
|
||||
c = cnext;
|
||||
counter = 0;
|
||||
} else {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
dst16[offset++] = counter;
|
||||
dst16[offset++] = c;
|
||||
return offset * 2;
|
||||
}
|
||||
|
||||
size_t extrle::decode(const ubyte* src, size_t srclen, ubyte* dst) {
|
||||
size_t offset = 0;
|
||||
for (size_t i = 0; i < srclen;) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue