How to write a JPEG file decoder from scratch
This page has a lot of info on how to process a jpeg file. Also, you can take a look at my own attempt at writing a jpeg decoder in Python.
The short variable names in the program often correspond directly to variables in the standard. So if you have the standard ready, it'll help a lot. It's called ITU-1150 and is freely available on the Internet.
Jpegs are tricky if you're just starting. You need to work with huffmann tables, have some sort of fast inverse discrete cosine transform function, and the ability to interpret quantization tables.
http://en.wikipedia.org/wiki/JPEG is rather helpful.
If you want to start with something simpler, look at PNGs. The format is basically a header, followed by a bunch of variable length, chunks, and then a zlib stream. Decompressing that leaves you with almost-raw pixels, but they've been filtered. Unfiltering is easy.