1. A method of compressing an image implemented on a device comprising: a. detecting using a processor varying complexity values in portions of an image; b. determining a remaining buffer space of a buffer; and c. allocating a number of bits based on the complexity values of the portions of the image and the remaining buffer space.