55template <SupportsTransparency PixelType>
69 [[nodiscard]] std::size_t
size()
const
71 return index_map_.size();
79 [[nodiscard]]
bool empty()
const
97 requires requires(
const PixelType &p) { p.is_transparent(); }
99 add_colors_impl(tile.unique_nontransparent_colors());
116 requires requires(
const PixelType &p) { p.is_transparent(p); }
118 add_colors_impl(tile.unique_nontransparent_colors(extrinsic));
134 requires requires(
const PixelType &p) { p.is_transparent(); }
136 add_colors_from_pal_impl(pal, [](
const PixelType &p) {
return p.is_transparent(); });
153 requires requires(
const PixelType &p) { p.is_transparent(p); }
155 add_colors_from_pal_impl(pal, [&extrinsic](
const PixelType &p) {
return p.is_transparent(extrinsic); });
171 requires requires(
const PixelType &p) { p.is_transparent(); }
173 add_colors_from_pal_impl(pal, [](
const PixelType &p) {
return p.is_transparent(); });
190 requires requires(
const PixelType &p) { p.is_transparent(p); }
192 add_colors_from_pal_impl(pal, [&extrinsic](
const PixelType &p) {
return p.is_transparent(extrinsic); });
208 requires requires(
const PixelType &p) { p.is_transparent(); }
210 if (anim.has_key_frame()) {
211 for (
const auto &tile : anim.key_frame().tiles()) {
215 for (
const auto &[name, frame] : anim.frames()) {
216 for (
const auto &tile : frame.tiles()) {
236 requires requires(
const PixelType &p) { p.is_transparent(p); }
238 if (anim.has_key_frame()) {
239 for (
const auto &tile : anim.key_frame().tiles()) {
243 for (
const auto &[name, frame] : anim.frames()) {
244 for (
const auto &tile : frame.tiles()) {
265 auto it = color_map_.find(index);
266 if (it != color_map_.end()) {
285 [[nodiscard]] std::optional<ColorIndex>
index_at_color(
const PixelType &color)
const
287 auto it = index_map_.find(color);
288 if (it != index_map_.end()) {
304 void add_colors_impl(
const std::set<PixelType> &colors)
306 auto color_index =
size();
307 for (
const auto &pixel : colors) {
308 if (index_map_.insert({pixel, ColorIndex{color_index}}).second) {
309 color_map_.insert({ColorIndex{color_index}, pixel});
327 template <std::
size_t N,
typename TransparencyPredicate>
328 void add_colors_from_pal_impl(
const Palette<PixelType, N> &pal, TransparencyPredicate is_transparent_pred)
330 auto color_index = size();
331 for (std::size_t i = 0; i < pal.size(); i++) {
332 auto color_opt = pal.at_optional(i);
333 if (!color_opt.has_value()) {
336 const auto &color = color_opt.value();
337 if (is_transparent_pred(color)) {
340 if (index_map_.insert({color, ColorIndex{color_index}}).second) {
341 color_map_.insert({ColorIndex{color_index}, color});
347 std::map<PixelType, ColorIndex> index_map_;
348 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_pal(const Palette< PixelType > &pal, const PixelType &extrinsic)
Adds colors from a dynamic 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.
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.
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_pal(const Palette< PixelType > &pal)
Adds colors from a dynamic palette to the mapping using intrinsic 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_pal(const Palette< PixelType, pal::max_size > &pal)
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.
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.