implementing custom libjpeg