The implementation is extremely simple (it's literally one line of code.)
All it does is take a pre-processed 'map' of the image and uses the corresponding pixel value as the index into the palette.
(e.g. the color '0x06' in the map is index 6 in the palette)