Easily swap palletes, with intelligent color swap

I’ve wondered, though never explored, if scaling the range of the source palette to fit the range of the destination palette (at the simplest an AABB mapping) before performing colour matching could produce better results without manual fiddling.