UPDATED: sdefl and sinfl compression libraries

This commit is contained in:
Ray
2023-06-30 09:47:16 +02:00
parent ceafbcf9d2
commit e190b7eee9
2 changed files with 155 additions and 68 deletions

28
src/external/sinfl.h vendored
View File

@ -72,7 +72,7 @@ Results on the [Silesia compression corpus](http://sun.aei.polsl.pl/~sdeor/index
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2020 Micha Mettke
Copyright (c) 2020-2023 Micha Mettke
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
@ -400,17 +400,21 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size)
} break;
case stored: {
/* uncompressed block */
int len, nlen;
sinfl_refill(&s);
unsigned len, nlen;
sinfl__get(&s,s.bitcnt & 7);
len = sinfl__get(&s,16);
nlen = sinfl__get(&s,16);
in -= 2; s.bitcnt = 0;
len = (unsigned short)sinfl__get(&s,16);
nlen = (unsigned short)sinfl__get(&s,16);
s.bitptr -= s.bitcnt / 8;
s.bitbuf = s.bitcnt = 0;
if (len > (e-in) || !len)
if ((unsigned short)len != (unsigned short)~nlen)
return (int)(out-o);
memcpy(out, in, (size_t)len);
in += len, out += len;
if (len > (e - s.bitptr) || !len)
return (int)(out-o);
memcpy(out, s.bitptr, (size_t)len);
s.bitptr += len, out += len;
if (last) return (int)(out-o);
state = hdr;
} break;
case fixed: {
@ -443,8 +447,9 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size)
/* decode code lengths */
for (n = 0; n < nlit + ndist;) {
int sym = 0;
sinfl_refill(&s);
int sym = sinfl_decode(&s, hlens, 7);
sym = sinfl_decode(&s, hlens, 7);
switch (sym) {default: lens[n++] = (unsigned char)sym; break;
case 16: for (i=3+sinfl_get(&s,2);i;i--,n++) lens[n]=lens[n-1]; break;
case 17: for (i=3+sinfl_get(&s,3);i;i--,n++) lens[n]=0; break;
@ -458,8 +463,9 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size)
case blk: {
/* decompress block */
while (1) {
int sym;
sinfl_refill(&s);
int sym = sinfl_decode(&s, s.lits, 10);
sym = sinfl_decode(&s, s.lits, 10);
if (sym < 256) {
/* literal */
if (sinfl_unlikely(out >= oe)) {