-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Python example in compress and decompress
- Loading branch information
Showing
3 changed files
with
60 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,29 +59,22 @@ jobs: | |
env: | ||
CIBW_BUILD: 'cp38-win_amd64 cp39-win_amd64 cp310-win_amd64 cp311-win_amd64' | ||
CIBW_BEFORE_TEST: python -m pip install --upgrade pip && python -m pip install -r requirements-test.txt | ||
CIBW_TEST_COMMAND: cmd /V /C "set "BLOSC_TRACE=1" && python {project}/examples/test.py {project}/examples/teapot.ppm" | ||
CIBW_TEST_COMMAND: > | ||
cmd /V /C "python {project}/examples/compress.py {project}/examples/teapot.ppm /tmp/teapot.b2nd" | ||
CIBW_BUILD_VERBOSITY: 1 | ||
|
||
- name: Build wheels (Mac OSX arm64) | ||
if: ${{ matrix.os == 'macos-latest' && matrix.arch == 'arm64' }} | ||
uses: pypa/[email protected] | ||
env: | ||
CIBW_BUILD: 'cp38-* cp39-* cp310-* cp311-*' | ||
CIBW_BEFORE_TEST: python -m pip install --upgrade pip && python -m pip install -r requirements-test.txt | ||
CIBW_TEST_COMMAND: BLOSC_TRACE=1 python {project}/examples/test.py {project}/examples/teapot.ppm | ||
CIBW_BUILD_VERBOSITY: 1 | ||
CIBW_ARCHS_MACOS: "arm64" | ||
|
||
- name: Build wheels (Linux / Mac OSX) | ||
if: ${{ matrix.os != 'windows-latest' && (matrix.arch == 'x86_64' || matrix.arch == 'aarch64') }} | ||
uses: pypa/[email protected] | ||
env: | ||
CIBW_BEFORE_BUILD: python -m pip install --upgrade pip && python -m pip install -r requirements-build.txt | ||
CIBW_BUILD: 'cp38-* cp39-* cp310-* cp311-*' | ||
CIBW_SKIP: '*-manylinux*_i686 *-musllinux_* ${{ env.CIBW_SKIP}}' | ||
#CIBW_SKIP: '*-manylinux*_i686 *-musllinux_* ${{env.CIBW_SKIP}}' | ||
CIBW_ARCHS_LINUX: ${{ matrix.arch }} | ||
CIBW_BEFORE_TEST: python -m pip install --upgrade pip && python -m pip install -r requirements-test.txt | ||
CIBW_TEST_COMMAND: BLOSC_TRACE=1 python {project}/examples/test.py {project}/examples/teapot.ppm | ||
CIBW_TEST_COMMAND: > | ||
python {project}/examples/compress.py {project}/examples/teapot.ppm /tmp/teapot.b2nd && | ||
python {project}/examples/decompress.py /tmp/teapot.b2nd /tmp/teapot.ppm | ||
CIBW_BUILD_VERBOSITY: 1 | ||
CIBW_ARCHS_MACOS: "x86_64" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import argparse | ||
|
||
import blosc2 | ||
import numpy as np | ||
from PIL import Image | ||
|
||
|
||
# Register the codec, with this number we will tell blosc2 to use the openhj2k codec. | ||
# This is done once. | ||
blosc2.register_codec("openhtj2k", 244) | ||
|
||
def decompress(array): | ||
"""This function gets a blosc2 array and returns a PIL image. | ||
""" | ||
# Transform the blosc2 array to a numpy array. This is where decompression happens. | ||
np_array = array[:] | ||
|
||
# Get back 1 byte per color (the codec works with uint32) | ||
np_array = np_array.astype('uint8') | ||
|
||
# Get back the original shape: height, width, channel | ||
np_array = np.transpose(np_array, (2, 1, 0)) | ||
|
||
# Transfom the numpy array to a PIL image | ||
im = Image.fromarray(np_array) | ||
|
||
return im | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser( | ||
description='Decompress the given Blosc2 file, and optionally display the image', | ||
) | ||
parser.add_argument('inputfile') | ||
parser.add_argument('outputfile') | ||
parser.add_argument('--show', action='store_true') | ||
args = parser.parse_args() | ||
|
||
array = blosc2.open(args.inputfile) | ||
im = decompress(array) | ||
im.save(args.outputfile) | ||
|
||
if args.show: | ||
im.show() |