Nodes/Pixel Palette Art/Insert Palette At Index
ComfyUI Node

Insert Palette At Index

Drop colors into the middle of a palette, not the end

By ranska·Created about a year ago·Updated 7 months ago· 1
Insert Palette At Index
  • palette
  • sub_palette
  • modified_palette
index0

Insert Palette At Index is the surgical version of Append Palette. Where append just glues a second palette onto the end, this one lets you choose the exact position where a sub-palette gets spliced in. It's the difference between "add these colors at the end" and "add these colors right after index 3, because that's where the shadows end and the highlights begin."

This is one of those nodes you don't need every day, but when you need it, there's no workaround. Building an indexed palette is a positional art - slot 0 might be your outline color, slots 1–4 your shadow ramp, slots 5–8 your base. If you later want to widen the shadow ramp, you can't just append; the new colors have to land between the existing bands or every index downstream shifts. Insert gives you that. Set index to 4 and your sub-palette slides in before what's currently at index 4, pushing everything else down.

How it works

The node calls PixelPalette.insert_palette(sub, index), which builds a new palette from three slices: everything before index, the sub-palette's colors, then everything from index on. All colors are deep-copied, so neither input palette is modified - the output is a brand-new object. index=0 inserts at the very beginning; index=len(palette) appends, which makes Insert a strict superset of Append if you ever want to forget Append exists.

One honest limitation: the index slider caps at 255. Palettes in this pack are realistically far smaller than that, so it only bites if you're doing something pathological like stitching together dozens of ramps into one mega-palette. If your palette exceeds the cap, you'll hit the runtime guard and get the original palette back with an error logged.

Inputs and outputs

  • palette (PIXEL_PALETTE) - the destination you're splicing into.
  • sub_palette (PIXEL_PALETTE) - the colors to insert.
  • index (INT, default 0) - insertion position; 0 = front.

Output: modified_palette, a new PIXEL_PALETTE of len(palette) + len(sub_palette) colors. Wire it into Palette View to inspect the seam, or Sort Palette if you don't actually care where the insert lands.

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. Only Pillow needed - no model files, no downloads.

Common issues

The index-off-by-one confusion is the classic. Colors are inserted before the current occupant of index, so index=4 means "the old index-4 color moves to 5 and everything shifts down." If you want a sub-palette to land after position 4, insert at 5.

Out-of-range behavior is silent-but-safe: an index beyond the palette length returns a deep copy of the original and logs an error, rather than throwing and killing your graph. And if the two input palettes are actually the same object (a common shortcut), you'll get a doubled palette - inserting a palette into itself works, but it's almost never what you meant. Use Copy Subset to make a distinct slice first.

Categorypixel_art/palette

Inputs (3)

NameTypeDefaultDescription
palettePIXEL_PALETTEPalette de destination
sub_palettePIXEL_PALETTEPalette à insérer
indexINT00–255Position d'insertion (0 = début)

Outputs (1)

NameTypeDescription
modified_palettePIXEL_PALETTE