29[[nodiscard]]
constexpr std::pair<std::size_t, std::size_t>
index_to_row_col(std::size_t index)
77template <SupportsTransparency PixelType>
84 explicit PixelTile(std::array<PixelType, tile::size_pix>
pix) : pix_{std::move(
pix)} {}
91 explicit PixelTile(
const PixelType &fill_value) : pix_{}
93 std::fill(pix_.begin(), pix_.end(), fill_value);
108 requires requires(const PixelType &p) { p.is_transparent(); }
110 return is_transparent_impl([](
const PixelType &pixel) {
return pixel.is_transparent(); });
125 requires requires(
const PixelType &p) { p.is_transparent(p); }
127 return is_transparent_impl([&extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(extrinsic); });
152 requires requires(
const PixelType &p) { p.is_transparent(); }
154 auto pred = [](
const PixelType &pixel) {
return pixel.is_transparent(); };
155 return equals_ignoring_transparency_impl(other, pred, pred);
181 requires requires(
const PixelType &p) { p.is_transparent(p); }
183 auto pred = [&extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(extrinsic); };
184 return equals_ignoring_transparency_impl(other, pred, pred);
212 const PixelTile &other,
const PixelType &extrinsic,
const PixelType &other_extrinsic)
const
213 requires requires(
const PixelType &p) { p.is_transparent(p); }
215 return equals_ignoring_transparency_impl(
217 [&extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(extrinsic); },
218 [&other_extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(other_extrinsic); });
263 requires requires(
const PixelType &p) { p.is_transparent(p); }
266 const auto &pa = a.pix_.at(i);
267 const auto &pb = b.pix_.at(i);
268 const bool ta = pa.is_transparent(a_et);
269 const bool tb = pb.is_transparent(b_et);
274 return std::weak_ordering::less;
277 return std::weak_ordering::greater;
279 if (
const auto cmp = pa <=> pb; cmp != 0) {
283 return std::weak_ordering::equivalent;
286 [[nodiscard]] PixelType
at(std::size_t i)
const
289 panic(
"index out of bounds: " + std::to_string(i));
294 [[nodiscard]] PixelType
at(std::size_t row, std::size_t col)
const
297 panic(
"row index out of bounds: " + std::to_string(row));
300 panic(
"col index out of bounds: " + std::to_string(col));
305 void set(std::size_t i,
const PixelType &p)
308 panic(
"index out of bounds: " + std::to_string(i));
313 void set(std::size_t row, std::size_t col,
const PixelType &p)
316 panic(
"row index out of bounds: " + std::to_string(row));
319 panic(
"col index out of bounds: " + std::to_string(col));
342 flipped_tile.set(row, col,
at(src_row, src_col));
363 requires requires(const PixelType &p) { p.is_transparent(); }
365 return unique_nontransparent_colors_impl([](
const PixelType &pixel) {
return pixel.is_transparent(); });
387 requires requires(
const PixelType &p) { p.is_transparent(p); }
389 return unique_nontransparent_colors_impl(
390 [&extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(extrinsic); });
393 [[nodiscard]]
const std::array<PixelType, tile::size_pix> &
pix()
const
411 template <
typename TransparencyPredicate>
412 [[nodiscard]]
bool is_transparent_impl(TransparencyPredicate is_transparent_pred)
const
414 return std::ranges::all_of(
pix(), is_transparent_pred);
434 template <
typename SelfTransparencyPredicate,
typename OtherTransparencyPredicate>
435 [[nodiscard]]
bool equals_ignoring_transparency_impl(
437 SelfTransparencyPredicate self_is_transparent_pred,
438 OtherTransparencyPredicate other_is_transparent_pred)
const
441 const auto &pixel1 = pix_.at(i);
442 const auto &pixel2 = other.pix_.at(i);
444 if (self_is_transparent_pred(pixel1) && other_is_transparent_pred(pixel2)) {
447 if (pixel1 != pixel2) {
466 template <
typename TransparencyPredicate>
467 [[nodiscard]] std::set<PixelType> unique_nontransparent_colors_impl(TransparencyPredicate is_transparent_pred)
const
469 std::set<PixelType> colors;
470 for (
const auto &pixel : pix_) {
471 if (!is_transparent_pred(pixel)) {
472 colors.insert(pixel);
478 std::array<PixelType, tile::size_pix> pix_;
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.
std::set< PixelType > unique_nontransparent_colors() const
Returns the set of unique non-transparent colors present in this PixelTile (intrinsic transparency on...
auto operator<=>(const PixelTile &) const =default
virtual ~PixelTile()=default
bool equals_ignoring_transparency(const PixelTile &other, const PixelType &extrinsic, const PixelType &other_extrinsic) const
Compares this PixelTile with another, treating transparent pixels as equal, using independent extrins...
const std::array< PixelType, tile::size_pix > & pix() const
static std::weak_ordering cross_et_compare(const PixelTile &a, const PixelType &a_et, const PixelTile &b, const PixelType &b_et)
Strict weak ordering that treats transparent pixels under each side's own ET as equivalent.
bool equals_ignoring_transparency(const PixelTile &other) const
Compares this PixelTile with another, treating all transparent pixels as equal.
bool is_transparent() const
Checks if this entire PixelTile is transparent (intrinsic transparency only).
PixelTile(std::array< PixelType, tile::size_pix > pix)
PixelTile flip(bool h_flip, bool v_flip) const
Creates a flipped copy of this PixelTile.
PixelType at(std::size_t row, std::size_t col) const
bool is_transparent(const PixelType &extrinsic) const
Checks if this entire PixelTile is transparent.
PixelType at(std::size_t i) const
void set(std::size_t i, const PixelType &p)
bool equals_ignoring_transparency(const PixelTile &other, const PixelType &extrinsic) const
Compares this PixelTile with another, treating all transparent pixels as equal.
std::set< PixelType > unique_nontransparent_colors(const PixelType &extrinsic) const
Returns the set of unique non-transparent colors present in this PixelTile.
PixelTile(const PixelType &fill_value)
Constructs a PixelTile with all pixels set to a fill value.
void set(std::size_t row, std::size_t col, const PixelType &p)
constexpr std::size_t side_length_pix
constexpr std::pair< std::size_t, std::size_t > index_to_row_col(std::size_t index)
Converts a linear index to row and column coordinates.
constexpr std::size_t row_col_to_index(std::size_t row, std::size_t col)
Converts row and column coordinates to a linear index.
constexpr std::size_t size_pix
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.