|
Porytiles
|
A generic palette container for colors that support transparency checking. More...
#include <palette.hpp>
Public Types | |
| using | StorageType = std::conditional_t< N==0, std::vector< std::optional< ColorType > >, std::array< std::optional< ColorType >, N > > |
| The storage type used internally, selected based on N. | |
Public Member Functions | |
| Palette ()=default | |
| Default constructs a Palette. | |
| Palette (std::vector< ColorType > colors) | |
| Construct this palette with a given color vector. | |
| Palette (std::array< ColorType, N > colors) | |
| Construct this palette from an array of colors. | |
| Palette (ColorType color) | |
| Constructs a Palette filled with a single color. | |
| void | add (ColorType color) |
| Adds a color to the end of the palette. | |
| void | add_wildcard () |
| Adds a wildcard slot to the end of the palette. | |
| void | set (std::size_t index, ColorType color) |
| Sets the color at a specific index in the palette. | |
| void | set_wildcard (std::size_t index) |
| Sets a slot as a wildcard at a specific index. | |
| bool | is_wildcard (std::size_t index) const |
| Checks if a slot is a wildcard. | |
| bool | has_any_wildcards () const |
| Checks if the palette contains any wildcard slots. | |
| std::size_t | size () const |
| Returns the number of slots in the palette. | |
| ColorType | slot_zero_color () const |
| Get the slot 0 palette color. | |
| ColorType | at (std::size_t index) const |
| Gets the color at a specific index. | |
| std::optional< ColorType > | at_optional (std::size_t index) const |
| Gets the optional color at a specific index. | |
| std::map< ColorType, PaletteIndex > | color_to_index_map () const |
| Creates a map from colors to their palette indices. | |
| std::map< PaletteIndex, ColorType > | index_to_color_map () const |
| Creates a map from palette indices to their colors. | |
A generic palette container for colors that support transparency checking.
Palette is a container for storing colors that satisfy the SupportsTransparency concept. It supports both dynamic (vector-backed) and fixed-size (array-backed) storage based on the template parameter N.
When N == 0 (the default), the palette uses std::vector for dynamic storage, allowing colors to be added incrementally. When N > 0, the palette uses std::array<T, N> for fixed-size storage with compile-time size guarantees.
Both variants support "wildcard" slots - palette positions that have no assigned color. Wildcards are represented internally as std::nullopt. Client code can use wildcards to represent partially-filled palettes or to allow flexible color assignment.
The ColorType template parameter must satisfy the SupportsTransparency concept, meaning it must provide methods for checking whether a color is transparent.
| ColorType | The color type of this palette must satisfy the SupportsTransparency concept |
| N | The fixed size of the palette (0 for dynamic sizing, default) |
Definition at line 47 of file palette.hpp.
| using porytiles::Palette< ColorType, N >::StorageType = std::conditional_t<N == 0, std::vector<std::optional<ColorType> >, std::array<std::optional<ColorType>, N> > |
The storage type used internally, selected based on N.
When N == 0, uses std::vector for dynamic sizing. When N > 0, uses std::array for fixed-size storage. Both use std::optional to support wildcard slots.
Definition at line 56 of file palette.hpp.
|
default |
Default constructs a Palette.
For dynamic palettes (N == 0), creates an empty palette. For fixed-size palettes (N > 0), creates a palette with N wildcard slots (all std::nullopt).
|
inlineexplicit |
Construct this palette with a given color vector.
Only available for dynamic palettes (N == 0). Each color in the input vector becomes a non-wildcard slot.
| colors | The color vector |
Definition at line 76 of file palette.hpp.
|
inlineexplicit |
Construct this palette from an array of colors.
Only available for fixed-size palettes (N > 0). Each color in the input array becomes a non-wildcard slot.
| colors | The color array |
Definition at line 92 of file palette.hpp.
|
inlineexplicit |
Constructs a Palette filled with a single color.
For dynamic palettes (N == 0), creates a palette containing 16 copies of the provided color. For fixed-size palettes (N > 0), fills all N slots with the provided color. No slots are wildcards after this construction.
| color | The color to fill the palette with |
Definition at line 109 of file palette.hpp.
|
inline |
Adds a color to the end of the palette.
Appends the provided color as a non-wildcard slot at the end of the palette. This method is only available for dynamic palettes (N == 0).
| color | The color to add |
Definition at line 132 of file palette.hpp.
|
inline |
Adds a wildcard slot to the end of the palette.
Appends a wildcard slot (std::nullopt) at the end of the palette. This method is only available for dynamic palettes (N == 0).
Definition at line 145 of file palette.hpp.
|
inline |
Gets the color at a specific index.
Returns the color at the given index. Panics if the index is out of bounds or if the slot is a wildcard.
| index | The index to get |
Definition at line 276 of file palette.hpp.
|
inline |
Gets the optional color at a specific index.
Returns the optional color at the given index, which may be std::nullopt if the slot is a wildcard. Panics if the index is out of bounds.
| index | The index to get |
Definition at line 298 of file palette.hpp.
|
inline |
Creates a map from colors to their palette indices.
Builds a lookup table that maps each non-wildcard color in the palette to its corresponding index position. Slot 0 is explicitly excluded because it is reserved for the transparent color and handled separately. Wildcard slots are also excluded.
This can cause issues when comparing tiles that were indexed using different palette slots for the same color. If you need to match tiles where the palette may have duplicate colors, use color-equivalence comparison (compare the actual palette colors at each index) rather than direct index comparison. See TilesPngWorkspace::find_existing_contiguous_tiles_by_color() for an example of this pattern.
Definition at line 325 of file palette.hpp.
|
inline |
Checks if the palette contains any wildcard slots.
Definition at line 211 of file palette.hpp.
|
inline |
Creates a map from palette indices to their colors.
Builds a lookup table that maps each non-wildcard palette index to its corresponding color. Slot 0 is explicitly excluded because it is reserved for the transparent color and handled separately. Wildcard slots are also excluded.
Definition at line 346 of file palette.hpp.
|
inline |
Checks if a slot is a wildcard.
Returns true if the slot at the given index is a wildcard (has no assigned color). Panics if the index is out of bounds.
| index | The index to check |
Definition at line 198 of file palette.hpp.
|
inline |
Sets the color at a specific index in the palette.
Replaces the slot at the given index with the provided color, making it a non-wildcard slot. Panics if the index is out of bounds.
| index | The index at which to set the color |
| color | The color to set |
Definition at line 162 of file palette.hpp.
|
inline |
Sets a slot as a wildcard at a specific index.
Replaces the slot at the given index with a wildcard (std::nullopt). Panics if the index is out of bounds.
| index | The index at which to set the wildcard |
Definition at line 179 of file palette.hpp.
|
inline |
Returns the number of slots in the palette.
For dynamic palettes (N == 0), returns the current vector size. For fixed-size palettes (N > 0), returns N.
Definition at line 229 of file palette.hpp.
|
inline |
Get the slot 0 palette color.
The slot 0 color is effectively unused by the GBA. Any tile pixel with value 0 will be treated as transparent by the hardware, thus the value in any palette's 0 slot is basically ignored. Some community tools exploit this by utilizing slot 0 for configuration, metadata, etc. (see .pla blend colors). Porytiles should respect user slot 0 preferences and do its best to ignore the value set here. It should also avoid clobbering it at all costs. Users communicate transparency information in Porytiles assets by utilizing the intrinsic/extrinsic transparency concept.
Definition at line 254 of file palette.hpp.