dipcompress
Lossless image compression built from scratch — LZ77 + Huffman coding, PNG-style row filters, and a custom .dip binary format. Ships with an optional C extension that makes LZ77 significantly faster, with a pure-Python fallback so it works everywhere.
512x512 PNG → 786,432 B → 301,204 B (-61.7%)
Installation
pip install dipcompress
Requires Python 3.11+. NumPy and Pillow are pulled in automatically.
The C extension is included in the pre-built wheels (Linux x86_64, Windows AMD64, macOS x86_64 + arm64). If you install from source, it compiles automatically via setup.py. If compilation fails, the package still works — it just uses the pure-Python LZ77.
CLI
dipcompress <command> [options]
compress
dipcompress compress photo.png photo.dip
dipcompress c photo.png photo.dip # short alias
dipcompress compress photo.png photo.dip -v # verbose — shows each pipeline stage
Output (non-verbose):
512x512 786,432 B -> 301,204 B (-61.7%)
decompress
dipcompress decompress photo.dip restored.png
dipcompress d photo.dip restored.png # short alias
dipcompress decompress photo.dip restored.png -v
info
Inspect a .dip file without decompressing it:
dipcompress info photo.dip
dipcompress i photo.dip # short alias
Output:
File : photo.dip
Dimensions : 512 x 512 (RGB)
Raw size : 786,432 bytes (768.0 KB)
Stored size : 301,204 bytes (294.1 KB)
Ratio : 0.383 (61.7% smaller)
Row filters : {'Paeth': 301, 'Sub': 124, 'Up': 75, 'None': 12}
Format ver : 1
version
dipcompress --version
Python API
from dipcompress import compress, decompress
# Returns a dict with compression stats
stats = compress("photo.png", "photo.dip")
print(stats["savings_pct"]) # e.g. 61.7
decompress("photo.dip", "restored.png")
compress(input_path, output_path, verbose=False) -> dict
| Key | Type | Description |
|---|---|---|
original_size |
int | Raw pixel bytes |
compressed_size |
int | Final .dip file size |
ratio |
float | compressed / original |
savings_pct |
float | Positive = smaller, negative = larger |
width |
int | Image width in pixels |
height |
int | Image height in pixels |
channels |
int | 1 (grayscale), 3 (RGB), 4 (RGBA) |
filter_stats |
dict | Count of each row filter type used |
decompress(input_path, output_path, verbose=False)
Reconstructs the original pixel data exactly. Output can be any PIL-supported format (.png, .bmp, etc.).
Lower-level utilities
from dipcompress import load_image, save_image, pixels_to_bytes, bytes_to_pixels
from dipcompress import rle_encode, rle_decode
Checking if the C extension loaded
from dipcompress.lz77_fast import using_c
print("C extension active:", using_c)
How it works
Each image goes through a four-stage pipeline:
Image → Row Filters → LZ77 → Huffman → .dip file
1. Row filters — each row is encoded as the delta from a predictor (same idea as PNG). Five filter types are tried per row and the one that produces the smallest byte range wins: None, Sub, Up, Average, Paeth.
2. LZ77 — a sliding-window compressor that replaces repeated byte sequences with (distance, length, literal) tokens. The C extension handles this step when available; otherwise the pure-Python implementation is used.
3. Huffman coding — builds a frequency-based prefix code over the LZ77 byte stream and stores the code table in the file header.
4. .dip format — a custom binary container:
[4B magic: DIP\x01] [2B version] [4B width] [4B height]
[1B channels] [1B compression mode] [4B compressed length]
[height × 1B filter table]
[Huffman table]
[compressed payload]
Magic bytes: 44 49 50 01
Building from source
git clone https://github.com/16bitOni/dipcompress
cd dipcompress
pip install -e ".[dev]"
To explicitly build (or rebuild) the C extension:
python dipcompress/_c_ext/build.py
Run the tests:
pytest
Platform support
| Platform | Arch | Pre-built wheel |
|---|---|---|
| Linux | x86_64 | yes |
| Windows | AMD64 | yes |
| macOS | x86_64 | yes |
| macOS | arm64 (Apple Silicon) | yes |
| Any | source install | yes (C ext compiles if toolchain available) |
Python 3.11 and 3.12 are tested in CI.
Project structure
dipcompress/
├── __init__.py # public API surface
├── cli.py # argparse CLI
├── encoder.py # compress() — full pipeline
├── decoder.py # decompress() — full pipeline
├── filters.py # PNG-style row filters
├── lz77.py # pure-Python LZ77
├── lz77_fast.py # C ext wrapper with Python fallback
├── huffman.py # Huffman encode/decode
├── format.py # .dip binary format (header, tables)
├── image_io.py # PIL image load/save helpers
└── _c_ext/ # C source for LZ77
License
MIT — see LICENSE.
Credits
Built by Subhadip Mondal.
The compression algorithms, binary format, filter logic, and architecture were all designed and written by hand.
The GitHub Actions CI/CD pipeline, setup.py C extension build config, and PyPI publishing workflow were put together at the last minute with help from Claude — because apparently even people who implement Huffman coding from scratch draw the line at YAML indentation errors at 2 AM. No shame.
Metadata
Release files for dipcompress 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dipcompress-0.1.1.tar.gz | 18.6 kB | Details |
Built distributions (wheels)
Total release size: 238.8 kB
Release files / dipcompress-0.1.1.tar.gz
| Download URL | dipcompress-0.1.1.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
293341cbf52a16e77724bcc0c17ffafc25ff6b47ab1c7de05484d3fb3df6d9a0
|
|
BLAKE2b-256 checksum How to use checksums |
ae41db56958609756ac2f2f326104f9fd97bb295fb5a4969c870dbe62954f946
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp312-cp312-win_amd64.whl
| Download URL | dipcompress-0.1.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 21.5 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
74d942ef7fbbb1f5c8a4e65d29b605de8fa25094b7de2a0627ce395fc4f72f01
|
|
BLAKE2b-256 checksum How to use checksums |
f7e528bb0b767bf1c72aef793c4dbff28355fc61d9c70ab2c5799365cb683179
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | dipcompress-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 25.7 kB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
79b5fd323ee38a9e7bddc2d9ca9fc59338ad44d8d67935e77500efe3a84e5782
|
|
BLAKE2b-256 checksum How to use checksums |
3f1ca693ee8d6369346431a5f1dbfde6076855870e248d23d4ae73fa373308b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | dipcompress-0.1.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 25.7 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
414cbf6389ae2dd45272a0054c93c5c225aa2e8dcec11e6903afff61ccbd8be5
|
|
BLAKE2b-256 checksum How to use checksums |
10632a15afaaa39c7fddf8158b81a9ffdf8882c2c4df7839608f165da0056dbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | dipcompress-0.1.1-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 18.9 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
aafcb8718cd049e711b60fcddecceb35b63fe70a546d02d2cc50fb51b612e979
|
|
BLAKE2b-256 checksum How to use checksums |
88ef40e51ca956f169ae061b747b223b8f723055113d002a33eb809a03c787fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp312-cp312-macosx_10_13_x86_64.whl
| Download URL | dipcompress-0.1.1-cp312-cp312-macosx_10_13_x86_64.whl |
|---|---|
| Size | 18.5 kB |
| Tags | CPython 3.12 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
40e5beb5cfdb9dc6719791f49cfad8306d1784b94751281fe209ef2e0f627d37
|
|
BLAKE2b-256 checksum How to use checksums |
76c218be8ac7a52de7e7f628712979aa5479044f7a50153e64f7606bc3a3e50c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp311-cp311-win_amd64.whl
| Download URL | dipcompress-0.1.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 21.5 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e5f12b2b6dbdb72666f0166123ed1e81b620344901cdfc8dc24b5c9419abdddd
|
|
BLAKE2b-256 checksum How to use checksums |
93f082f194a663d59561309bdebec08927e9598ec43d69a3d59afa153f2374a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | dipcompress-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 25.6 kB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
40bede3ec72e8c97aba0aa1dbedb1f3109a9925d124da07d1c25feec30f53fa7
|
|
BLAKE2b-256 checksum How to use checksums |
dd35af0b9ba21a5b06d196dc291797f8086819e0f46d686e6d410befead00b20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | dipcompress-0.1.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 25.6 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
638bcb7e287f7ebdb1f9b01fed8b4fdb50749f9983404b9c92effd6f24fadddf
|
|
BLAKE2b-256 checksum How to use checksums |
119b2fa584bab508b9b7469cd6c4b34c9fb76db42cbea5fc4908ec9535ea43c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | dipcompress-0.1.1-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 18.9 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dfaa8962cd8fbc1e318159ad46096e87008979af67a4c706b6a67bbd4e9c8f88
|
|
BLAKE2b-256 checksum How to use checksums |
839175d49c05dc9d8505c1700d197e85e749e5d2e71493213d37e8040c0c011c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / dipcompress-0.1.1-cp311-cp311-macosx_10_9_x86_64.whl
| Download URL | dipcompress-0.1.1-cp311-cp311-macosx_10_9_x86_64.whl |
|---|---|
| Size | 18.5 kB |
| Tags | CPython 3.11 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
d4c94deafc13fb3048995da72cc792cea7a388d438bcb838d897e721c533b324
|
|
BLAKE2b-256 checksum How to use checksums |
cf28431d7152f6b22b9bc8be688c1be741fcd4f617b6917bb579800fab6b2300
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency log