Skip to content

Add Floyd-Steinberg error diffusion dithering#6

Merged
willibrandon merged 2 commits into
mainfrom
feature/floyd-steinberg-dithering
Oct 18, 2025
Merged

Add Floyd-Steinberg error diffusion dithering#6
willibrandon merged 2 commits into
mainfrom
feature/floyd-steinberg-dithering

Conversation

@willibrandon
Copy link
Copy Markdown
Owner

Adds Floyd-Steinberg error diffusion as a new dithering pattern, bringing the total to 16 patterns.

Changes

  • Implemented Floyd-Steinberg algorithm with standard error propagation weights (7/16, 5/16, 3/16, 1/16)
  • Creates horizontal gradients using color selection by Euclidean distance
  • Added test that verifies gradient output by inspecting pixels
  • Updated example client to show Bayer 4x4 vs Floyd-Steinberg side-by-side

Testing

All existing tests pass. New test confirms the algorithm produces gradients with both colors distributed across the region.

Fixes #5

Implements Floyd-Steinberg error diffusion algorithm for the draw_with_dither tool. The algorithm creates gradients by distributing quantization errors to neighboring pixels using the standard 7/16, 5/16, 3/16, 1/16 weight pattern.

- Add floyd_steinberg pattern to draw_with_dither (16 patterns total)
- Implement gradient generation and error propagation in Lua
- Use Euclidean distance for color selection instead of luminance threshold
- Add test verifying gradient output by reading back pixels
- Add side-by-side example comparing Bayer 4x4 vs Floyd-Steinberg

Fixes #5
@willibrandon willibrandon self-assigned this Oct 18, 2025
@willibrandon willibrandon added the enhancement New feature or request label Oct 18, 2025
@willibrandon willibrandon requested a review from Copilot October 18, 2025 05:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements Floyd-Steinberg error diffusion dithering to enhance the dithering capabilities of the pixel art tool. Floyd-Steinberg is a high-quality error diffusion algorithm that produces smooth gradients by propagating quantization errors to neighboring pixels.

  • Adds Floyd-Steinberg error diffusion as a new dithering pattern
  • Implements horizontal gradient generation using Euclidean distance for color selection
  • Creates comprehensive test coverage for the new algorithm with pixel verification

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/tools/dithering_test.go Adds Floyd-Steinberg to pattern tests and creates comprehensive gradient verification test
pkg/tools/dithering.go Updates pattern validation and documentation to include Floyd-Steinberg
pkg/aseprite/lua_drawing.go Implements Floyd-Steinberg error diffusion algorithm in Lua generation
examples/client/main.go Updates demo to show side-by-side comparison of Bayer vs Floyd-Steinberg

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pkg/aseprite/lua_drawing.go Outdated
Comment thread pkg/aseprite/lua_drawing.go Outdated
- Update function documentation to accurately describe gradient generation
  and clarify that density parameter is unused
- Add edge case handling for width=1 to prevent division by zero
- Verified all tests pass including new width=1 edge case
@willibrandon willibrandon merged commit b62bb37 into main Oct 18, 2025
2 checks passed
@willibrandon willibrandon deleted the feature/floyd-steinberg-dithering branch October 18, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Floyd-Steinberg error diffusion dithering support

2 participants