Unfortunately both the article and the code suffer from a crucial misunderstanding of JPEG -- the 8x8 blocks do actually undergo a 2-dimensional DCT. Zig-zag scanning down to 1D comes later, after quantization, and is applied to the quantized DCT coefficients in order to maximize runs of zero for the benefit of RLE.
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.
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.