39 points · by ot · 11y ago · 7 comments
The code and the article assume that the scan is applied earlier, to the spatial data, in preparation for a 1D DCT and as a consequence mistakenly performs all of its operations in scan order. In reality, a 1D DCT of zigzag-scanned samples differs dramatically from a zigzag scan of 2D frequency coefficients.
The technique still works to an extent as it's still processing edges (only diagonally), creating a similar effect in some cases to the desired one, but likely less effective than a row-column or other 2D approach which models the actual transform and the intended behavior outlined in the blog post.
Surprisingly this code was accepted into mozjpeg nearly a year ago and remains as in the blog post.
Why not? The examples seem to work and show improvements. Anyone is welcome to submit an improved version if they like.
I have actually implemented and tested a 2D overshoot, and it gave worse quality/filesize ratio.
Perhaps by accident (or less obvious correlation), but this order seems to give most compressible pattern.
It would be interesting to see how far this technique would take if implemented with correct assumptions.
Clipping is required by JFIF, so you can't implement spilling in the decoder by default, even if you assume the source was 0-255 RGB. So implementing this in the encoder like the article does is best. but I have mixed feelings about it since it's most helpful for images that shouldn't be saved as JPEG at all.
Of course, this ringing is totally natural, and if the display operated "properly" from a signal processing perspective (like an audio DAC), you'd see it everywhere: a single-pixel line would be below the band limit!
To really solve the problem, you have to stop treating pixels as samples, since they're not displayed that way. Instead, you should upsample the image to a higher resolution using a kernel which matches how a display renders pixels, perform your signal processing on this higher-resolution image, then downsample using the same kernel.