How the Color Palette Extractor Works
The page decodes the user’s image and draws it to an OFFSCREEN <canvas>, downscaled so its longest edge is at most 320px, then reads the raw RGBA pixels with getImageData. A pure engine (paletteExtractEngine.ts) stride-samples the visible (opaque) pixels down to roughly 24,000 points and runs a MODIFIED MEDIAN CUT quantizer: all points start in one box, and the box with the greatest priority — its colour-cube volume multiplied by its pixel population — is split at the median of its longest RGB channel, repeating until the requested colour count is reached. Each box is reported as the population-weighted average of its pixels, ordered by area share. Everything runs in the browser; the image is never uploaded.
- Image drawn to an offscreen canvas and read with getImageData — no upload
- Downscaled to ≤320px and stride-sampled to ~24k pixels for instant results
- Modified median cut splits the most populous box first (volume × count)
- Each swatch is the population-weighted average of its cluster
- Colours are ordered from largest area share to smallest
