Porytiles
Loading...
Searching...
No Matches
porytiles2::PixelTile< PixelType > Class Template Reference

An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type. More...

#include <pixel_tile.hpp>

Inheritance diagram for porytiles2::PixelTile< PixelType >:
[legend]

Public Member Functions

virtual ~PixelTile ()=default
 
 PixelTile ()
 
 PixelTile (std::array< PixelType, tile::size_pix > pix)
 
auto operator<=> (const PixelTile &) const =default
 
bool is_transparent () const
 Checks if this entire PixelTile is transparent (intrinsic transparency only).
 
bool is_transparent (const PixelType &extrinsic) const
 Checks if this entire PixelTile is transparent.
 
bool equals_ignoring_transparency (const PixelTile &other) const
 Compares this PixelTile with another, treating all transparent pixels as equal.
 
bool equals_ignoring_transparency (const PixelTile &other, const PixelType &extrinsic) const
 Compares this PixelTile with another, treating all transparent pixels as equal.
 
PixelType at (std::size_t i) const
 
PixelType at (std::size_t row, std::size_t col) const
 
void set (std::size_t i, const PixelType &p)
 
void set (std::size_t row, std::size_t col, const PixelType &p)
 
PixelTile flip (bool h_flip, bool v_flip) const
 Creates a flipped copy of this PixelTile.
 
std::set< PixelType > unique_nontransparent_colors () const
 Returns the set of unique non-transparent colors present in this PixelTile (intrinsic transparency only).
 
std::set< PixelType > unique_nontransparent_colors (const PixelType &extrinsic) const
 Returns the set of unique non-transparent colors present in this PixelTile.
 
const std::array< PixelType, tile::size_pix > & pix () const
 

Detailed Description

template<SupportsTransparency PixelType>
class porytiles2::PixelTile< PixelType >

An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.

PixelTile represents tiles using direct per-pixel storage in a 64-element array (8x8 grid). Each pixel position in the tile explicitly stores a PixelType value, providing a straightforward one-to-one mapping between tile coordinates and pixel data. This contrasts with ShapeTile, which uses a mask-based representation that maps shape regions to pixel values.

This representation is ideal for:

  • Direct pixel-level manipulation and access operations
  • Simple tile transformations like flipping that operate on individual pixels
  • Straightforward conversion from image data formats

The PixelType template parameter must satisfy the SupportsTransparency concept, meaning it must provide methods for checking whether a pixel is transparent. This enables transparency checking at both the intrinsic level (for pixel types like IndexPixel that have built-in transparency) and extrinsic level (for pixel types like Rgba32 where transparency is determined by comparison with a reference value).

Key features:

  • Direct indexed access via at() methods supporting both linear and 2D coordinate access
  • Boundary-checked access with panic on out-of-bounds indices
  • Flipping operations that create new tiles with transformed pixel positions
  • Transparency checking with overloads for both intrinsic and extrinsic transparency
  • Full equality and comparison support via defaulted spaceship operator
Invariant
Default-constructed PixelTile is transparent (satisfies SupportsTransparency design invariant). That is, PixelTile<PixelType>{} produces a tile where all pixels are default-constructed (and thus transparent, assuming PixelType itself satisfies the invariant).
Template Parameters
PixelTypeThe pixel type of this tile; must satisfy SupportsTransparency concept

Definition at line 83 of file pixel_tile.hpp.

Constructor & Destructor Documentation

◆ ~PixelTile()

template<SupportsTransparency PixelType>
virtual porytiles2::PixelTile< PixelType >::~PixelTile ( )
virtualdefault

◆ PixelTile() [1/2]

template<SupportsTransparency PixelType>
porytiles2::PixelTile< PixelType >::PixelTile ( )
inline

Definition at line 87 of file pixel_tile.hpp.

◆ PixelTile() [2/2]

template<SupportsTransparency PixelType>
porytiles2::PixelTile< PixelType >::PixelTile ( std::array< PixelType, tile::size_pix pix)
inlineexplicit

