3

For a particular reason I am wanting to extract the header info from a jpeg which has been loaded into a byte array.

To find the length of the header I have been comparing the bytes of different jpegs.

The common denominator is that the 1st 623 bytes of each image have the same byte value.

These jpegs are of the same height, width, resolution but of different images/scenes.

Is it really this simplistic? Are the 1st 623 the common header between all assuming that the header does not contain the length of each image in bytes?

5
  • en.wikipedia.org/wiki/JPEG#Syntax_and_structure Commented Dec 19, 2013 at 10:35
  • More like: jpeg.org/public/jfif.pdf Commented Dec 19, 2013 at 10:38
  • Thanks both of you. I wanted to know, in my scenario whether I can simplistically ignore the 1st 623 bytes and the last 2 bytes and say 'the rest are the pixel info'. I have seen these header descripts before. I guess I will run a test to see if I can reconstruct the image on the server just b adding the 'common' 623 header and 'common' 2 bytes tail. Commented Dec 19, 2013 at 10:41
  • 1
    Your specific method might happen to work for your input data, but it's in no way a generic way to do this... ;-) JFIF supports tables-only files ("header" only), as well as table-less files ("data" only). This is probably what you want to use, but you need an encoder/decoder that supports this. Commented Dec 19, 2013 at 12:35
  • Hi, thanks for your feedback. I am quite sure that this would not be a generic approach. It was specific to my app that has a controlled feed of jpegs. Thanks for the info :) Commented Dec 19, 2013 at 15:59

2 Answers 2

1

There is no "JPEG" header (other than the start of image marker). JPEG is a sequence markers, some of which have following data blocks.

Various JPEG file formats define formats (e.g. JFIF, XFIF) for APPn markers that identify the file format.

Your 623 matching bytes could well be the same comment marker written by the same encoder. So, NO you cannot ignore 623 bytes and reliably determine the contents of the file.

My guess is that it would be in an APPn marker specific to the particular file format or in the Start of Frame marker.

Sign up to request clarification or add additional context in comments.

Comments

1

(Posted answer on behalf of the question author).

From my tests If I extract the header from the very 1st image (which is 623 bytes long) and the last 2 bytes 255, 217 and then block copy the bytes in between (623 to length of byte array -2) and append the extracted (1st) header and tail on the server side the image processing works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.