How to limit the color palette while rendering?

Maybe this is what you need.