Make a parameter const
Move code
Use long for width and height of JPEG decoder
Add reading and writing from memory