Skip to main content

Module palette

Module palette 

Source
Expand description

Dominant-colour palettes, matching Eagle’s palettes field.

Eagle runs modified median cut quantization (MMCQ, the algorithm behind color-thief) on a copy of the image at most 360 px wide, then turns box populations into percentages. This port keeps Eagle’s exact control flow, quirks included, so the same pixels give the same palette:

  • the colour bounds are tracked with if min .. else if max, so a channel’s first value only ever sets its minimum;
  • each of the two splitting passes stops after 5 iterations, which caps a palette at about 11 colours;
  • boxes are kept in a lazily sorted queue whose tie order matters.

Constants§

ANALYSIS_WIDTH
Width of the image Eagle analyses.

Functions§

analysis_image
The image Eagle hands to the quantizer: img scaled down (never up) to at most ANALYSIS_WIDTH wide, keeping the aspect ratio.
extract
Extracts the palette Eagle would store for img.
from_rgba
Extracts a palette from an RGBA buffer that is already analysis-sized.
refresh_source
The picture Eagle analyses when a palette is refreshed: the original when the item has noThumbnail (a small SVG is rendered at its own size), otherwise the thumbnail file. None when there is nothing to read.