53template <SupportsTransparency PixelType>
65 [[nodiscard]] std::size_t
size()
const
67 return index_map_.size();
73 [[nodiscard]]
bool empty()
const
89 requires requires(
const PixelType &p) { p.is_transparent(); }
91 add_colors_impl(tile.unique_nontransparent_colors());
106 requires requires(
const PixelType &p) { p.is_transparent(p); }
108 add_colors_impl(tile.unique_nontransparent_colors(extrinsic));
122 requires requires(
const PixelType &p) { p.is_transparent(); }
124 add_colors_from_palette_impl(palette, [](
const PixelType &p) {
return p.is_transparent(); });
139 requires requires(
const PixelType &p) { p.is_transparent(p); }
141 add_colors_from_palette_impl(palette, [&extrinsic](
const PixelType &p) {
return p.is_transparent(extrinsic); });
155 requires requires(
const PixelType &p) { p.is_transparent(); }
157 add_colors_from_palette_impl(palette, [](
const PixelType &p) {
return p.is_transparent(); });
172 requires requires(
const PixelType &p) { p.is_transparent(p); }
174 add_colors_from_palette_impl(palette, [&extrinsic](
const PixelType &p) {
return p.is_transparent(extrinsic); });
188 requires requires(
const PixelType &p) { p.is_transparent(); }
190 if (anim.has_key_frame()) {
191 for (
const auto &tile : anim.key_frame().tiles()) {
195 for (
const auto &[
name, frame] : anim.frames()) {
196 for (
const auto &tile : frame.tiles()) {
214 requires requires(
const PixelType &p) { p.is_transparent(p); }
216 if (anim.has_key_frame()) {
217 for (
const auto &tile : anim.key_frame().tiles()) {
221 for (
const auto &[
name, frame] : anim.frames()) {
222 for (
const auto &tile : frame.tiles()) {
241 auto it = color_map_.find(index);
242 if (it != color_map_.end()) {
259 [[nodiscard]] std::optional<ColorIndex>
index_at_color(
const PixelType &color)
const
261 auto it = index_map_.find(color);
262 if (it != index_map_.end()) {
276 void add_colors_impl(
const std::set<PixelType> &colors)
278 auto color_index =
size();
279 for (
const auto &pixel : colors) {
280 if (index_map_.insert({pixel, ColorIndex{color_index}}).second) {
281 color_map_.insert({ColorIndex{color_index}, pixel});
297 template <std::
size_t N,
typename TransparencyPredicate>
298 void add_colors_from_palette_impl(
const Palette<PixelType, N> &palette, TransparencyPredicate is_transparent_pred)
300 auto color_index = size();
301 for (std::size_t i = 0; i < palette.size(); i++) {
302 auto color_opt = palette.at_optional(i);
303 if (!color_opt.has_value()) {
306 const auto &color = color_opt.value();
307 if (is_transparent_pred(color)) {
310 if (index_map_.insert({color, ColorIndex{color_index}}).second) {
311 color_map_.insert({ColorIndex{color_index}, color});
317 std::map<PixelType, ColorIndex> index_map_;
318 std::map<ColorIndex, PixelType> color_map_;
A complete tileset animation with name, configuration, and frame data.
A bidirectional mapping between pixel color values and sequential integer indices.
std::size_t size() const
Returns the number of unique colors in the mapping.
void add_palette(const Palette< PixelType, palette::max_size > &palette, const PixelType &extrinsic)
Adds colors from a fixed-size palette to the mapping using extrinsic transparency.
void add_tile(const PixelTile< PixelType > &tile)
Adds colors from a single tile to the mapping using intrinsic transparency.
std::optional< ColorIndex > index_at_color(const PixelType &color) const
Retrieves the index associated with a given color.
void add_anim(const Animation< PixelType > &anim, const PixelType &extrinsic)
Adds colors from an animation to the mapping using extrinsic 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_palette(const Palette< PixelType > &palette, const PixelType &extrinsic)
Adds colors from a dynamic palette to the mapping using extrinsic transparency.
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.
void add_palette(const Palette< PixelType, palette::max_size > &palette)
Adds colors from a fixed-size palette to the mapping using intrinsic transparency.
void add_anim(const Animation< PixelType > &anim)
Adds colors from an animation to the mapping using intrinsic transparency.
void add_palette(const Palette< PixelType > &palette)
Adds colors from a dynamic palette to the mapping using intrinsic transparency.
Represents a color index value for palette operations.
A generic palette container for colors that support transparency checking.
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.