remap
allows you to remap the colors of an image to a limited set of colors specified by your palette.
git clone https://github.com/bernhardfritz/remap.git
cd remap
mkdir build
cd build
cmake ..
make
make install
remap inputFilename paletteFilename outputFilename
remap dungeon.png endesga-32-1x.png output.png