set_color_mode
Convert sprites between RGB, indexed, and grayscale modes. For indexed output, builds the palette from the artwork and refuses conversions that would erase drawn pixels.
Instructions
Convert a sprite between colour modes ("rgb", "indexed", "gray").
Converting **to indexed** builds the palette from the sprite's own colours first,
which is what the editor does and what makes the art survive. Mapping art against
whatever palette the sprite happened to carry is how this tool used to empty a
sprite: a saved RGB sprite carries a single transparent entry, so every pixel
resolved to it and the whole image became transparent while the call reported ok.
Args:
color_mode: "rgb", "indexed", or "gray".
dithering: "none" (default), "ordered", or "old". How a colour between two
palette entries is resolved. Indexed conversions only.
palette_source: "from_art" (default) quantizes the sprite's colours into a new
palette and maps onto that, so flat colours convert exactly. "keep" maps
against the palette the sprite already has, for when you loaded or built one
deliberately; snapping the art to that palette is the point, so expect
colours to shift, and expect two art colours to merge where the palette has
only one entry near them. Indexed conversions only; the other modes have no
palette to choose.
**Refuses** a conversion to indexed that would make drawn pixels disappear, naming
how many, and leaves the file untouched when it does. Losing colour accuracy is what
indexed mode is for and is allowed; losing pixels is not recoverable and is the one
thing a mode change must never do quietly. `set_palette` or `add_palette_color` fix a
palette that has nothing to draw with.
That check counts every pixel of every frame, twice. Past `MAX_VERIFY_PIXELS` the
conversion still runs and reports `verified: false` with the reason, rather than
being refused: a capability that declines to work on a large sheet because the check
is unaffordable is worse than one that works and says what it did not check.
`diff_sprites` against a copy taken beforehand answers the same question by hand.
Returns the sprite's structured info, plus `drawn_pixels` and `verified` (whether
that count was actually compared across the conversion) and the `palette_source`
used, for indexed targets.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | ||
| dithering | No | Default: "none". | none |
| color_mode | Yes | ||
| palette_source | No | Default: "from_art". | from_art |