Skip to content
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

pixel: fix Monochrome setPixel #716

Merged
merged 2 commits into from
Oct 28, 2024
Merged

pixel: fix Monochrome setPixel #716

merged 2 commits into from
Oct 28, 2024

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Oct 28, 2024

Set/setPixel and Get weren't using the same indices. I've taken the ones used in Get and applied them to setPixel too.
This fixes testImageNoise for the monochrome image.

I don't know which of the two behaviors was correct, but the one in Get certainly is simpler and more efficient.
@deadprogram do you have a specification of the format somewhere?

Set/setPixel and Get weren't using the same indices. I've taken the ones
used in Get and applied them to setPixel too.
This fixes testImageNoise for the monochrome image.
@aykevl aykevl requested a review from deadprogram October 28, 2024 08:54
bits := index - (offset * 8)
bits := index % 8
Copy link
Member Author

Choose a reason for hiding this comment

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

This code looks different, but it doesn't change behavior. It's just a simplification.

Comment on lines -141 to +142
x := index % int(img.width)
offset := index / 8
bits := index % 8
Copy link
Member Author

Choose a reason for hiding this comment

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

The old behavior was most certainly incorrect.

Take for example an image of size 5x2. The first pixel at (0, 0) is index 0 and x 0 (make sense).
But at position (0, 1), which is index 5, you also get index 0 and x 0. So the two pixels are stored at the same location.

Copy link
Member

Choose a reason for hiding this comment

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

exactly, took me a while to discover that the old behavior only works on images with width multiple of 8 🤦

@deadprogram
Copy link
Member

This is great, thank you very much for fixing this @aykevl

Tested on badger2040 display, works as expected. Now merging.

@deadprogram deadprogram merged commit 76a4276 into dev Oct 28, 2024
1 check passed
@deadprogram deadprogram deleted the monochrome-fix-setPixel branch October 28, 2024 09:07
@aykevl aykevl mentioned this pull request Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants