jpeg file format decoding

Viewed 1615

I'm trying to write a JPEG/JFIF encoder and decoder from scratch using C. I experimented writing a sample JPEG file, but it seems that I cannot open it using MS paint, Firefox. But I can decode it using JPEGsnoop ( http://www.impulseadventure.com/photo/jpeg-snoop.html?ver=1.5.2) and http://nothings.org/stb_image.c . I think the sample JPEG file complies the JPEG/JFIF standard, I don't know why applications like MS paint and Firefox cannot open it.

Here is how the sample JPEG looks like:


    SOI
       APP0 segment
       DQT  segment (contains two quantization tables)
       COM  segment
       SOF0 segment
       DHT  segment (contains four Huffman tables)
       SOS  segment
       huffman encoded data
    EOI

The sample JPEG file has three component Y Cb Cr. No subsampling for Cb Cr component. The two quantization tables are all filled with ones. The Four huffman tables in DHT segment are all identical, it looks like this


      [0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0]
      [0,1,2, ... , 254]

That means all the codes are 8bits, so huffman encoding does not really compress data.

The huffman encoded data look like this:


       [0x0000(DC) 0x0000(AC)](Y)  
       [0x0000(DC) 0x0000(AC)](Cb) 
       [0x0000(DC) 0x0000(AC)](Cr)  for all (i, j) MCUs except (10, 10)

       the data in (10, 10) MCU: 
       [0x0008(DC) 0x0000(DC), 0x0000(AC)](Y)  
       [0x0000(DC) 0x0000(AC)](Cb) 
       [0x0000(DC) 0x0000(AC)](Cr)

Can anyone tell me what is wrong with this sample JPEG file? thanks.

Here is a link to the sample JPEG file (ha.jpg) http://www.guoxiaoyong.net/ha.jpg

3 Answers
Related