Definition at line 89 of file pixel_tile.hpp.

Member Function Documentation

◆ at() [1/2]

template<SupportsTransparency PixelType>
PixelType porytiles2::PixelTile< PixelType >::at ( std::size_t  i) const
inline

Definition at line 181 of file pixel_tile.hpp.

◆ at() [2/2]

template<SupportsTransparency PixelType>
PixelType porytiles2::PixelTile< PixelType >::at ( std::size_t  row,
std::size_t  col 
) const
inline

Definition at line 189 of file pixel_tile.hpp.

◆ equals_ignoring_transparency() [1/2]

template<SupportsTransparency PixelType>
bool porytiles2::PixelTile< PixelType >::equals_ignoring_transparency ( const PixelTile< PixelType > &  other) const
inline

Compares this PixelTile with another, treating all transparent pixels as equal.

This method provides a semantic equality comparison that differs from operator== in that it considers all transparent pixels to be equal, regardless of their underlying representation. Two pixels are considered equal if:

  • Both are transparent (via intrinsic is_transparent()), OR
  • Neither is transparent and they compare equal via operator==

This is useful when comparing tiles where only the logical transparency state matters, not the specific pixel values. The practical application depends on the pixel type's transparency semantics. For IndexPixel, since only index 0 is intrinsically transparent, this method behaves like operator== in typical usage. However, for pixel types with more complex intrinsic transparency (e.g., hypothetical future types supporting multiple transparent representations), this method would treat all such representations as equal.

This overload is only available for pixel types that support intrinsic transparency (e.g., IndexPixel).

Parameters
otherThe PixelTile to compare against
Returns
True if the tiles are equivalent under transparency-ignoring semantics, false otherwise

Definition at line 146 of file pixel_tile.hpp.

◆ equals_ignoring_transparency() [2/2]

template<SupportsTransparency PixelType>
bool porytiles2::PixelTile< PixelType >::equals_ignoring_transparency ( const PixelTile< PixelType > &  other,
const PixelType &  extrinsic 
) const
inline

Compares this PixelTile with another, treating all transparent pixels as equal.

This method provides a semantic equality comparison that differs from operator== in that it considers all transparent pixels to be equal, regardless of their underlying representation. Two pixels are considered equal if:

  • Both are transparent (via extrinsic is_transparent(extrinsic)), OR
  • Neither is transparent and they compare equal via operator==

This is useful when comparing tiles where the specific representation of transparent pixels doesn't matter, only the logical transparency state. For example, a tile with Rgba32{255,0,255} (magenta, considered extrinsically transparent under default settings) and another with Rgba32{0,0,0,0} (black with alpha=0, also transparent) would be considered equal at those positions when using the appropriate extrinsic transparency value.

This overload is only available for pixel types that support extrinsic transparency (e.g., Rgba32).

Parameters
otherThe PixelTile to compare against
extrinsicThe extrinsic transparency value to use when checking pixel transparency
Returns
True if the tiles are equivalent under transparency-ignoring semantics, false otherwise

Definition at line 174 of file pixel_tile.hpp.

◆ flip()

template<SupportsTransparency PixelType>
PixelTile porytiles2::PixelTile< PixelType >::flip ( bool  h_flip,
bool  v_flip 
) const
inline

Creates a flipped copy of this PixelTile.

Returns a new PixelTile flipped according to the specified parameters. Horizontal flip reflects the tile across a vertical axis, vertical flip reflects across a horizontal axis.

Parameters
h_flipWhether to flip horizontally
v_flipWhether to flip vertically
Returns
A new PixelTile with the specified flips applied

Definition at line 230 of file pixel_tile.hpp.

◆ is_transparent() [1/2]

template<SupportsTransparency PixelType>
bool porytiles2::PixelTile< PixelType >::is_transparent ( ) const
inline

