-
Notifications
You must be signed in to change notification settings - Fork 235
Rewrote imgconvert use quantization so we have dithering support #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Looks good to me. Will try it soon. |
|
I don't interact with GenAI, if it helps you manage the OSS project, you do you. Human questions I'm always happy to answer. I'll try to include a image example of the effect of this PR. |
There was a problem hiding this 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 modernizes the image conversion script to use PIL's quantization algorithm instead of simple bit-chopping, enabling dithering support for improved grayscale conversion quality.
- Replaces manual grayscale bit-truncation with PIL's quantize method using Floyd-Steinberg dithering
- Adds command-line options to control dithering (-nd flag) and gray levels (-l parameter)
- Updates byte packing logic to work with quantized palette indices
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| scripts/imgconvert.py | Implements quantization-based grayscale conversion with palette generation, adds new CLI arguments, and updates pixel packing logic to use palette indices instead of bit-shifted values |
| scripts/README.md | Documents the new -nd (disable dithering) and -l (gray levels) command-line arguments |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
martinberlin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the comments and correct what you think is necessary. After that the PR will be approved. Thanks
|
I've process the remarks, and added screenshots |
martinberlin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good
|
Thanks for implementing this! |
The old code would convert to grayscale, and then chop of the lower 4 bits of the color. This new code allows you to dither, and leave the color mapping to PILLOW/PIL's quantize, which uses a more fancy algorithm where possible.
Some example images (zoom in to see the dithering)
For example, this input:

Used to be turned into:

But now is turned into:

Or less syntatic, this picture:

used to become:

is now:
