Purely functional implementation of JPEG and ENCODER and DECODER