32template <SupportsTransparency PixelType,
typename TransparencyPredicate>
33[[nodiscard]] ShapeTile<PixelType>
36 std::map<PixelType, ShapeMask> color_to_mask;
40 const auto pixel = pixel_tile.
at(row, col);
41 if (is_transparent_pred(pixel)) {
44 color_to_mask[pixel].set(row, col);
49 for (
const auto &[color, mask] : color_to_mask) {
50 result.
set(mask, color);
83template <SupportsTransparency PixelType>
84[[nodiscard]] std::vector<ShapeGroup<PixelType>>
92 auto shape_only_less = [](
const ShapeTile<PixelType> &a,
const ShapeTile<PixelType> &b) {
97 std::map<ShapeTile<PixelType>, std::vector<ShapeGroupMember<PixelType>>,
decltype(shape_only_less)> groups(
100 for (std::size_t i = 0; i < tiles.size(); ++i) {
102 tiles[i], [&extrinsic](
const PixelType &c) {
return c.is_transparent(extrinsic); });
105 if (shape_tile.is_transparent()) {
109 CanonicalShapeTile<PixelType>
canonical{shape_tile};
111 ShapeGroupMember<PixelType> member;
112 member.tile_index = i;
118 groups[
static_cast<const ShapeTile<PixelType> &
>(
canonical)].push_back(std::move(member));
122 std::vector<ShapeGroup<PixelType>> result;
123 for (
auto &[canonical_shape, members] : groups) {
124 if (members.size() < 2) {
129 bool has_distinct_colors =
false;
130 for (std::size_t j = 1; j < members.size(); ++j) {
131 if (members[j].colors != members[0].colors) {
132 has_distinct_colors =
true;
137 if (!has_distinct_colors) {
141 ShapeGroup<PixelType> group;
142 group.canonical_shape = canonical_shape;
143 group.members = std::move(members);
144 result.push_back(std::move(group));
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.
PixelType at(std::size_t i) const
An 8x8 tile backed by mask-based storage that maps shape regions to pixel values.
void set(const ShapeMask &mask, const PixelType &color)
Sets or updates the pixel value for a specific shape mask.
static bool compare_shape_only(const ShapeTile &lhs, const ShapeTile &rhs)
Compares two ShapeTiles based ONLY on shape masks, ignoring pixel values.
bool is_transparent() const
Checks if this entire ShapeTile is transparent.
constexpr std::size_t side_length_pix
std::vector< ShapeGroup< PixelType > > analyze_shape_groups(const std::vector< PixelTile< PixelType > > &tiles, const PixelType &extrinsic)
Analyzes a collection of pixel tiles and groups them by canonical shape for tile sharing analysis.
@ canonical
Export tiles in canonical form without applying flip transformations.
ShapeTile< PixelType > shape_tile_from_pixel_tile(const PixelTile< PixelType > &pixel_tile, TransparencyPredicate is_transparent_pred)
Converts a PixelTile to a ShapeTile by grouping pixels by color into ShapeMasks.