3 ms·
If you want to know all the details, the spec itself isn't too hard to understand either, and comes with a bunch of flowcharts on how to decode the Huffman tabl
by userbinator 8y ago
If you want to know all the details, the spec itself isn't too hard to understand either, and comes with a bunch of flowcharts on how to decode the Huffman tables and the run-length codes for each DCT block:
https://www.w3.org/Graphics/JPEG/itu-t81.pdf https://www.w3.org/Graphics/JPEG/itu-t81.pdf
I highly recommend writing a JPEG en/decoder as an exercise in coding; getting to the point of being able to decode almost all the images you probably have or can find on the Internet shouldn't take more than a few hours and <1k lines of (C) code. Once you've done that, you'll be ready to take on a simple video codec, like H.261. I find it self-motivational because the results are very visible (and if you have a bug, all sorts of fun effects can appear too.)
(As you may have guessed, I've written a JPEG decoder, as well as JBIG2 (partially), H.261, and MPEG-1, each of which is roughly 1kLoC. Currently thinking of trying JPEG2000 too, which is over an order of magnitude more complex.)
- cedex12 8y agoany book recommendation on the basics of compression?
- grenoire 8y agoWhat's always daunting to me in projects like these is the time it would take me to dig and understand the spec itself...
- userbinator 8y agoThe JPEG spec is a bit on the verbose side, and most of it can be skimmed easily; for example, one of the sentences near the beginning is "An encoder is an embodiment of an encoding process." There's also specifications of lossless modes and arithmetic compression, which you probably don't care about for a first exercise; the "baseline DCT" is the only variant that really matters. The spec is nearly 200 pages, but the diagrams and flowcharts take up a significant amount of that space. Interestingly enough, the JPEG2000 spec is at first glance not that much longer, but it is far more terse, so the size of the spec is only a rough estimate of the complexity and work it'd take to implement.
- 1wd 8y agoCan you share your 1kLoC sources?
- appleflaxen 8y agothat's awesome! are there any good free libraries for jpg2000?
- userbinator 8y agoI can't say if it's "good", but OpenJPEG is the most prominent one and endorsed as a reference implementation: https://www.openjpeg.org/ https://www.openjpeg.org/