Checks if this entire PixelTile is transparent (intrinsic transparency only).

A PixelTile is transparent if all of its pixels are intrinsically transparent. This overload is only available for pixel types that support parameterless is_transparent() (e.g., IndexPixel).

Returns
True if all pixels in the PixelTile are transparent, false otherwise

Definition at line 102 of file pixel_tile.hpp.

◆ is_transparent() [2/2]

template<SupportsTransparency PixelType>
bool porytiles2::PixelTile< PixelType >::is_transparent ( const PixelType &  extrinsic) const
inline

Checks if this entire PixelTile is transparent.

A PixelTile is transparent if all of its pixels are either intrinsically or extrinsically transparent, according to the provided extrinsic transparency value. This overload is only available for pixel types that support extrinsic transparency (e.g., Rgba32).

Parameters
extrinsicThe extrinsic transparency value to check each pixel against
Returns
True if all pixels in the PixelTile are transparent, false otherwise

Definition at line 119 of file pixel_tile.hpp.

◆ operator<=>()

template<SupportsTransparency PixelType>
auto porytiles2::PixelTile< PixelType >::operator<=> ( const PixelTile< PixelType > &  ) const
default

◆ pix()

template<SupportsTransparency PixelType>
const std::array< PixelType, tile::size_pix > & porytiles2::PixelTile< PixelType >::pix ( ) const
inline

Definition at line 288 of file pixel_tile.hpp.

◆ set() [1/2]

template<SupportsTransparency PixelType>
void porytiles2::PixelTile< PixelType >::set ( std::size_t  i,
const PixelType &  p 
)
inline

Definition at line 200 of file pixel_tile.hpp.

◆ set() [2/2]

template<SupportsTransparency PixelType>
void porytiles2::PixelTile< PixelType >::set ( std::size_t  row,
std::size_t  col,
const PixelType &  p 
)
inline

Definition at line 208 of file pixel_tile.hpp.

◆ unique_nontransparent_colors() [1/2]

template<SupportsTransparency PixelType>
std::set< PixelType > porytiles2::PixelTile< PixelType >::unique_nontransparent_colors ( ) const
inline

Returns the set of unique non-transparent colors present in this PixelTile (intrinsic transparency only).

This method constructs and returns a std::set containing all unique non-transparent PixelType values found in the tile. Pixels are filtered using their intrinsic transparency (via parameterless is_transparent()), and only non-transparent pixels are included in the result. The set automatically handles uniqueness, so duplicate pixel values will only appear once.

This overload is only available for pixel types that support intrinsic transparency (e.g., IndexPixel). For IndexPixel tiles, this means index 0 (intrinsically transparent) will be excluded from the returned set.

Returns
A std::set containing all unique non-transparent pixel values in this tile

Definition at line 257 of file pixel_tile.hpp.

◆ unique_nontransparent_colors() [2/2]

template<SupportsTransparency PixelType>
std::set< PixelType > porytiles2::PixelTile< PixelType >::unique_nontransparent_colors ( const PixelType &  extrinsic) const
inline

Returns the set of unique non-transparent colors present in this PixelTile.

This method constructs and returns a std::set containing all unique non-transparent PixelType values found in the tile. Pixels are filtered using both intrinsic and extrinsic transparency (via is_transparent(extrinsic)), and only non-transparent pixels are included in the result. The set automatically handles uniqueness, so duplicate pixel values will only appear once.

This overload is only available for pixel types that support extrinsic transparency (e.g., Rgba32). For Rgba32 tiles:

  • Pixels with alpha=0 (intrinsically transparent) are excluded
  • Pixels matching the extrinsic transparency value (e.g., magenta) are excluded
  • Only opaque, non-transparent pixels are included in the result
Parameters
extrinsicThe extrinsic transparency value to check each pixel against
Returns
A std::set containing all unique non-transparent pixel values in this tile

Definition at line 281 of file pixel_tile.hpp.


The documentation for this class was generated from the following file: