JPEG Lossless Reductor: How it works?
TL;DR: we optimize the lossless step of JPEG compression, so that the original image is preserved pixel to pixel
JPEG compression consists of three sequential steps:
- spatial-to-frequency transformation (DCT). This step transforms the input image into a representation where large content details are separated from fine details and noise. This transform is lossy due to finite precision of mathematical operations;
- quantization. This step intentionally removes data from the transformed representation by reducing value precision starting from the noise, through the fine details and, depending on the specified quantization parameters, up into the large image details;
- entropy coding. This step uses an entropy coding algorithm (Huffman coding) to convert the output of the previous step into a compact form. Entropy coding is a lossless and fully reversible process.
JPEG Lossless Reductor works by first undoing the entropy coding step and then re-applying it in a more efficient manner (when possible). This way, the actual file size can be reduced without changing the original image. In case when the input file size cannot be further reduced (e.g. if it was already processed by the Reductor) the file is left intact.
So why it's not done right in the first place? Good question! Entropy coding works by assigning shorter codes to more frequent chunks of data at the expense of the less frequent ones. Ideally, to know the frequency distribution, the encoder needs to make an extra pass over the input data. Hardware JPEG encoders of most mobile devices instead rely on hard-coded frequency tables to avoid added complexity of the extra pass. The result is not bad but is not ideal either. The Reductor is at your service to bring the compression to perfection!