32template <SupportsTransparency PixelType,
typename TransparencyPredicate>
36 TransparencyPredicate is_transparent_pred)
39 std::map<ColorIndex, ShapeMask> index_to_mask;
44 const auto pixel = pixel_tile.
at(row, col);
47 if (is_transparent_pred(pixel)) {
54 panic(
"Pixel not found in ColorIndexMap");
60 if (index_to_mask.find(index) == index_to_mask.end()) {
65 index_to_mask[index].
set(row, col);
71 for (
const auto &[index, mask] : index_to_mask) {
72 result.
set(mask, index);
104template <SupportsTransparency PixelType>
105[[nodiscard]] ShapeTile<ColorIndex>
110 pixel_tile, color_index_map, [](
const PixelType &p) {
return p.is_transparent(); });
139template <SupportsTransparency PixelType>
145 pixel_tile, color_index_map, [&extrinsic](
const PixelType &p) {
return p.is_transparent(extrinsic); });
171template <SupportsTransparency PixelType>
172[[nodiscard]] PixelTile<PixelType>
179 std::array<bool, tile::size_pix> pixel_set{};
182 for (
const auto &[mask, index] : shape_tile.
colors()) {
186 panic(
"ColorIndex not found in ColorIndexMap");
189 const PixelType &color = *color_opt;
194 if (mask.get(row, col)) {
198 if (pixel_set[pixel_index]) {
199 panic(
"Overlapping masks detected in ShapeTile - programmer error");
202 result.
set(row, col, color);
203 pixel_set[pixel_index] =
true;
234template <SupportsTransparency PixelType>
235[[nodiscard]] ShapeTile<PixelType>
241 for (
const auto &[mask, index] : shape_tile.
colors()) {
245 panic(
"ColorIndex not found in ColorIndexMap");
248 const PixelType &color = *color_opt;
251 result.
set(mask, color);
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.
Represents a color index value for palette operations.
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.
void set(std::size_t i, const PixelType &p)
PixelType at(std::size_t i) const
Represents which pixels in an 8x8 tile are non-transparent.
void set(int row, int col)
Sets the bit at the specified row and column to 1.
An 8x8 tile backed by mask-based storage that maps shape regions to pixel values.
const std::map< ShapeMask, PixelType > & colors() const
Returns the internal map of shape masks to pixel values.
bool is_transparent() const
Checks if this entire ShapeTile is transparent.
void set(const ShapeMask &mask, const PixelType &color)
Sets or updates the pixel value for a specific shape mask.
ShapeTile< ColorIndex > from_pixel_tile_impl(const PixelTile< PixelType > &pixel_tile, const ColorIndexMap< PixelType > &color_index_map, TransparencyPredicate is_transparent_pred)
Helper function implementing the core PixelTile to ShapeTile conversion logic.
constexpr std::size_t side_length_pix
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
PixelTile< PixelType > from_shape_tile(const ShapeTile< ColorIndex > &shape_tile, const ColorIndexMap< PixelType > &color_index_map)
Converts a ShapeTile<ColorIndex> to a PixelTile using a ColorIndexMap.
ShapeTile< ColorIndex > from_pixel_tile(const PixelTile< PixelType > &pixel_tile, const ColorIndexMap< PixelType > &color_index_map)
Converts a PixelTile to a ShapeTile<ColorIndex> using a ColorIndexMap (intrinsic transparency).
ShapeTile< PixelType > shape_tile_to_pixel_colors(const ShapeTile< ColorIndex > &shape_tile, const ColorIndexMap< PixelType > &color_index_map)
Converts a ShapeTile<ColorIndex> to a ShapeTile<PixelType> using a ColorIndexMap.