What makes two main JPEG file formats, JFIF and Exif, incompatible?
JPEG is not a file format. The two major formats are JFIF and Exif. Wikipedia page on JFIF says that:
JFIF is mutually incompatible with the newer Exchangeable image file format (Exif).
The two formats are quite similar though. What causes the incompatibility?
Solution 1:
If you want to be 100% spec-conformant, JFIF and Exif are incompatible. In practice they can be mixed in a single file. That's because the incompatibility is caused by a single detail in both specs that is not important if you're mixing them.
Files in both formats have the same structure:
- Start of image marker:
FF D8
- Any number of segments:
- 2-byte segment type identifier
- 2-byte segment length (excluding identifier bytes)
- segment data
- Start of scan marker:
FF DA
- Image data
- End of image marker:
FF D9
Image data is identical in both formats. Segment types, their identifiers and content structures are in a large part identical. Other segments are unique for one of the formats and don't use identifiers from the other, so no incompatibility there either. The problem is that JFIF required the first segment in a file to be FF E0
, while Exif requires FF E1
. So indeed if a file is conformant with one of the specs, it automatically becomes non-conformant with the other.
I haven't toyed with JPEGs for a while, but the last time I checked all JPEG-consuming software that I've checked simply ignored segments that it didn't recognize. So if a program eg. assumes a file is Exif because it starts with a FF E1
segment, it would either still read and recognize FF E0
(not very useful, since it duplicates information from FF E1
) or skip it. All FF Ex
segments should be ignored according to spec if the program doesn't recognize them.