Skip to main content

Grok (JPEG2000 codec) plugin for Blosc2.

Project description

Blosc2 grok

A plugin of the excellent grok library for Blosc2. grok is a JPEG2000 codec, and with this plugin, you can use it as yet another codec in applications using Blosc2. See an example of use at: https://github.com/Blosc/blosc2_grok/blob/main/examples/params.py

Installation

For using blosc2_grok you will first have to install its wheel:

pip install blosc2-grok -U

Usage

import blosc2
import numpy as np
import blosc2_grok
from PIL import Image

# Set the params for the grok codec
kwargs = {}
kwargs['cod_format'] = blosc2_grok.GrkFileFmt.GRK_FMT_JP2
kwargs['quality_mode'] = "dB"
kwargs['quality_layers'] = np.array([5], dtype=np.float64)
blosc2_grok.set_params_defaults(**kwargs)

# Define the compression and decompression parameters for Blosc2.
# Disable the filters and do not split blocks (these won't work with grok).
cparams = {
    'codec': blosc2.Codec.GROK,
    'filters': [],
    'splitmode': blosc2.SplitMode.NEVER_SPLIT,
}

# Read the image
im = Image.open("examples/kodim23.png")
# Convert the image to a numpy array
np_array = np.asarray(im)

# Transform the numpy array to a blosc2 array. This is where compression happens, and
# the HTJ2K codec is called.
bl_array = blosc2.asarray(
    np_array,
    chunks=np_array.shape,
    blocks=np_array.shape,
    cparams=cparams,
    urlpath="examples/kodim23.b2nd",
    mode="w",
)

# Print information about the array, see the compression ratio (cratio)
print(bl_array.info)

Parameters for compression

The following parameters are available for compression for grok, with their defaults. Most of them are named after the ones in the Pillow library and have the same meaning. The ones that are not in Pillow are marked with a * and you can get more information about them in the grok documentation, or by following the provided links. For those marked with a **, you can get more information in the grok.h header.

'tile_size': (0, 0),
'tile_offset': (0, 0),
'quality_mode': None,
'quality_layers': np.zeros(0, dtype=np.float64),
'progression': "LRCP",
'num_resolutions': 6,
'codeblock_size': (64, 64),
'irreversible': False,
'precinct_size': (0, 0),
'offset': (0, 0),
'mct': 0,
* 'numgbits': 2,  # Equivalent to -N, -guard_bits
* 'roi_compno': -1,  # Together with 'roi_shift' it is equivalent to -R, -ROI
* 'roi_shift': 0,
* 'decod_format': GrkFileFmt.GRK_FMT_UNK,
* 'cod_format': GrkFileFmt.GRK_FMT_UNK,
* 'rsiz': GrkProfile.GRK_PROFILE_NONE,  # Equivalent to -Z, -rsiz
* 'framerate': 0,
* 'apply_icc_': False,  # Equivalent to -f, -apply_icc
* 'rateControlAlgorithm': GrkRateControl.BISECT,
* 'num_threads': 0,
* 'deviceId': 0,  # Equivalent to -G, -device_id
* 'duration': 0,  # Equivalent to -J, -duration
* 'repeats': 1,  # Equivalent to -e, -repetitions
* 'mode': GrkMode.DEFAULT,  # Equivalent to -M, -mode
* 'verbose': False,  # Equivalent to -v, -verbose
** 'enableTilePartGeneration': False,  # See header of grok.h above
** 'max_cs_size': 0,  # See header of grok.h above
** 'max_comp_size': 0,  # See header of grok.h above

More examples

See the examples directory for more examples.

Thanks

Thanks to Marta Iborra, from the Blosc Development Team, for doing most of the job in making this plugin possible, and J. David Ibáñez and Francesc Alted for the initial contributions. Also, thanks to Aaron Boxer, the original author of the grok library, for his help in ironing out issues for making this interaction possible.

That's all folks!

The Blosc Development Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

blosc2_grok-0.2.0-py3-none-win_amd64.whl (4.0 MB view details)

Uploaded Python 3Windows x86-64

blosc2_grok-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

blosc2_grok-0.2.0-py3-none-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

blosc2_grok-0.2.0-py3-none-macosx_10_9_x86_64.whl (1.9 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file blosc2_grok-0.2.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: blosc2_grok-0.2.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 4.0 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for blosc2_grok-0.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a6bed39fe07160293e7ba0421cc9a0876eaf5470ed674664ce953e7c3d82eed2
MD5 1209cef30800d540129a11b71b827b9f
BLAKE2b-256 74704179f326da9ce54fa972bf1e548851336b57467b8416bc2012529d684f81

See more details on using hashes here.

File details

Details for the file blosc2_grok-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blosc2_grok-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 888a5ab4449728b4a36c03cb504b87c55803301216fd1e8bb8d295ab8558eef7
MD5 c218cbf31e8a7d8a187a8233fff0b03c
BLAKE2b-256 eb16599ae12770245164ff7706fc30cf10b055bc3aaa345bf8e6a9bb59c7ecf8

See more details on using hashes here.

File details

Details for the file blosc2_grok-0.2.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for blosc2_grok-0.2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 977434228c26e3151ef4b160a77f58eec71bf7aa9c10bda148246a59461ae2d8
MD5 35009bbd7f81cfc31a656b659cb93eaf
BLAKE2b-256 88b88e004f33fbe5d37e272c691a904abaeccd79f12867a1fec01efc082764b6

See more details on using hashes here.

File details

Details for the file blosc2_grok-0.2.0-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for blosc2_grok-0.2.0-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1a7b254a4a77ecf56448b7427adf5928d4264e9255faa527332c889204fee989
MD5 d67143384989b2562ccb03682f712010
BLAKE2b-256 55e968427e07d3981d37049a9465841e1a18996186fe2a50ec28e86aac076e43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page