Export PNG without compressing the palette

I’m working with 4bpp indexed sprites and have an interesting issue.

Several of my sprites are designed to share the same 16-color palette but when I save sprites that don’t use the first few colors in the palette, the pixels are re-indexed when the image is saved to PNG format. So if I only use color indexes 0x9, 0xa, 0xe, and 0xf in the drawing, when I save the PNG, they are re-indexed as 0x1…0x4 in the PNG file, which makes them look wrong in my application they’re designed for.

Is there a way to write a LUA script that would export the PNG with the indexes unchanged?

Even more useful would be a way to save them with the indexes = mod 16. So color 0xb would save as 0xb, but 0x1b would be saved as 0xb also. Obviously this would require that the sprite only used indexes within the same 16-color ranges, but that would make it much easier to play with multiple 16-color palettes in Aseprite.

Welcome @ZeroByte, it’s strange because Aseprite should load and save the 16-color palette correctly, are you using Indexed mode? Could you please check if going to Sprite > Color Mode what options are available? Can you share an example .png to give a try?

This is weird. I’m not on the computer with the PNGs in question, so I went to make a quick pair of example PNGs to post here. Here, it’s working properly either when I save the files as PNG, or when I export them as PNG. I’m not sure what I may have done wrong when working with the other images, but I’ll go take a peek again later on when I’m at the computer they’re on.

Meanwhile, I should be able to get back to what I wanted to accomplish in the first place. I’m using Aseprite to draw resources for a game I’m making on this retro computer called Commander X16. It has a single 256-color master palette which 4bpp assets divide into sixteen 16-color palettes. It would be nice in Aseprite to have the whole palette available while drawing, but be able to swap the pixels of the sprite to use one of the different 16-color ranges, and to be able to export them with indexes relative to the “sub palette” currently used.