New Script for perfect palette generation from RGB sprite

I found out that Aseprite palette generation is also not perfect. Many colors in palette don’t match RGB colors of image after “New Palette from Sprite” operation. So I’ve written a simple Lua script to generate palette from RGB sprite with EXACTLY same colors used in image across all frames. Please prefix required layers with + or # sign for script to process them.


Also here is new version of RGB-to-Indexed conversion script. It’s still required to keep right colors after conversion, because “Sprite → Color Mode → Indexed” doesn’t do the thing right. Mark your layers with + or # sign prefix and click OK after each converted layer added to new sprite. Then save new Indexed sprite to file.

eg_rgbconv.lua eg_rgbconv.lua - Google Drive

That’s it! :slight_smile:

Hi @BraidAcer, we would love to check an example where the palette is not generated correctly. There are cases (mainly for images with more than 256 colors) that things get tricky (colors must be grouped in clusters and a quantization process will loss precision in all the colors).

Here is the file test_palgen.ase - Google Drive with problem details

Also: Maybe in this sprite palette generated correctly, but we found cases when it was not generated correctly. I’ll try to find where exactly. So I had to write palgen script.

ok i just reported the same bug, thats actually funny

I tested and it looks like the colors are generated correctly in this case, but I understand that problems will appear when the image contains more than 256 colors (all colors are reduced to 5-bit RGB precision and 3-bit for alpha). Some information about the fix coming in v1.3. We’ll try to add a new “automatic heuristic” no choose the algorithm to generate the palette automatically (octree by default, the old 5-bit RGBA cube if alpha is needed).

when i was testing this i also got the palette right, however i noticed that colour count was reduced after the conversion to indexed.
it goes from 17 colours (without alpha entry) to 14 colours (without alpha entry).
there’s also the difference depending on process. convert to indexed, convert to rgb, create palette yields different result than create palette, convert to indexed:

interestingly, BraidAcer’s script generates only palette of 16 colours (17, but with alpha entry), but that’s another thing.

Sorry I followed the instructions now in the layers (didn’t see them before). It fails in the indicated area. The new version v1.3 will fix this.


I hope we’ll see 1.3 version soon :slight_smile:

Among 17 colors generated by “New Palette from Sprite” first two are both blacks. My script generates only index 0 as black and as transparent for evident reason (transparent color index 0 in Indexed sprites). Aseprite generates two blacks of same reason I presume. Second black is for bkg layer.


Ok, got it. My script don’t generate black color at all if only +sprite layer if prefixed, because black color is not used in that layer. That is a feature of palgen script allowing to get generated only colors really used in layers prepared for conversion / exporting.

oh, i see - i checked it and indeed it does it in the case of create palette → convert to indexed, when it’s convert to indexed → convert to rgb → create palette double black isn’t there (colour count is still lower than it should be, of course). interesting. btw. i’m converting both +bkg and +sprite layers at once.