27[[nodiscard]]
constexpr std::pair<std::size_t, std::size_t>
index_to_row_col(std::size_t index)
71template <SupportsTransparency PixelType>
78 explicit PixelTile(std::array<PixelType, tile::size_pix>
pix) : pix_{std::move(
pix)} {}
83 explicit PixelTile(
const PixelType &fill_value) : pix_{}
85 std::fill(pix_.begin(), pix_.end(), fill_value);
98 requires requires(const PixelType &p) { p.is_transparent(); }
100 return is_transparent_impl([](
const PixelType &pixel) {
return pixel.is_transparent(); });
113 requires requires(
const PixelType &p) { p.is_transparent(p); }
115 return is_transparent_impl([&extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(extrinsic); });
138 requires requires(
const PixelType &p) { p.is_transparent(); }
140 auto pred = [](
const PixelType &pixel) {
return pixel.is_transparent(); };
141 return equals_ignoring_transparency_impl(other, pred, pred);
165 requires requires(
const PixelType &p) { p.is_transparent(p); }
167 auto pred = [&extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(extrinsic); };
168 return equals_ignoring_transparency_impl(other, pred, pred);
194 const PixelTile &other,
const PixelType &extrinsic,
const PixelType &other_extrinsic)
const
195 requires requires(
const PixelType &p) { p.is_transparent(p); }
197 return equals_ignoring_transparency_impl(
199 [&extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(extrinsic); },
200 [&other_extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(other_extrinsic); });
243 requires requires(
const PixelType &p) { p.is_transparent(p); }
246 const auto &pa = a.pix_.at(i);
247 const auto &pb = b.pix_.at(i);
248 const bool ta = pa.is_transparent(a_et);
249 const bool tb = pb.is_transparent(b_et);
254 return std::weak_ordering::less;
257 return std::weak_ordering::greater;
259 if (
const auto cmp = pa <=> pb; cmp != 0) {
263 return std::weak_ordering::equivalent;
266 [[nodiscard]] PixelType
at(std::size_t i)
const
269 panic(
"index out of bounds: " + std::to_string(i));
274 [[nodiscard]] PixelType
at(std::size_t row, std::size_t col)
const
277 panic(
"row index out of bounds: " + std::to_string(row));
280 panic(
"col index out of bounds: " + std::to_string(col));
285 void set(std::size_t i,
const PixelType &p)
288 panic(
"index out of bounds: " + std::to_string(i));
293 void set(std::size_t row, std::size_t col,
const PixelType &p)
296 panic(
"row index out of bounds: " + std::to_string(row));
299 panic(
"col index out of bounds: " + std::to_string(col));
320 flipped_tile.set(row, col,
at(src_row, src_col));
339 requires requires(const PixelType &p) { p.is_transparent(); }
341 return unique_nontransparent_colors_impl([](
const PixelType &pixel) {
return pixel.is_transparent(); });
361 requires requires(
const PixelType &p) { p.is_transparent(p); }
363 return unique_nontransparent_colors_impl(
364 [&extrinsic](
const PixelType &pixel) {
return pixel.is_transparent(extrinsic); });
367 [[nodiscard]]
const std::array<PixelType, tile::size_pix> &
pix()
const
383 template <
typename TransparencyPredicate>
384 [[nodiscard]]
bool is_transparent_impl(TransparencyPredicate is_transparent_pred)
const
386 return std::ranges::all_of(
pix(), is_transparent_pred);
404 template <
typename SelfTransparencyPredicate,
typename OtherTransparencyPredicate>
405 [[nodiscard]]
bool equals_ignoring_transparency_impl(
407 SelfTransparencyPredicate self_is_transparent_pred,
408 OtherTransparencyPredicate other_is_transparent_pred)
const
411 const auto &pixel1 = pix_.at(i);
412 const auto &pixel2 = other.pix_.at(i);
414 if (self_is_transparent_pred(pixel1) && other_is_transparent_pred(pixel2)) {
417 if (pixel1 != pixel2) {
434 template <
typename TransparencyPredicate>
435 [[nodiscard]] std::set<PixelType> unique_nontransparent_colors_impl(TransparencyPredicate is_transparent_pred)
const
437 std::set<PixelType> colors;
438 for (
const auto &pixel : pix_) {
439 if (!is_transparent_pred(pixel)) {
440 colors.insert(pixel);
446 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.