dithering

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorDifusionDithering

func ErrorDifusionDithering(img image.Image, algorithm string, level int) image.Image

ErrorDiffusionDithering applies an error diffusion dithering effect to an image. This technique distributes the quantization error of a pixel to neighboring pixels according to different distribution patterns defined by various algorithms.

Supported algorithms:

  • floyd-steinberg: Classic algorithm with good balance of quality and performance
  • false-floyd-steinberg: Simplified version with fewer error terms
  • jarvis-judice-ninke: Higher quality with wider error distribution (12 neighboring pixels)
  • stucki: Modified Jarvis algorithm with improved weights
  • atkinson: Partial error distribution that preserves detail (only distributes 3/4 of error)
  • sierra: Good quality with moderate computational cost
  • two-row-seirra: Two-row variant of Sierra algorithm with reduced complexity
  • sierra-lite: Simplified one-row Sierra variant for faster processing
  • none: No error diffusion applied (simple quantization)

Parameters:

  • img: The input image to be processed
  • algorithm: The name of the dithering algorithm to use (case-sensitive)
  • level: The number of quantization levels per channel (1-10), where: Lower values (1-3) produce more posterized results with high contrast. Higher values (8-10) produce more subtle dithering with greater color depth.

Returns:

  • image.Image: A new RGBA image with the dithering effect applied

func OrderedDithering

func OrderedDithering(img image.Image, level, size int) image.Image

OrderedDithering applies an ordered dithering effect to an image using a Bayer matrix pattern. Ordered dithering creates a retro visual effect by systematically applying threshold patterns to reduce color depth while maintaining visual structure.

Parameters:

  • img: The input image to be processed
  • level: The number of quantization levels (1 - 20); higher values result in more color bands and less pronounced dithering effect. Values outside this range will be clamped.
  • size: The size of the dithering matrix (must be a power of 2, e.g., 2, 4, 8); larger matrices create more complex dithering patterns. Non-power-of-2 values will be adjusted to the next even number.

Returns:

  • A new image.Image with the ordered dithering effect applied, in RGBA64 format

Note: The alpha channel is also dithered by default. The function automatically handles bounds checking and matrix size adjustments.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL