57template <SupportsTransparency PixelType>
82 requires requires(
const PixelType &p) { p.is_transparent(); }
109 requires requires(
const PixelType &p) { p.is_transparent(p); }
125 [[nodiscard]] std::size_t
size()
const
127 return index_map_.size();
155 auto it = color_map_.find(index);
156 if (it != color_map_.end()) {
175 [[nodiscard]] std::optional<ColorIndex>
index_at_color(
const PixelType &color)
const
177 auto it = index_map_.find(color);
178 if (it != index_map_.end()) {
197 template <
typename ColorExtractor>
198 void constructor_impl(
const std::vector<
PixelTile<PixelType>> &tiles, ColorExtractor extract_colors)
200 std::map<PixelType, ColorIndex> pixel_indexes{};
201 std::map<ColorIndex, PixelType> index_to_color{};
203 unsigned int color_index = 0;
204 for (
const auto &tile : tiles) {
205 for (
const auto &pixel : extract_colors(tile)) {
206 if (pixel_indexes.insert({pixel, ColorIndex{color_index}}).second) {
207 index_to_color.insert({ColorIndex{color_index}, pixel});
213 index_map_ = pixel_indexes;
214 color_map_ = index_to_color;
217 std::map<PixelType, ColorIndex> index_map_;
218 std::map<ColorIndex, PixelType> color_map_;
A bidirectional mapping between pixel color values and sequential integer indices.
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.
std::size_t size() const
Returns the number of unique colors in the mapping.
ColorIndexMap(const std::vector< PixelTile< PixelType > > &tiles, const PixelType &extrinsic)
Constructs a ColorIndexMap from a collection of tiles and an extrinsic transparency value.
ColorIndexMap(const std::vector< PixelTile< PixelType > > &tiles)
Constructs a ColorIndexMap from a collection of tiles using intrinsic transparency.
bool empty() const
Determines if the mapping is empty.
Represents a color index value for palette operations.
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.
std::set< PixelType > unique_nontransparent_colors() const
Returns the set of unique non-transparent colors present in this PixelTile (intrinsic transparency on...