Home » Blog
date 04.Mar.2018

■ File detective: discover JPG images with SOF2 progressive marker


xplorer² recent major upgrade to v4.0 brought among other things a programmable column that can do some fancy file property algebra. You can effectively define your own composite file properties. Today we will see a possible application of this feature to identify pictures with interlaced progressive format.

According to wikipedia, the interlaced progressive JPEG format compresses data in multiple passes of progressively higher detail. This is ideal for large images that will be displayed while downloading over a slow connection, allowing a reasonable preview after receiving only a portion of the data. That makes them ideal for use in websites. Programs like Irfanview can save as progressive JPG and even batch convert "plain" JPG into the progressive format. But how do we know which pictures need to be converted?

The JPEG specification is quite complex; both normal and progressive formats superficially look the same — all pictures have .JPG extension. As far as I can tell there is no system property that would tell us if a picture is progressive or not. The only way is to examine the picture header data, i.e. read the file bytes.

Disclaimer: I am not a picture format or web development expert. But it seems that the progressive format's SOF2 marker — the 2 bytes (0xFF, 0xC2) — are stored at file offset 158 in all JPG sample pictures I found. Based on this conjecture we can use xplorer² FBYTES function to fish out this information.

progressive format header

Right click on the column header and pick programmable from the menu, then type the following expression:

${Extension}=jpg & FBYTES(158,2)="FF.C2"

This is a boolean conjunction with two terms. Files with JPG extension and (&) with the SOF2 marker at file offset 158 satisfy the expression — its value is 1. Note we check the extension first because we don't want to slow down xplorer² checking unrelated file types. Then we can see at a glance which pictures are progressive and which aren't:

progressive status in programmable column

If you watch the demo video about the programmable column, you can also define a search rule on this "progressive" property we just defined, which means you can search to find all progressive JPGs in your collection (or those that are plain).

ps. As it turns out JPG pictures with EXIF information will probably store the SOF2 marker at a different position, and you'd need a program to decipher the exact location. However you may be able to get away with a few extra FBYTE terms separated with or (|) like:
${Extension}=jpg & (FBYTES(158,2)="FF.C2" | FBYTES(xxx,2)="FF.C2" | ...)

Post a comment on this topic »

Share |

©2002-2018 ZABKAT LTD, all rights reserved | Privacy policy | Sitemap