JPEG encoder for educational purpose