1. A machine-implemented encoding method, comprising: operating a processor to perform operation comprising: quantizing an image by assigning sub-ranges of pixel values in the image to respective quantization levels and determining a target spatial distribution of the quantization levels in the quantized image; accessing a mask lookup table indexing masks with respective index values, wherein each of the indexed masks represents a respective spatial distribution of the quantization levels and all of the masks that are indexed by the mask lookup table collectively represent less than all possible spatial distributions of the quantization levels in the image; and encoding the quantized image with a code comprising a selected one of the index values in the mask lookup table only in response to a determination that the mask indexed by the selected index value exactly matches the target spatial distribution of the quantization levels.