Fix a bug in the palette encoder