Skip to content

Commit

Permalink
compress example: --transformation argument
Browse files Browse the repository at this point in the history
Note that the examples must not be called from the project root, because
then the root's blosc2_openhtj2k will be picked up, instead of the one
installed.
  • Loading branch information
jdavid committed Aug 25, 2023
1 parent 06e225c commit 056dbab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
19 changes: 13 additions & 6 deletions examples/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
2 changes: 0 additions & 2 deletions src/blosc2_htj2k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ int blosc2_openhtj2k_decoder(
}




int set_params_defaults(
uint8_t qfactor,
bool isJPH,
Expand Down
4 changes: 2 additions & 2 deletions src/test_j2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

This comment has been minimized.

Copy link
@FrancescAlted

FrancescAlted Aug 28, 2023

Member

'/tmp' is defined in Windows?


/* Helper function to register the codec */
void openhtj2k_register(blosc2_codec *codec) {
Expand Down

0 comments on commit 056dbab

Please sign in to comment.