I need to get the width and height information from
a JPEG file without reading all the image data from
the file (I guess jpeg_decompress reads all the image
data from the file in addition to the header).
> I need to get the width and height information from
> a JPEG file without reading all the image data from
> the file (I guess jpeg_decompress reads all the image
> data from the file in addition to the header).
> Vamsee Lakamsani
There is no guarantee where the information will be located.
You should search through the JPEG stream for the required information.
I recommend using 512 bytes as your read buffer size, you should find the
information in the first 512 buffer but don't depend on it.
Ok here is the search, search for a 'start of frame marker' = 0xFFC# where
# can be 0 - F. The data following the start frame marker is as follow:
integer length Marker segment length including this integer.
byte bits Component length in bits.
integer height Image height in pixels.
integer width Image width in pixels.
byte planes Number of components.
. Component information
If you need more information than this it is available in the standard
or the Penny & Mitchell book. Hope this helps.
The minimum code to interpret JPEG headers safely is a few dozen lines
of C. You can find an example in rdjpgcom.c in the new release of the
IJG JPEG code (ftp.uu.net:/graphics/jpeg/jpegsrc.v5beta1.tar.gz).
regards, tom lane
organizer, Independent JPEG Group
Go into IJG source codes. The location of IJG sources is mentioned
in JPEG FAQ.
A copy of FAQ of JPEG is available at
David Bourgin - UFR IMA (French University - Grenoble)
I'm a netsurfer, and as such a citizen of the world!