QuickLook thumbnails don’t always render JPEGs right

QuickLook is one of those features which we take for granted, and have sometimes come to rely on heavily. When preparing images for use in the articles here, my main tools are Finder Column views, their QuickLook thumbnails, and GraphicConverter. Some days I work through dozens of thumbnails, using them to identify and prepare images for inclusion.

In the midst of all the turbulence in recent versions of macOS, QuickLook has been relatively calm. There was the embarrassing issue of its cache, which could in the past be browsed by almost anyone passing by, but Apple took prompt action and it’s now locked away from prying eyes. A while back, it couldn’t cope with generating thumbnails for files which were mistyped – such as a JPEG with the the extension .png – but that too got fixed quickly, and QuickLook got quietly on with its job.

A few days ago I downloaded some JPEG images of engravings of Gustave Doré’s illustrations to Milton’s Paradise Lost. Instead of seeing immaculately scaled thumbnails, though, they were badly disfigured by moiré. You can see this best by comparing the thumbnail shown in the Finder window, on the left, against a rescaled QuickLook preview of the same file, on the right.

qlthumbnail

If you want to test this yourself, this image came from here, and there are several others which behave similarly. They’re fairly standard JPEGs as far as I can see, in Greyscale colour mode with 256 greys (8 bit), 1:1 compression at 300 dpi. The only tricky thing about them is that, despite being greyscale, they’ve ended up with an RGB colour profile, although I can’t see how that results in such gross moiré.

A little further exploration became even stranger. This moiré effect is only seen in the thumbnail when it’s viewed in Finder Column views. Use another type of Finder view and the thumbnail is rendered normally. It persists when the Rotate left Finder action is applied. But, most oddly of all, it’s possible to make the thumbnail snap out of its moiré by resizing the area in which the thumbnail is displayed within the window. But, instead of that fairer thumbnail being cached, it’s easy to make it return to its moiréed form.

Then I got thoroughly confused when I tried changing the file’s extension. QuickLook continued to display the image thumbnail, with or without moiré as it pleased, when I changed this file’s extension to .png or .pdf, even if I also changed the file’s name. But if I changed the extension to .txt, the thumbnail then previewed the file as a text document.

This all happens in macOS 10.15.5, both before and after the latest Supplemental Update. It’s independent of the current Appearance mode, and completely reproducible on this iMac Pro. I’d be fascinated to know if you and others can reproduce it on other systems too. QuickLook’s small area of calm doesn’t necessarily run as deep as we might think.

Postscript

Thanks to some brilliant detective work on Twitter, and mainly the insights and testing of @Sam_Ohanaware, it looks like this is what is happening:

  • QuickLook builds a first-pass thumbnail, which it draws with CGContextSetInterpolationQuality set to NONE for speed. That generates the moiréed version of the image.
  • While that’s being displayed, a slower and fairer version of the thumbnail is generated, which is then drawn at higher quality.
  • In some circumstances, such as those described above, the second fair image doesn’t get displayed, leaving just the moiréed version on view.

And Sam reports this as far back as 10.14.6 too, so this isn’t a Catalina bug after all, it just took some unusual images to make it so obvious.