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

Optimize color counting #598

Merged
merged 4 commits into from
Mar 28, 2024
Merged

Optimize color counting #598

merged 4 commits into from
Mar 28, 2024

Conversation

kornelski
Copy link
Contributor

I've seen a panic in most_popular_edge_color, so I've made it more resilient.

@AlexTMjugador
Copy link
Collaborator

Thank you, these changes look sensible. Do you have any clue on why len can be outside of the expected range in the affected code?

@kornelski
Copy link
Contributor Author

I only have a core dump without the image, so I don't know exactly.

A common tricky case that may be related is pixels having higher values than palette length.

It also could have been 1x1 interlaced image.

@andrews05
Copy link
Collaborator

Thanks for this @kornelski. I'll take a closer look later and try to figure out what would actually cause this, but I'm surprised it can happen since:

  1. The image should have already been cleaned from any palette issues at this point.
  2. Interlaced images are explicitly excluded from the co_occurrence_matrix sort methods.

Copy link
Collaborator

@AlexTMjugador AlexTMjugador left a comment

Choose a reason for hiding this comment

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

Both of your comments sound good! I think this PR could be merged as-is, as it's not exclusive with actually figuring out what's causing the bad len, but I'll leave the final choice to @andrews05, given Andrews is more familiar with this code.

@andrews05
Copy link
Collaborator

I managed to reproduce a crash at that point. @kornelski was right - it can happen when palette entries are missing.
The reduced_palette is supposed to fix any such issues, but it won't if the palette was one entry too short. I'll make up a separate PR with a test case to fix this.

@andrews05 andrews05 mentioned this pull request Mar 28, 2024
@andrews05 andrews05 merged commit eae5336 into shssoichiro:master Mar 28, 2024
10 checks passed
@kornelski kornelski deleted the count branch April 8, 2024 13:33
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