> Hi,
> 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).
> Thanks
> --
> Vamsee Lakamsani
JPEG data streams use what they call 'markers' to identify header information
and data streams. Markers could be thought of as similar to TIFF tags.
However, JPEG marker structure is much more free flowing than the TIFF IFD
structure. NOTE: All data is in nibble(4 bit) pairs, bytes(8 bit), and
two byte integers(16 bit) which are big-endian(most significant byte first).
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.