Importing indexed color png as cel

I have tried to import some of my png as CEL in a sprite, but I get the following issue:

                local image = Image{ fromFile=app.fs.joinPath(folderPath, item)}
                log("image path: ", item ))
                local cel = ase:newCel(layer, celNumber, image, Point(0, 0))

The log indicates a correct file, but all the ones that use indexed colors are left totally transparent. I tested with switching one to RVB, and it worked. Do I need to specify something to import images with a palette? Should I convert all to RVB? Or do I need to set up a Sprite palette first so that it covers all colors in use in the files to be imported?

Hi @Galdred,

This sounds similar to another thread:

You can load the same file path as an image and as a palette, then use both to make an RGB color mode version.

I’m guessing you could also load as a Sprite, convert to RGB with a command, extract copies of the cel images you want, then close the sprite when done. I’ve not tried this approach, but I suspect the trick would be making sure that commands target the correct sprite and that no references to frames, cels, layers outlive the reference to the sprite to which they belong.

If you want to convert the composite RGB sprite to be indexed color mode afterward, and want to extract a cumulative palette, the “New Palette from Sprite” command is called ColorQuantization in the API. Check the source code, not the documentation, for parameter names.

1 Like

Thank you for your helpful reply!
image and palette loading seems like the best solution.
What would be the best if I have to import several indexed images into a single sprite? All the images of a given “layerName” would share the same palette, but the palette might be different between layerNames.

If I import them all as color indexed images, I would need to check every image palette against the sprite palette, add the missing ones and modify the pixels in the image/cels so that they use the index of the newly added sprite colors, right?

If so, it seems better to convert to RGB on load, and back to indexed on export.

I’m not sure if you’re trying to take the rubber duck approach here, but I would suggest drafting some code (even just testing out the methods I mentioned above one by one, or the code in the linked thread). Then, later, if you run into issues after integrating, post with an MCVE.