Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Besides standard/progressive, the 3rd kind of JPEG compression: load by channel?

this question might be an "Open Question" and many of you might be eager to close it, but please don't. Let me explain.

As we all know, JPEG has two kinds of compression (at least in Photoshop save dialog)

  • optimized, where image was loaded kinda like line-by-line
  • progressive, where image was loaded first mosaic-like, the progressively better till the original resolution

I have read a lot of PNG/JPEG optimization articles before, but now I encountered this awesome third kind compression, from a wild random Google Image search. The JPEG in question is this

http://storage.googleapis.com/marc-pres/boston-event-1012/images/google-data-center.jpg

Try load the link in Chrome/Firefox (in IE/Safari only until the image was fully loaded then displayed)

you can observe:

  1. image were loaded first in black & white
  2. then looks like the Red channel loaded
  3. next the Green channel loaded
  4. last the Blue channel loaded

I tried loading it again with a emulated very slow connection, and observed that the JPEG is not only loads by channel order, but in progressive way as well. So first loaded image is blank-and-white mosaic then green-ish mosaic then gradually full color mosaic and finally full resolution and full color image.

This is amazing technology, suppose you are building an e-magazine, where each page has a lot of pictures, you want the user to fast flip browsing through pages, and this kind of image is exactly what works best. For fast preview, load blank-n-white thumbnail, if the user stays, fully load the original image.

So my question is: How could I generate such image using Python Pillow or ImageMagick, or any kind of open source software?

If you think this question is inappropriate please comment, don't just close it.

Update 1:

It turns out Google used this technology in all of its JPEG pictures 1, 2 e.g. this

Update 2: I found another clue

like image 327
est Avatar asked Mar 28 '13 05:03

est


1 Answers

The image data in a JPEG file can be sliced up in many different ways, and the slices (or "scans" as they're usually called) can be stored in the file in many different orders.

In most JPEG files, the first scan in the file contains all of the image's color components, interleaved together if it is a color image. In a non-progressive JPEG, the file will contain just that one scan. In a progressive JPEG, other scans will follow, each of which may contain one component or multiple components.

But there's nothing that requires it to be done that way. If the first scan in the file does not contain all the color components, we might call such a file "non-interleaved".

Your examples files are non-interleaved, and they are also progressive. Progressive non-interleaved JPEGs seem to be more widely supported than non-progressive non-interleaved JPEGs.

The standard IJG libjpeg software is capable of creating non-interleaved files. Though it's not exactly easy, you can use its cjpeg utility, with the -scans option documented in the wizard.txt file.

like image 66
jason_s Avatar answered Dec 24 '22 08:12

jason_s