Add Floyd-Steinberg error diffusion dithering#6
Merged
Conversation
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
There was a problem hiding this comment.
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.
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Floyd-Steinberg error diffusion as a new dithering pattern, bringing the total to 16 patterns.
Changes
Testing
All existing tests pass. New test confirms the algorithm produces gradients with both colors distributed across the region.
Fixes #5