Replace Color At Index
Swap one color in a palette without rebuilding it
- palette
- color
- modified_palette
Replace Color At Index is the precision tool of the Pixel Palette Art pack. It takes a palette, one new color, and an index, and swaps out exactly one slot - nothing else moves. Need slot 12 to be a slightly darker blue instead of the muddy one you mixed? This is the node. It's the "find and replace" for indexed palettes, where position is meaning and you want to change one entry while keeping every other index intact.
Where it shines is the iterative workflow. You load a palette, eyeball it in Palette View, spot the one shade that's wrong, and swap it. Because the operation is non-destructive - the input palette is deep-copied and the replacement lands in a fresh palette - you can chain replacements one after another: replace slot 3, then slot 7, then review the whole thing again. It's the palette equivalent of a surgical edit, and it beats rebuilding a gradient or re-typing 32 values by a wide margin.
How it works
The node validates that the input is a real palette and a real color, and that index is in range (0 to length−1). On success it deep-copies the palette and assigns your color to that slot. Two behaviors to know: the replacement color keeps its own identity (including its name, which will show up in GIMP exports and Palette View labels), and out-of-range indices don't crash - the node logs an error and returns the original palette unchanged, so a bad index is a silent no-op rather than an exception.
Inputs and outputs
palette(PIXEL_PALETTE) - the one to edit.color(PIXEL_COLOR) - the new color for that slot.index(INT, default 0) - which slot, 0-based.
Output: modified_palette, a new PIXEL_PALETTE identical to the input except for the one swapped slot.
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. Pillow only - no model files or heavy deps.
Common issues
Zero-based indexing catches everyone once. The tooltip even spells it out: index runs 0 to length-1, so the first color is slot 0. Pick 12 thinking it's the 12th color and you're editing the 13th.
The silent no-op on out-of-range is the other trap - if you think you replaced a color but Palette View shows no change, your index was probably past the end of the palette, and the node just handed your original back with an error in the console. Check the terminal before assuming a bug. And one more: this replaces a slot, it doesn't find-and-replace a value. If the same wrong color lives in slots 4 and 9, you need two Replace nodes (or Sort/Copy Subset gymnastics), because there's no "replace every instance of this color" mode.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| palette | PIXEL_PALETTE | Palette dans laquelle remplacer la couleur | |
| color | PIXEL_COLOR | Nouvelle couleur à insérer | |
| index | INT | 00–255 | Index de la couleur à remplacer (0 à palette.length-1) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| modified_palette | PIXEL_PALETTE | — |