Pixel sampling and color reduction
The image is read pixel by pixel, or a representative sample for larger images, and colors that sit visually close to each other are grouped together. That collapses the thousands of near-unique pixel values a typical photo contains into a short list of representative swatches, rather than trying to preserve every individual shade actually present in the file.