1. A method of encoding programmed in a controller in a device comprising: a. performing embedded graphics coding by i. partitioning an image into blocks; ii. converting pixels of the blocks into binary representations; iii. partitioning the pixels into groups; and iv. processing the groups in a current bit-plane; b. applying context-adaptive prediction comprising performing prediction on refinement bits and generating prediction residuals, if members of a group have a different bit value; and c. applying binary run-length coding including applying an adaptive codebook to the prediction residuals.