Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect libdeflate >= 1.9 and adjust CRAM RN encoding. #1383

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cram/cram_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,8 +1108,8 @@ char *zlib_mem_inflate(char *cdata, size_t csize, size_t *size) {
static char *libdeflate_deflate(char *data, size_t size, size_t *cdata_size,
int level, int strat) {
level = level > 0 ? level : 6; // libdeflate doesn't honour -1 as default
level *= 1.2; // NB levels go up to 12 here; 5 onwards is +1
if (level >= 8) level += level/8; // 8->10, 9->12
level *= 1.23; // NB levels go up to 12 here; 5 onwards is +1
level += level>=8; // 5,6,7->6,7,8 8->10 9->12
if (level > 12) level = 12;

if (strat == Z_RLE) // not supported by libdeflate
Expand Down Expand Up @@ -1213,6 +1213,7 @@ char *zlib_mem_inflate(char *cdata, size_t csize, size_t *size) {
}
#endif

#if !defined(HAVE_LIBDEFLATE) || LIBDEFLATE_VERSION_MAJOR < 1 || (LIBDEFLATE_VERSION_MAJOR == 1 && LIBDEFLATE_VERSION_MINOR <= 8)
static char *zlib_mem_deflate(char *data, size_t size, size_t *cdata_size,
int level, int strat) {
z_stream s;
Expand Down Expand Up @@ -1269,6 +1270,7 @@ static char *zlib_mem_deflate(char *data, size_t size, size_t *cdata_size,
}
return (char *)cdata;
}
#endif

#ifdef HAVE_LIBLZMA
/* ------------------------------------------------------------------------ */
Expand Down Expand Up @@ -1754,9 +1756,11 @@ static char *cram_compress_by_method(cram_slice *s, char *in, size_t in_size,
//
// Eg RN at level 5; libdeflate=55.9MB zlib=51.6MB
#ifdef HAVE_LIBDEFLATE
# if (LIBDEFLATE_VERSION_MAJOR < 1 || (LIBDEFLATE_VERSION_MAJOR == 1 && LIBDEFLATE_VERSION_MINOR <= 8))
if (content_id == DS_RN && level >= 4 && level <= 7)
return zlib_mem_deflate(in, in_size, out_size, level, strat);
else
# endif
return libdeflate_deflate(in, in_size, out_size, level, strat);
#else
return zlib_mem_deflate(in, in_size, out_size, level, strat);
Expand Down