My application requires VERY small size jpeg files (less than 2.5KB) to be stored as DATA (CANNOT BE A LINK) in a QR code. Both quality and size are a concern. Any byte I can save might mean that I can make the QR code easier to read. Luckily, they all have a standard resolution (160×240) and color depth (24 bits).
I had an idea of taking part of the header out of the JPEG files themselves, and have the application add the header back into the data array later, which would save a good 600 bytes (wow). The way I’m doing compression so far is to keep a “gold standard file” and compress that file with Q = 80-10% until it fits into 2.5KB.
Because a different compression ratio means a different header, my idea would be to pass the final compressed image through ANOTHER pass of a known, standard compression. But then if the “standard compression” is greater than the original compression the image settled on, the size may actually be GREATER than the final compressed image.
Is there a standard method of doing something like this? I feel like I might be onto something, but I can’t seem to get it to work.
What I eventually ended up doing was having multiple levels of compression, and I stored the header (D0-DB) and the Huffman Table (C4). I am able to save roughly 550 bytes this way with a simple replace algorithm. It’s not 100% ideal, but it’s not half bad either. I lose around 50 bytes, but the trade off with increased quality and app program memory size makes it worth it.
To make it easier to scan, I decreased the maximum size to 1.9KB prior to the replace algorithm.