Skip to content

Conversation

@DavyLandman
Copy link
Contributor

@DavyLandman DavyLandman commented Dec 21, 2025

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:
Screen Shot 2025-12-21 at 13 59 24

Used to be turned into:
test-before

But now is turned into:
test-with-dithering

Or less syntatic, this picture:
pexels-jacub-gomez-447561-1143379

used to become:
test

is now:
test

@martinberlin
Copy link
Collaborator

Looks good to me. Will try it soon.
Also assigned CoPilot to review your change so you can check what it says. Just a test if doesn't come out anything good then we just close it.

@DavyLandman
Copy link
Contributor Author

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.

Copy link

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 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 martinberlin self-requested a review December 22, 2025 10:47
@martinberlin martinberlin self-assigned this Dec 22, 2025
Copy link
Collaborator

@martinberlin martinberlin left a 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

@DavyLandman
Copy link
Contributor Author

I've process the remarks, and added screenshots

@martinberlin martinberlin self-requested a review December 22, 2025 16:10
@martinberlin martinberlin added the done Implemented and tested label Dec 22, 2025
Copy link
Collaborator

@martinberlin martinberlin left a comment

Choose a reason for hiding this comment

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

All good

@martinberlin martinberlin merged commit a293ef3 into vroland:main Dec 25, 2025
13 checks passed
@vroland
Copy link
Owner

vroland commented Dec 30, 2025

Thanks for implementing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

done Implemented and tested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants