Sort Palette
Make sense of a color pile by hue or by brightness
- palette
- sorted_palette
Sort Palette is the tidying node - the one you reach for when a palette looks like someone spilled a box of crayons. It takes any palette and reorders it by one of two criteria: hue (walking the color wheel) or brightness (dark to light). One input, one dropdown, and suddenly a chaotic pile of colors becomes something you can actually scan with your eyes.
It's a deceptively important step in real pixel-art workflows. Palettes loaded from random .gpl files or stitched together with Append Palette rarely arrive in a usable order - especially if you care about index positions, since in indexed art the order is the layout. Sorting by hue gives you the classic rainbow ramp that's easy to reason about; sorting by brightness gives you a value ramp you can use directly as a lighting scale (shadows → midtones → highlights). It's also the classic pre-processing step before you hand a palette off to a human or an exporter.
How it works
The node deep-copies the palette and sorts it with Python's sorted-style keying. Hue sort converts each color to HSV (via colorsys) and sorts on the hue value, so it wraps the wheel in the natural 0–1 order. Brightness sort uses the perceptual luminance formula 0.299·R + 0.587·G + 0.114·B - note it's weighted toward green, matching human perception, not a naive average. Either way, the original palette is untouched; you get a new, reordered palette out. Color names travel with their colors through the sort.
Inputs and outputs
palette(PIXEL_PALETTE) - what to reorder.sort_by-hueorbrightness(defaulthue).
Output: sorted_palette, a new PIXEL_PALETTE with the same colors in a new order.
Installing
Part of the Pixel Palette Art pack. ComfyUI Manager → "Pixel Palette Art", or:
cd ComfyUI/custom_nodes
git clone https://github.com/ranska/pixel_palette_art.git
Restart ComfyUI; it's under pixel_art/palette. Just Pillow - no downloads, no models.
Common issues
The whole point is that sorting destroys your original order. If your palette was deliberately ordered (a dark-to-light ramp where slot 0 is the outline color), sorting by hue will scramble that intent - and there's no undo, so keep the original wire around for comparison. This is the one node where "save a copy first" is genuinely good advice.
Brightness vs value is a subtle difference people bump into: brightness here is perceptual luminance, not raw RGB sum, so pure red and dark teal with the same "average" will not sit next to each other. That's correct behavior, but it surprises people the first time. And the usual pack caveat: output is an object, so wire it into Palette View to see the sorted result - if you sort and "nothing happened," you're looking at the wrong thing.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| palette | PIXEL_PALETTE | Palette à trier | |
| sort_by | COMBO | hue | Critère de tri : teinte (hue) ou luminosité (brightness) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| sorted_palette | PIXEL_PALETTE | — |