Metadata-Version: 2.4
Name: jp15
Version: 0.1.0
Summary: Python bindings for OpenJPH HTJ2K encode/decode
Author: Alessandro A. Grande
License: BSD-2-Clause
License-File: LICENSE
Requires-Python: >=3.12
Requires-Dist: numpy<3,>=2
Provides-Extra: dev
Requires-Dist: pre-commit>=4.3; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest>=8; extra == 'test'
Requires-Dist: zarr>=3.1.3; extra == 'test'
Provides-Extra: zarr
Requires-Dist: zarr>=3.1.3; extra == 'zarr'
Description-Content-Type: text/markdown

# jp15

Python bindings for OpenJPH HTJ2K encode/decode, with an optional Zarr v3 codec.

## Installation

```bash
pip install "jp15[zarr]"   # with Zarr codec support
pip install jp15           # encode/decode only
```

## Basic usage

```python
import jp15
import numpy as np

data = np.random.randint(0, 60000, (64, 128), dtype=np.uint16)

encoded = jp15.encode(
    data,
    irreversible=False,
    qstep=None,
    num_decompositions=5,
    block_size=(64, 64),
    progression_order="LRCP",
    color_transform=False,
    planar=True,
)
decoded = jp15.decode(encoded)

np.testing.assert_array_equal(decoded, data)
```

`decode` requires no dtype or shape hint from the caller. HTJ2K codestreams carry a SIZ
(image size) marker in their header that records the image dimensions, number of
components, bit depth, and signedness at encode time. `decode` reads this marker and
uses it to allocate the output buffer and select the correct element type, so the
reconstructed array always matches the original without any extra bookkeeping on the
caller's side.

## Zarr v3 codec

`OpenJPHCodec` is a Zarr v3 array-to-bytes codec passed in the array's `codecs` pipeline.

```python
from jp15.zarr import OpenJPHCodec
import numpy as np
import zarr

data = np.arange(64 * 96, dtype=np.uint16).reshape(64, 96)

array = zarr.create(
    store="example.zarr",
    shape=data.shape,
    chunks=data.shape,
    dtype=data.dtype,
    codecs=[OpenJPHCodec(layout="yx")],
    zarr_format=3,
)

array[:] = data
np.testing.assert_array_equal(array[:], data)
```
