30template <SupportsTransparency PixelType,
typename TransparencyPredicate>
31[[nodiscard]] ShapeTile<PixelType>
34 std::map<PixelType, ShapeMask> color_to_mask;
38 const auto pixel = pixel_tile.
at(row, col);
39 if (is_transparent_pred(pixel)) {
42 color_to_mask[pixel].set(row, col);
47 for (
const auto &[color, mask] : color_to_mask) {
48 result.
set(mask, color);
79template <SupportsTransparency PixelType>
80[[nodiscard]] std::vector<ShapeGroup<PixelType>>
86 auto shape_only_less = [](
const ShapeTile<PixelType> &a,
const ShapeTile<PixelType> &b) {
91 std::map<ShapeTile<PixelType>, std::vector<ShapeGroupMember<PixelType>>,
decltype(shape_only_less)> groups(
94 for (std::size_t i = 0; i < tiles.size(); ++i) {
96 tiles[i], [&extrinsic](
const PixelType &c) {
return c.is_transparent(extrinsic); });
99 if (shape_tile.is_transparent()) {
103 CanonicalShapeTile<PixelType>
canonical{shape_tile};
105 ShapeGroupMember<PixelType> member;
106 member.tile_index = i;
112 groups[
static_cast<const ShapeTile<PixelType> &
>(
canonical)].push_back(std::move(member));
116 std::vector<ShapeGroup<PixelType>> result;
117 for (
auto &[canonical_shape, members] : groups) {
118 if (members.size() < 2) {
123 bool has_distinct_colors =
false;
124 for (std::size_t j = 1; j < members.size(); ++j) {
125 if (members[j].colors != members[0].colors) {
126 has_distinct_colors =
true;
131 if (!has_distinct_colors) {
135 ShapeGroup<PixelType> group;
136 group.canonical_shape = canonical_shape;
137 group.members = std::move(members);
138 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.