|
Porytiles
|
A bidirectional mapping between pixel color values and sequential integer indices. More...
#include <color_index_map.hpp>
Public Member Functions | |
| ColorIndexMap ()=default | |
| ColorIndexMap (const std::vector< PixelTile< PixelType > > &tiles) | |
| Constructs a ColorIndexMap from a collection of tiles using intrinsic transparency. | |
| ColorIndexMap (const std::vector< PixelTile< PixelType > > &tiles, const PixelType &extrinsic) | |
| Constructs a ColorIndexMap from a collection of tiles and an extrinsic transparency value. | |
| std::size_t | size () const |
| Returns the number of unique colors in the mapping. | |
| bool | empty () const |
| Determines if the mapping is empty. | |
| 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.
Key features:
| PixelType | The pixel color type, must satisfy SupportsTransparency concept |
Example usage:
Definition at line 58 of file color_index_map.hpp.
|
default |
|
inline |
Constructs a ColorIndexMap from a collection of tiles using intrinsic transparency.
This constructor analyzes all provided tiles to identify unique non-transparent colors and assigns each a sequential integer index starting from 0. The process:
This overload is only available for pixel types that support intrinsic transparency (e.g., IndexPixel).
The order of index assignment depends on the order in which colors are encountered during tile iteration.
| tiles | A vector of tiles with the specified pixel type to analyze for unique colors |
Definition at line 81 of file color_index_map.hpp.
|
inline |
Constructs a ColorIndexMap from a collection of tiles and an extrinsic transparency value.
This constructor analyzes all provided tiles to identify unique non-transparent colors and assigns each a sequential integer index starting from 0. The process:
This overload is only available for pixel types that support extrinsic transparency (e.g., Rgba32).
The order of index assignment depends on the order in which colors are encountered during tile iteration.
| tiles | A vector of tiles with the specified pixel type to analyze for unique colors |
| extrinsic | The extrinsic transparency value used for transparency filtering |
Definition at line 108 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 153 of file color_index_map.hpp.
|
inline |
Determines if the mapping is empty.
Definition at line 135 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 175 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 125 of file color_index_map.hpp.