|
Porytiles
|
A bidirectional mapping between pixel color values and sequential integer indices. More...
#include <color_index_map.hpp>
Public Member Functions | |
| ColorIndexMap ()=default | |
| std::size_t | size () const |
| Returns the number of unique colors in the mapping. | |
| bool | empty () const |
| Determines if the mapping is empty. | |
| void | add_tile (const PixelTile< PixelType > &tile) |
| Adds colors from a single tile to the mapping using intrinsic transparency. | |
| void | add_tile (const PixelTile< PixelType > &tile, const PixelType &extrinsic) |
| Adds colors from a single tile to the mapping using extrinsic transparency. | |
| void | add_pal (const Palette< PixelType, pal::max_size > &pal) |
| Adds colors from a fixed-size palette to the mapping using intrinsic transparency. | |
| void | add_pal (const Palette< PixelType, pal::max_size > &pal, const PixelType &extrinsic) |
| Adds colors from a fixed-size palette to the mapping using extrinsic transparency. | |
| void | add_pal (const Palette< PixelType > &pal) |
| Adds colors from a dynamic palette to the mapping using intrinsic transparency. | |
| void | add_pal (const Palette< PixelType > &pal, const PixelType &extrinsic) |
| Adds colors from a dynamic palette to the mapping using extrinsic transparency. | |
| void | add_anim (const Animation< PixelType > &anim) |
| Adds colors from an animation to the mapping using intrinsic transparency. | |
| void | add_anim (const Animation< PixelType > &anim, const PixelType &extrinsic) |
| Adds colors from an animation to the mapping using extrinsic transparency. | |
| std::optional< PixelType > | color_at_index (ColorIndex index) const |
| Retrieves the color associated with a given index. | |
| std::optional< ColorIndex > | index_at_color (const PixelType &color) const |
| Retrieves the index associated with a given color. | |
A bidirectional mapping between pixel color values and sequential integer indices.
ColorIndexMap provides a true bidirectional association between pixel color values and sequential integer indices, starting from 0. The class maintains two internal maps:
This class is used for palette operations where each unique non-transparent color in a collection of tiles needs to be assigned a unique integer identifier, with the ability to perform lookups in both directions.
The mapping is constructed by examining all unique non-transparent colors across a collection of tiles, filtering out both intrinsically transparent pixels (alpha=0) and extrinsically transparent pixels (e.g., magenta for Rgba32). Each unique color that passes the transparency filter is assigned the next available sequential index.
| PixelType | The pixel color type, must satisfy SupportsTransparency concept |
Example usage:
Definition at line 56 of file color_index_map.hpp.
|
default |
|
inline |
Adds colors from an animation to the mapping using intrinsic transparency.
Iterates through all tiles in the animation's key frame (if present) and all regular frames, adding any new colors to the mapping. Colors that already exist in the mapping are skipped. New colors are assigned sequential indices starting from the current size of the mapping.
This overload is only available for pixel types that support intrinsic transparency (e.g., IndexPixel).
| anim | The animation to extract colors from |
Definition at line 207 of file color_index_map.hpp.
|
inline |
Adds colors from an animation to the mapping using extrinsic transparency.
Iterates through all tiles in the animation's key frame (if present) and all regular frames, adding any new colors to the mapping. Colors that already exist in the mapping are skipped. New colors are assigned sequential indices starting from the current size of the mapping.
This overload is only available for pixel types that support extrinsic transparency (e.g., Rgba32).
| anim | The animation to extract colors from |
| extrinsic | The extrinsic transparency value used for transparency filtering |
Definition at line 235 of file color_index_map.hpp.
|
inline |
Adds colors from a dynamic palette to the mapping using intrinsic transparency.
Extracts non-transparent colors from the provided palette and adds any new colors to the mapping. Wildcards and transparent colors are skipped. Colors that already exist in the mapping are also skipped. New colors are assigned sequential indices starting from the current size of the mapping.
This overload is only available for pixel types that support intrinsic transparency (e.g., IndexPixel).
| pal | The palette to extract colors from |
Definition at line 170 of file color_index_map.hpp.
|
inline |
Adds colors from a dynamic palette to the mapping using extrinsic transparency.
Extracts non-transparent colors from the provided palette and adds any new colors to the mapping. Wildcards and transparent colors are skipped. Colors that already exist in the mapping are also skipped. New colors are assigned sequential indices starting from the current size of the mapping.
This overload is only available for pixel types that support extrinsic transparency (e.g., Rgba32).
| pal | The palette to extract colors from |
| extrinsic | The extrinsic transparency value used for transparency filtering |
Definition at line 189 of file color_index_map.hpp.
|
inline |
Adds colors from a fixed-size palette to the mapping using intrinsic transparency.
Extracts non-transparent colors from the provided palette and adds any new colors to the mapping. Wildcards and transparent colors are skipped. Colors that already exist in the mapping are also skipped. New colors are assigned sequential indices starting from the current size of the mapping.
This overload is only available for pixel types that support intrinsic transparency (e.g., IndexPixel).
| pal | The palette to extract colors from |
Definition at line 133 of file color_index_map.hpp.
|
inline |
Adds colors from a fixed-size palette to the mapping using extrinsic transparency.
Extracts non-transparent colors from the provided palette and adds any new colors to the mapping. Wildcards and transparent colors are skipped. Colors that already exist in the mapping are also skipped. New colors are assigned sequential indices starting from the current size of the mapping.
This overload is only available for pixel types that support extrinsic transparency (e.g., Rgba32).
| pal | The palette to extract colors from |
| extrinsic | The extrinsic transparency value used for transparency filtering |
Definition at line 152 of file color_index_map.hpp.
|
inline |
Adds colors from a single tile to the mapping using intrinsic transparency.
Extracts unique non-transparent colors from the provided tile and adds any new colors to the mapping. Colors that already exist in the mapping are skipped. New colors are assigned sequential indices starting from the current size of the mapping.
This overload is only available for pixel types that support intrinsic transparency (e.g., IndexPixel).
| tile | The tile to extract colors from |
Definition at line 96 of file color_index_map.hpp.
|
inline |
Adds colors from a single tile to the mapping using extrinsic transparency.
Extracts unique non-transparent colors from the provided tile and adds any new colors to the mapping. Colors that already exist in the mapping are skipped. New colors are assigned sequential indices starting from the current size of the mapping.
This overload is only available for pixel types that support extrinsic transparency (e.g., Rgba32).
| tile | The tile to extract colors from |
| extrinsic | The extrinsic transparency value used for transparency filtering |
Definition at line 115 of file color_index_map.hpp.
|
inline |
Retrieves the color associated with a given index.
Performs a lookup in the index-to-color mapping to find the pixel color assigned to the specified index. If the index exists in the map, returns the associated color. If the index does not exist (was never assigned during construction), returns std::nullopt.
This method enables efficient reverse lookup: given an index, retrieve its color.
| index | The color index to lookup |
Definition at line 263 of file color_index_map.hpp.
|
inline |
Determines if the mapping is empty.
Definition at line 79 of file color_index_map.hpp.
|
inline |
Retrieves the index associated with a given color.
Performs a lookup in the color-to-index mapping to find the color index assigned to the specified pixel color. If the color exists in the map, returns the associated index. If the color does not exist (was never assigned during construction or was filtered out as transparent), returns std::nullopt.
This method enables efficient forward lookup: given a color, retrieve its index.
| color | The pixel color to lookup |
Definition at line 285 of file color_index_map.hpp.
|
inline |
Returns the number of unique colors in the mapping.
Returns the count of unique non-transparent colors that were identified during construction. This is equivalent to the size of both the color-to-index and index-to-color maps.
Definition at line 69 of file color_index_map.hpp.