add palette merging function