I am trying to write a JPEG / JFIF encoder and decoder from scratch using C. I have experimented with 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 conforms to the JPEG / JFIF standard, I donโt know why applications like MS paint and Firefox cannot open it.
Here's what an example 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
An example JPEG file contains three components of Y Cb Cr. No subsampling for the Cb Cr component. Two quantization tables are filled with one. The four huffman tables in the DHT segment are identical, it looks like
[0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0]
[0,1,2, ..., 254]
This means that all codes have 8 bits, so huffman encoding really does not compress the data.
Huffman encoded data is as follows:
[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 someone tell me what is wrong with this sample jpeg file? Thank you
Here is a link to a sample JPEG file (ha.jpg) http://www.guoxiaoyong.net/ha.jpg
c image file-format compression jpeg
PeopleMoutainPeopleSea
source share