Metadata-Version: 2.4
Name: hufi
Version: 0.1.5
Summary: A Python library for encoding and decoding .hufi image files.
Author: Hagan Ernest Pereira
License-Expression: Apache-2.0
Project-URL: Homepage, https://hagan-studios.github.io/HUFI/
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Pillow>=9.0.0
Dynamic: license-file

# HUFI (`hufipy`)

A lightweight Python library for encoding, decoding, and inspecting **`.hufi`** (Hagan's Ultimate Format for Images) files. 

`.hufi` is a custom binary image format that pairs horizontal predictive sub-filtering with zlib Deflate compression to achieve fast, efficient, lossless image storage.

---

## Installation

Install via `pip`:

```bash
pip install hufi

```

---

## Quickstart

### 1. Save and Open `.hufi` Files

```python
import hufi

# Convert standard image formats (PNG, JPG, WEBP, etc.) to .hufi
hufi.save("input.png", "output.hufi")

# Load a .hufi file directly as a Pillow (PIL) Image
img = hufi.open_hufi("output.hufi")
img.show()

```

### 2. Extract Metadata Fast

Inspect header details without decompressing the entire image payload:

```python
import hufi

metadata = hufi.get_metadata("output.hufi")
print(f"Dimensions: {metadata['width']}x{metadata['height']} px")
print(f"Channels:   {metadata['channels']}")
print(f"Magic:      {metadata['magic']}")

```

### 3. In-Memory Encoding & Decoding

Work with bytes and Pillow image objects in memory without writing to disk:

```python
import hufi
from PIL import Image

# Encode a PIL Image to raw .hufi bytes
img = Image.open("photo.jpg")
hufi_bytes = hufi.encode(img, level=6)

# Decode raw .hufi bytes back to a PIL Image
restored_img = hufi.decode(hufi_bytes)

```

---

## Technical Specification

The `.hufi` format consists of a 13-byte binary header followed by a compressed payload:

| Field | Type | Size | Description |
| --- | --- | --- | --- |
| **Magic Signature** | ASCII String | 4 Bytes | Magic bytes `b"HUFI"` |
| **Width** | Uint32 (Little-Endian) | 4 Bytes | Image width in pixels |
| **Height** | Uint32 (Little-Endian) | 4 Bytes | Image height in pixels |
| **Channels** | Uint8 | 1 Byte | Color channels (default `3` for RGB) |
| **Payload** | Deflate Bytes | Variable | Horizontal sub-filtered byte deltas compressed via Zlib |

---

## License

Licensed under the Apache License, Version 2.0. See `LICENSE` for details.
