JPG segment length encoding

Posted by Blorgbeard on Stack Overflow See other posts from Stack Overflow or by Blorgbeard
Published on 2010-04-02T00:07:52Z Indexed on 2010/04/02 0:13 UTC
Read the original article Hit count: 646

Filed under:

I'm trying to write some code to extract Exif information from a JPG.

Exif is stored in the APP1 segment of a JPG file. According to the Exif spec, the format of the APP1 segment is supposed to start like this:

FF E1        // APP1 segment marker
nn nn        // Length of segment
45           // 'E'
78           // 'x'
69           // 'i'
66           // 'f'

And it goes until there is an FF followed by something other than FF or 00.

Looking at a JPG in a hex editor, I can see FF E1 and the Exif string, but I'm having trouble decoding the length bytes. An example: In one jpg, my hex editor tells me the APP1 segment is 686 bytes long, but the length bytes are F7 C8.

How should I use those bytes to come up with 686 decimal?

© Stack Overflow or respective owner

Related posts about jpg

Related posts about exif