Metadata-Version: 2.4
Name: qoi-rs
Version: 4.1.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Dist: pillow>=12.0 ; extra == 'pillow'
Provides-Extra: pillow
License-File: LICENSE
Summary: Blazingly fast library for decoding and encoding QOI images
Keywords: qoi,image,rust
Requires-Python: >=3.12
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Source Code, https://codeberg.org/Joshix/qoi-rs-python/

# qoi-rs

Python library made using [qoi](https://crates.io/crates/qoi) and [pyo3](https://crates.io/crates/pyo3).

## Usage

The `decode` function operates on normal python types implementing the Buffer protocol (bytes, memoryview, bytesarray).
The `encode` function returns a custom image object with all information extracted from the qoi image. The raw pixel data is available as a bytes object at the data property.

```py
from qoi_rs import decode, encode

with open("./qoi_test_images/dice.qoi", "rb") as file:
    image = decode(file.read())

qoi_bytes = encode(
    image.data,
    # required
    height=image.height, width=image.width,
    # defaults to "RGB" or "RGBA" depending on bytes in data
    input_channels=image.mode,
    # optional colour space
    colour_space=image.colour_space,
)

assert decode(qoi_bytes).data == image.data
```

### With Pillow

For use with [Pillow](https://pillow.readthedocs.io/en/stable/) are two convenience functions available.
While `encode_pillow` doesn't depend on Pillow and could work with other types, `decode_pillow` tries to import Pillow and fails if it isn't installed. Use `pip install qoi_rs[pillow]` to make sure a supported Pillow version is installed if you use one of these functions with Pillow.

```py
from PIL import Image
from qoi_rs import decode_pillow, encode_pillow

image: Image.Image = Image.open("./qoi_test_images/dice.png")

qoi_bytes: bytes = encode_pillow(image)
decoded: Image.Image = decode_pillow(qoi_bytes)

assert decoded.width == image.width
assert decoded.height == image.height

assert decoded.get_flattened_data() == image.get_flattened_data()

image.close()
decoded.close()
```

