First pass at a decoder. Unabashedly ripped from image/jpeg