Skip to main content

Dithering algorithms for e-paper/e-ink displays

Project description

epaper-dithering

Dithering algorithms optimized for e-ink/e-paper displays with limited color palettes.

Installation

pip install epaper-dithering

Features

  • Perceptually Correct: Uses linear RGB color space with gamma correction for accurate error diffusion
  • 8 Dithering Algorithms: From simple ordered dithering to high-quality Jarvis-Judice-Ninke
  • 6 Color Schemes: Support for mono, 3-color, 4-color, and 6-color e-paper displays
  • Serpentine Scanning: Reduces directional artifacts in error diffusion (enabled by default)
  • RGBA Support: Automatic compositing on white background for transparent images

Quick Start

from PIL import Image
from epaper_dithering import dither_image, ColorScheme, DitherMode

# Load your image
image = Image.open("photo.jpg")

# Apply dithering for a black/white/red display
dithered = dither_image(image, ColorScheme.BWR, DitherMode.FLOYD_STEINBERG)

# Save result
dithered.save("output.png")

Supported Color Schemes

  • MONO - Black and white (1-bit)
  • BWR - Black, white, red (3-color)
  • BWY - Black, white, yellow (3-color)
  • BWRY - Black, white, red, yellow (4-color)
  • BWGBRY - Black, white, green, blue, red, yellow (6-color Spectra)
  • GRAYSCALE_4 - 4-level grayscale

Dithering Algorithms

Algorithm Quality Speed Best For
NONE Lowest Fastest Testing, simple graphics
ORDERED Low Very Fast Patterns, textures
SIERRA_LITE Medium Fast Quick results
BURKES Good Medium General purpose (default)
FLOYD_STEINBERG Good Medium Popular standard
SIERRA High Medium Balanced quality
ATKINSON Good Medium High contrast, artistic
STUCKI Very High Slow Maximum quality
JARVIS_JUDICE_NINKE Highest Slowest Smooth gradients

Usage Examples

Basic Usage

from PIL import Image
from epaper_dithering import dither_image, ColorScheme, DitherMode

# Load image
img = Image.open("photo.jpg")

# Apply Floyd-Steinberg dithering for BWR display
result = dither_image(img, ColorScheme.BWR, DitherMode.FLOYD_STEINBERG)
result.save("dithered.png")

All Color Schemes

from epaper_dithering import ColorScheme

# Black and white only
dithered = dither_image(img, ColorScheme.MONO)

# Black, white, and red (common for e-paper tags)
dithered = dither_image(img, ColorScheme.BWR)

# Grayscale (4 levels)
dithered = dither_image(img, ColorScheme.GRAYSCALE_4)

# 6-color display (Spectra)
dithered = dither_image(img, ColorScheme.BWGBRY)

Advanced Options

Serpentine Scanning

By default, error diffusion algorithms use serpentine scanning (alternating scan direction per row) to reduce directional artifacts and "worm" patterns. You can disable this for raster scanning:

# Default: serpentine scanning (recommended for best quality)
result = dither_image(img, ColorScheme.BWR, DitherMode.FLOYD_STEINBERG, serpentine=True)

# Disable serpentine for raster scanning (left-to-right only)
result = dither_image(img, ColorScheme.BWR, DitherMode.FLOYD_STEINBERG, serpentine=False)

Note: The serpentine parameter only affects error diffusion algorithms (Floyd-Steinberg, Burkes, Atkinson, Sierra, Sierra Lite, Stucki, Jarvis-Judice-Ninke). It has no effect on NONE and ORDERED modes.

RGBA Images

Images with transparency (RGBA mode) are automatically composited on a white background, matching the typical appearance of e-paper displays:

# RGBA images are handled automatically
rgba_img = Image.open("transparent.png")  # Has alpha channel
result = dither_image(rgba_img, ColorScheme.BWR)
# Transparent areas become white

Development

# Install with dev dependencies
uv sync --all-extras

# Run tests
uv run pytest tests/ -v

# Run tests with coverage
uv run pytest tests/ --cov=src/epaper_dithering

# Lint
uv run ruff check src/ tests/

# Type check
uv run mypy src/epaper_dithering

Credits

Originally developed as part of py-opendisplay. Extracted to enable reuse across multiple e-paper display projects.

Project details


Download files

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

Source Distribution

epaper_dithering-0.3.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

epaper_dithering-0.3.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file epaper_dithering-0.3.0.tar.gz.

File metadata

  • Download URL: epaper_dithering-0.3.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for epaper_dithering-0.3.0.tar.gz
Algorithm Hash digest
SHA256 692e3e8ed87b90004258f4325220721885c0dc280803b30e5c34f478ee4a99e0
MD5 261dbb474f4066ae8052d633d3a2ffc7
BLAKE2b-256 63f577192cb5cbe68eaa88353b8a677161e18de0d74fe050d2e3330b5ee36ab7

See more details on using hashes here.

Provenance

The following attestation bundles were made for epaper_dithering-0.3.0.tar.gz:

Publisher: release.yml on OpenDisplay-org/epaper-dithering

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epaper_dithering-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for epaper_dithering-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61becfc20bbdea74ae75151a0e12d7b09a0e75e46e167683572862fcd91a9b48
MD5 826ed6098b48a33ff67775b04766a920
BLAKE2b-256 f909001fac8e981b3a5a337c524cd0e34b2e3316a5623d56ec4f78443fc6d170

See more details on using hashes here.

Provenance

The following attestation bundles were made for epaper_dithering-0.3.0-py3-none-any.whl:

Publisher: release.yml on OpenDisplay-org/epaper-dithering

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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