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

Allow for negative clevels in Zstd #165

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/HDF5Plugin-Zstandard/zstd_h5plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ DLL_EXPORT size_t zstd_filter(unsigned int flags, size_t cd_nelmts,
aggression = (int)cd_values[0];
else
aggression = ZSTD_CLEVEL_DEFAULT;
if (aggression < 1 /*ZSTD_minCLevel()*/)
aggression = 1 /*ZSTD_minCLevel()*/;
if (aggression < ZSTD_minCLevel())
aggression = ZSTD_minCLevel();
else if (aggression > ZSTD_maxCLevel())
aggression = ZSTD_maxCLevel();

Expand Down
12 changes: 7 additions & 5 deletions src/hdf5plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class Zstd(_FilterRefClass):
**hdf5plugin.Zstd())
f.close()

:param int clevel: Compression level from 1 (lowest compression) to 22 (maximum compression).
:param int clevel: Compression level from -131072 (lowest compression) to 22 (maximum compression).
Ultra compression extends from 20 through 22. Default: 3.

.. code-block:: python
Expand All @@ -405,11 +405,13 @@ class Zstd(_FilterRefClass):
"""
filter_id = ZSTD_ID

def __init__(self, clevel=3):
assert 1 <= clevel <= 22
self.filter_options = (clevel,)

def __init__(self, clevel=None):
if clevel is not None:
# filter_options are passed as uints: conversion needed to pass negative clevel
clevel = _ctypes.c_uint(clevel).value
self.filter_options = (clevel,)


def _init_filters():
"""Initialise and register HDF5 filters with h5py

Expand Down