Nuke
Nuke copied to clipboard
End-Of-Image markers for more robust Progressive JPEG decoding
This PR does a few things:
- 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.
- 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.jpegimage were passing). Added another imagetricky_progressive.jpegwhich trips up the decoder and requires those markers. Cross-checked withlibjpegend it also needs EOI markers. - Switched byte while-loops with
Data.firstIndexwhich seems to give a decent speed up. Also triedData.range(of:)but that was slower.