Nuke icon indicating copy to clipboard operation
Nuke copied to clipboard

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

Open theop-luma opened this issue 9 months ago • 0 comments

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.

theop-luma avatar Mar 07 '25 07:03 theop-luma