c - jpeg file format question -


i'm trying write jpeg/jfif encoder , decoder scratch using c. experimented writing sample jpeg file, seems cannot open using ms paint, firefox. can decode using jpegsnoop ( http://www.impulseadventure.com/photo/jpeg-snoop.html?ver=1.5.2) , http://nothings.org/stb_image.c . think sample jpeg file complies jpeg/jfif standard, don't know why applications ms paint , firefox cannot open it.

here how sample jpeg looks like:

      soi        app0 segment        dqt  segment (contains 2 quantization tables)        com  segment        sof0 segment        dht  segment (contains 4 huffman tables)        sos  segment        huffman encoded data     eoi  

the sample jpeg file has 3 component y cb cr. no subsampling cb cr component. 2 quantization tables filled ones. 4 huffman tables in dht segment identical, looks this

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

that means codes 8bits, huffman encoding not compress data.

the huffman encoded data this:

         [0x0000(dc) 0x0000(ac)](y)          [0x0000(dc) 0x0000(ac)](cb)         [0x0000(dc) 0x0000(ac)](cr)  (i, j) mcus except (10, 10)         data in (10, 10) mcu:         [0x0008(dc) 0x0000(dc), 0x0000(ac)](y)          [0x0000(dc) 0x0000(ac)](cb)         [0x0000(dc) 0x0000(ac)](cr)  

can tell me wrong sample jpeg file? thanks.

here link sample jpeg file (ha.jpg) http://www.guoxiaoyong.net/ha.jpg

i had similar problem years ago png code (though didn't write scratch). turns out code more standards compliant libraries windows, browsers, etc. did fine on typical cases, choked on unusual , contrived images, if in line standard. common way trip them use odd pixel width image. half of test suite not viewable windows. (this many versions ago, windows 95. windows codecs have improved substantially.)

i ended building open source png library , using reference implementation. long images code produced parsed reference implementation , vice versa, called good. checked code display image windows display. every time found bug, added image test suite before fixed it. enough project.

you same. believe there's open source jpeg library that's used reference implementation.

if want figure out why firefox (or whatever) cannot open image, try starting image open in firefox. incrementally make small changes (e.g, hex editor) make more image fails. might narrow down aspect of image tripping application. admittedly, of steps may hard try.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -