TurboPFor: lz compression
This commit is contained in:
44
lz.c
44
lz.c
@ -55,7 +55,7 @@ int lzenc(unsigned char *in, unsigned inlen, unsigned char *out, unsigned outsiz
|
||||
#include "lztc.c"
|
||||
#endif
|
||||
|
||||
#if defined(LZ4)
|
||||
#if defined(LZ4)
|
||||
case P_LZ4: if(codlev > 16) codlev = 16;
|
||||
if(strchr(codprm,'M')) { return !codlev?LZ4_compress_fast((char *)in, (char *)out, inlen, outsize, 4):(codlev<9?LZ4_compress_default((char *)in, (char *)out, inlen, outsize):LZ4_compress_HC((char *)in, (char *)out, inlen, outsize, codlev)); }
|
||||
else { char *q;
|
||||
@ -65,8 +65,8 @@ int lzenc(unsigned char *in, unsigned inlen, unsigned char *out, unsigned outsiz
|
||||
if(strchr(codprm,'f')) opts.autoFlush = 1;
|
||||
opts.frameInfo.blockSizeID = LZ4F_max4MB;
|
||||
if(q=strchr(codprm,'B')) opts.frameInfo.blockSizeID = (LZ4F_blockSizeID_t)atoi(q+(q[1]=='='?2:1));
|
||||
if(opts.frameInfo.blockSizeID>LZ4F_max4MB) opts.frameInfo.blockSizeID=LZ4F_max4MB;
|
||||
else if(opts.frameInfo.blockSizeID && opts.frameInfo.blockSizeID<LZ4F_default) opts.frameInfo.blockSizeID=LZ4F_default;
|
||||
if(opts.frameInfo.blockSizeID>LZ4F_max4MB) opts.frameInfo.blockSizeID=LZ4F_max4MB;
|
||||
else if(opts.frameInfo.blockSizeID && opts.frameInfo.blockSizeID<LZ4F_default) opts.frameInfo.blockSizeID=LZ4F_default;
|
||||
return LZ4F_compressFrame(out, outsize, in, inlen, &opts);
|
||||
}
|
||||
#endif
|
||||
@ -78,35 +78,35 @@ int lzenc(unsigned char *in, unsigned inlen, unsigned char *out, unsigned outsiz
|
||||
case 1 : return ec==2?turborcssxenc(in, inlen, out):turborcssenc(in, inlen, out);
|
||||
case 2 : return turborcnenc( in, inlen, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ZSTD)
|
||||
#if defined(ZSTD)
|
||||
case P_ZSTD:{ ZSTD_CCtx *ctx = ZSTD_createCCtx();
|
||||
ZSTD_parameters p = ZSTD_getParams(codlev, inlen, 0);
|
||||
ZSTD_parameters p = ZSTD_getParams(codlev, inlen, 0);
|
||||
if(dsize) { int windowLog = bsr32(dsize)-powof2(dsize); ZSTD_CCtx_setParameter(ctx, ZSTD_c_windowLog, windowLog); }
|
||||
unsigned rc = ZSTD_compress_advanced(ctx, out, outsize, in, inlen, NULL, 0, p);
|
||||
ZSTD_freeCCtx(ctx);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
case P_FSE: { size_t o = FSE_compress(out, outsize, in, inlen);
|
||||
if(o == 1) { out[0] = in[0]; return 1; }
|
||||
if(!o || o >= inlen) { memcpy(out, in, inlen); return inlen; }
|
||||
return o;
|
||||
}
|
||||
if(o == 1) { out[0] = in[0]; return 1; }
|
||||
if(!o || o >= inlen) { memcpy(out, in, inlen); return inlen; }
|
||||
return o;
|
||||
}
|
||||
case P_FSEH: { size_t o = HUF_compress(out, outsize, in, inlen);
|
||||
if(o == 1) { out[0] = in[0]; return 1; }
|
||||
if(!o || o >= inlen) { memcpy(out, in, inlen); return inlen; }
|
||||
return o;
|
||||
if(!o || o >= inlen) { memcpy(out, in, inlen); return inlen; }
|
||||
return o;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB)
|
||||
case P_ZLIB: { uLongf outlen = outsize; if(codlev < 1) codlev=1; if(codlev>9) codlev=9;
|
||||
int rc = compress2(out, &outlen, in, inlen, codlev);
|
||||
if(rc != Z_OK) printf("zlib compress2 rc=%d\n", rc);
|
||||
return outlen;
|
||||
}
|
||||
#if defined(ZLIB)
|
||||
case P_ZLIB: { uLongf outlen = outsize; if(codlev < 1) codlev=1; if(codlev>9) codlev=9;
|
||||
int rc = compress2(out, &outlen, in, inlen, codlev);
|
||||
if(rc != Z_OK) printf("zlib compress2 rc=%d\n", rc);
|
||||
return outlen;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
@ -118,7 +118,7 @@ int lzdec(unsigned char *in, unsigned inlen, unsigned char *out, unsigned outlen
|
||||
#include "lztd.c"
|
||||
#endif
|
||||
|
||||
#if defined(LZ4)
|
||||
#if defined(LZ4)
|
||||
case P_LZ4:
|
||||
if(strchr(codprm,'M')) { LZ4_decompress_safe((const char *)in, (char *)out, inlen, outlen); break; }
|
||||
else {
|
||||
@ -136,7 +136,7 @@ int lzdec(unsigned char *in, unsigned inlen, unsigned char *out, unsigned outlen
|
||||
case 1 : return ec==2?turborcssxdec(in, outlen, out):turborcssdec( in, outlen, out);
|
||||
case 2 : return turborcndec( in, outlen, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ZSTD)
|
||||
@ -429,7 +429,7 @@ unsigned lztp1xdec(unsigned char *in, unsigned inlen, unsigned char *out, unsign
|
||||
}
|
||||
|
||||
unsigned lztp1zenc(unsigned char *in, unsigned inlen, unsigned char *out, unsigned outsize, unsigned esize, unsigned char *tmp) {
|
||||
bitzenc(in, inlen, out, esize); CPYR(in,inlen,esize,out);
|
||||
bitzenc(in, inlen, out, esize); CPYR(in,inlen,esize,out);
|
||||
bitshuffle(out, inlen, tmp, esize);
|
||||
return lzenc(tmp, inlen, out, outsize, codid, codlev, codprm);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user