JPEG Information
Digital Cameras save images in JFIF (usually incorrectly called JPEG or if you're an MS-DOS user JPG) format. Anyway, “JPEG” files consist of “markers” which separate out each part of the file. For example, every JPEG starts with a “start of image” marker and stop with an “end of image” marker. Most markers are followed by 2 bytes which tell the number of bytes that fit in the frame that was marked with this marker. After that the data follows. So what markers are in a typeical JPEG? These markers should exist in all JPEG files:
- 0xffd8 - Start Of Image
- 0xfffe - Comment (Optional)
- 0xffdb - Quantization Table
- 0xffc0 - Start Of Frame (Baseline)
- 0xffc4 - Huffman Table (Sometimes ommited from mjpeg files)
- 0xffda - Start Of Scan (This is the actual compressed image)
- 0xffd9 - End Of Image
Why These Images Are Corrupt
So what's on a JPEG created by this camera:
- 0xffd8 - Start Of Image
- 0xffe1 - Application Data
- 0xffdb - Quantization Table
- 0xffc4 - Huffman Table
- 0xffc0 - Start Of Frame (Baseline)
- 0xffda - Start Of Scan
- 0xffd9 - End Of Image
This is all okay except for in the example file I used there are 8 extra padding bytes before the 0xffd9 and a bunch of extra garbage after the file. Actually, it seems to be padded by 11 bytes, but the IJG library only seems to complain about the 8 byte padding. I haven't seen another JPEG library that pads bytes tho. As far as the data at the end, I wonder what it looks like under a disassembler. I'm just glad I'm not using Windows or Internet Explorer to look at these images.
Anyway, after removing the 8 bytes of padding and the extra crap at the end of each file, the images open without any complaint. An interesting note: At the top of the file in the application data section, there appears to be some camera information here:
SQ Tech. Co., Ltd. SQ908 MEGA-Cam. CSTN FW Build 2.6.2007:01:06
Maybe firmware built after this date doesn't have this issue in it.