reading a JPEG header

reading a JPEG header

Post by Vamsee Lakamsa » Mon, 01 Aug 1994 06:27:57



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

 
 
 

reading a JPEG header

Post by Bill Tutt » Wed, 03 Aug 1994 01:14:08



> 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.



 
 
 

reading a JPEG header

Post by Tom La » Wed, 03 Aug 1994 23:17:32



> 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:

Just doing that is likely to fail ... in fact, it's certain to fail
if the file contains a compressed thumbnail image per the JFIF spec.
You need to skip over the contents of preceding markers to avoid
misinterpreting data as a marker.

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

 
 
 

1. JPEG file header reading function wanted!

Go into IJG source codes. The location of IJG sources is mentioned
in JPEG FAQ.
A copy of FAQ of JPEG is available at
ftp://rtfm.mit.edu:/pub/usenet/comp.graphics/

--
                                              David

David Bourgin - UFR IMA (French University - Grenoble)
I'm a netsurfer, and as such a citizen of the world!

2. Converting NTSC SVCD to Pal SVCD with Video Studio 6

3. How to read header of Graphics

4. rangefinder data merging

5. Reading TIFF File Header

6. Selections and Gray Pixels

7. Reading Graphic File Header

8. Reading DLL Headers..

9. How to read a gif file header?

10. Looking for software to read and edit headers of ICC color profiles

11. problems reading PCX header

12. How to read the graphic header in C