How to remove duplicate colors

I only found these issues:

Mine is that I want to manually or automatically remove all duplicate colors in my color palette.
I understand that with Indexed colors, this may cause issues, but I want to do this:
a. on project start
b. when exporting a palette to reuse later
so I don’t mind about the illustration changing. In addition, I can change some color settings if needed. All I need is that at the end, I can export a proper color palette preset with no redundant colors.

Currently, I’m sorting colors by some parameter so duplicates are neighbors, but the colors are so similar yet sometimes different, that it’s hard to see duplicates with bare eyes. I need to hover each color and compare RGB in text… then remove duplicates.

Another solution I see is to generate a PNG palette, reopen the PNG, and generate New Palette from Sprite, but that’s extra steps.

Is there either a button or an automated setting (riskier) to remove duplicate colors in the color palette?

Alternatively, is there a tool/plugin to merge palettes removing duplicates, or add a new palette except redundant colors? (currently I just Ctrl+C the colors from palette 1, open file with palette 2, add a new dummy color, select it, then Ctrl+V to paste the new colors, but it adds redundant colors too).

I also saw this:

which would help manipulating multiple color palettes at once; but it’s a bit different and would keep redundant colors.

Hi @hsandt,

A lot depends on whether you need to detect exact duplicates or nearly-matching colors in your palette.

Exact duplicates are easy to sift with a Lua script, as a color’s 32-bit integer representation can be used as a hash, or key, to a dictionary. See, for example, this post with a script to concatenate two palettes, excluding any duplicates

The biggest wrinkle you usually run into is how to handle colors with zero alpha, but potentially different RGB channels.

(Note: If you try the script linked above, a file preset string must be exactly right when loading palette from a preset, as a single typo can crash Aseprite :frowning: ).

Nearly-matching colors is a much more complex problem. This is because digital color can be represented multiple ways. Some ways are better suited finding near matching colors according to human perception, but come at the cost of extra computation time and learning on your part to understand them. You can get a taste of what’s involved here:

Aseprite’s scripting API does not provide much to handle this complexity, so you have to decide what’s worth your time and would give good-enough results.

As far as on project start vs. on export, what I’ve done to resolve other unrelated issues is to make my own new file dialog and GPL export (GPL is a file format that stores palettes), then assign custom hotkeys. If you have some coding background and interest in writing your own, take a look at Palette, which has a resize and a saveAs method; Sprite, which has a load from file constructor; and Dialog, which includes a file select widget.

Thank you! I remember the Concatenate Palette script now, this was exactly what I needed, since duplicate colors came from merging existing palettes!

It was in written in my notes and in fact, I had already installed it, but I was looking for “merge” instead of “concatenate”. I noticed I need to export in .pal or .gpl but otherwise I was already exporting my palettes so it shouldn’t change my workflow!

I also have similar colors but that’s another issue, which I can handle with bare eyes for now. Also, I’ll ask my pixel artist to pick a strict color palette next to avoid ending with similar not but identical colors in the same image or across images.

I needed this again today and had the idea of just reusing the Concatenate Palette script, merging the Active palette with itself with Uniques Only. It worked!

  1. Switch to RGB mode, as Indexed Color mode would cause color loss
  2. Run Concatenate Palette script
  3. Select Palette A: ACTIVE, Palette B: ACTIVE (just a trick to concatenate nothing new)
  4. Check Uniques Only (important)
  5. Press OK twice (bug?)

And it works!

I also found a solution without reopening the exported PNG, but it only works if you don’t mind using colors not actually used in the current artwork:

  1. Switch to RGB mode if needed
  2. Create New Palette from Sprite (will remove duplicates but also unused colors)
  3. You can now sort colors and switch back to Indexed Color mode if needed