How are the palette colors chosen?
The image is sampled pixel by pixel on a canvas, colors are grouped into buckets of similar shades, and the most frequent buckets become your palette — with a minimum color distance between picks so the palette doesn't fill up with near-identical shades.