I am reviewing legacy code that handles different tpyes of images, including JPEG. The legacy code uses a 4 byte sequence to determine if a byte[] is a valid JPEG. Specifically:
0xFF 0xD8 0xFF and either 0xE0 or 0xE1.
When I did my research I found that all you need is 0xFF 0xD8 0xFF, the 0xE0 or 0xE1 are part of what is known as the APP segment (http://en.wikipedia.org/wiki/JPEG#Syntax_and_structure). This segment is application specific and other research I have done indicates there are at least 4 other values possible in this segment (0xE2, 0xE3, 0xE8 and 0xED).
I thought a JPEG is a JPEG is a JPEG. That given a file with any one of the 6 known/allowed APP segments that any device that can display a JPEG would be able to display the given file. Is this correct?
Is there a good reason for filtering based on particular values of the APP segment?
How exactly does the APP segment effect the JPEG image? Is it used at all or is it application specific data that is only used when the displaying application recognizes their APP value? For instance I read that 0xED is used by Photoshop. So if the image was being displayed by Photoshop then the data in the APP segment is meaningful - but to any other app that is not Photoshop the APP segment is ignored and the image is displayed just fine.
NOTE: in the end a Java applet will be displaying the JPEG.