Lossless halftone image compression using adaptive context template update