Trying to get JPEG stuff working, code is a bit of a mess atm. Currently seg faulting when writing back...