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

End-Of-Image markers for more robust Progressive JPEG decoding #835

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

theop-luma
Copy link

@theop-luma theop-luma commented Mar 7, 2025

This PR does a few things:

  1. Makes sure that JPEGs with thumbnails still decode correctly and the markers for the thumbnails do not affect the decoding. Previously if a progressive JPEG had a baseline thumbnail the image would be misidentified as baseline and the scan numbers would be off causing failures.
  2. Adds EOI (end of image, 0xFFD9) markers before attempting to decode a partial progressive JPEG binary. This seems to be the more 'canonical' way to decode, even though it looks like Apple's decoder sometimes manages to decode correctly even without that marker (that's why the Unit tests with progressive.jpeg image were passing). Added another image tricky_progressive.jpeg which trips up the decoder and requires those markers. Cross-checked with libjpeg end it also needs EOI markers.
  3. Switched byte while-loops with Data.firstIndex which seems to give a decent speed up. Also tried Data.range(of:) but that was slower.

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.

1 participant