Orama-Interactive / Pixelorama

Unleash your creativity with Pixelorama, a powerful and accessible open-source pixel art multitool. Whether you want to create sprites, tiles, animations, or just express yourself in the language of pixel art, this software will realize your pixel-perfect dreams with a vast toolbox of features. Available on Windows, Linux, macOS and the Web!
https://orama-interactive.itch.io/pixelorama
MIT License
7.24k stars 387 forks source link

Implement indexed mode #1136

Closed OverloadedOrama closed 1 week ago

OverloadedOrama commented 1 week ago

Implements #572. In indexed mode, each pixel is assigned to a number that references a palette color. This essentially means that the colors of the image are restricted to a specific palette, and they will automatically get updated when you make changes to that palette, or when you switch to a different one.

Users can select whether new projects are using RGBA or indexed mode from the create new project dialog, and they can change the color mode whenever they want from the Image menu. Converting a project from RGBA to indexed mode will automatically change the colors of the image by finding the closest color in the selected palette, similar to what the Palettize effect does. Changing from indexed mode to RGBA does not change the colors of the image, but they will stop changing automatically get making changes to the palette.

https://github.com/user-attachments/assets/abbd294e-7148-4384-89f2-cdbc7dbd91f9

Since Godot's Image class has no indexed format, I made a custom ImageExtended class that extends Image and mimics indexed mode by having an internal Image for the indices of each pixel. Using an Image for the indices gives us the advantage of using shaders for quick operations, such as setting the indices when converting from RGB to indexed, and when converting from indexed to RGB. Now all PixelCels have an ImageExtended instance instead of Image. The indices are also stored in pxo files.

If a pixel's index is set to 0, it means that that pixel is transparent. Indices that are outside the bounds of the current palette (which can occur by shrinking the palette or switching to a smaller one) will also appear as transparent.

All tools, image effects, layer effects, resizing, merging layers and undo/redo all work with indexed mode.