diff --git a/examples/compress.py b/examples/compress.py index 7013278..6679279 100644 --- a/examples/compress.py +++ b/examples/compress.py @@ -11,8 +11,14 @@ # This is done once. blosc2.register_codec("openhtj2k", 244) -def compress(im, urlpath=None): - """This function gets a PIL image and returns a blosc2 array. +def compress(im, urlpath=None, **kwargs): + """ + This function gets a PIL image and returns a Blosc2 array. + + If the optional argument urlpath is given, the Blosc2 array will be saved to that + location. + + Other keyword arguments are passed to blosc2_openhtj2k.set_params_defaults(...) """ # Convert the image to a numpy array np_array = np.asarray(im) @@ -28,9 +34,7 @@ def compress(im, urlpath=None): np_array = np_array.astype('uint32') # Set the parameters that will be used by the codec - blosc2_openhtj2k.set_params_defaults( - transformation=0, # 0:lossy 1:lossless (default is 1) - ) + blosc2_openhtj2k.set_params_defaults(**kwargs) # Multithreading is not supported, so we must set the number of threads to 1 nthreads = 1 @@ -68,8 +72,11 @@ def compress(im, urlpath=None): ) parser.add_argument('inputfile') parser.add_argument('outputfile') + parser.add_argument('--transformation', type=int, help='0:lossy 1:lossless (default is 1)') args = parser.parse_args() + kwargs = {k: v for k, v in args._get_kwargs() if k in blosc2_openhtj2k.params_defaults} + im = Image.open(args.inputfile) Path(args.outputfile).unlink(missing_ok=True) - compress(im, args.outputfile) + compress(im, args.outputfile, **kwargs) diff --git a/src/blosc2_htj2k.cpp b/src/blosc2_htj2k.cpp index a54d266..7e58fc6 100644 --- a/src/blosc2_htj2k.cpp +++ b/src/blosc2_htj2k.cpp @@ -278,8 +278,6 @@ int blosc2_openhtj2k_decoder( } - - int set_params_defaults( uint8_t qfactor, bool isJPH, diff --git a/src/test_j2k.c b/src/test_j2k.c index 3ae03b1..03f05f8 100644 --- a/src/test_j2k.c +++ b/src/test_j2k.c @@ -27,8 +27,8 @@ #include "utils.h" #define BLOSC_CODEC_OPENHTJ2K 244 -#define IFNAME "examples/teapot.ppm" -#define OFNAME "examples/teapot2.ppm" +#define IFNAME "teapot.ppm" +#define OFNAME "/tmp/teapot2.ppm" /* Helper function to register the codec */ void openhtj2k_register(blosc2_codec *codec) {