Porytiles
Loading...
Searching...
No Matches
porytiles::Image< PixelType > Class Template Reference

A template for two-dimensional images with arbitrarily typed pixel values. More...

#include <image.hpp>

Public Member Functions

 Image ()
 
 Image (std::size_t width, std::size_t height)
 
 Image (std::size_t width, std::size_t height, std::vector< Rgba32 > palette)
 
 Image (std::size_t width, std::size_t height, PixelType fill_color)
 Constructs an image with all pixels set to a specified fill value.
 
PixelType at (std::size_t i) const
 Fetches the pixel value at a given one-dimensional pixel index.
 
PixelType at (std::size_t row, std::size_t col) const
 Fetches the pixel value at a given row and column.
 
void set (std::size_t i, PixelType pixel)
 Sets the pixel value at a given one-dimensional pixel index.
 
void set (std::size_t row, std::size_t col, PixelType pixel)
 Sets the pixel value at a given row and column.
 
std::size_t width () const
 
std::size_t height () const
 
std::size_t size () const
 
std::size_t size_in_tiles () const
 Gets the number of 8x8 tile regions in this image.
 
const std::optional< std::vector< Rgba32 > > & palette () const
 
void palette (std::vector< Rgba32 > pal)
 

Detailed Description

template<typename PixelType>
class porytiles::Image< PixelType >

A template for two-dimensional images with arbitrarily typed pixel values.

Clients who need to operate on images can use this class to read image data and manipulate image contents. This value type makes no assumptions about the underlying image storage format. Image provides an optional palette field for images which want to store an IndexPixel pixel type into a fixed palette of colors.

Template Parameters
PixelTypeThe pixel type for this Image

Definition at line 23 of file image.hpp.

Constructor & Destructor Documentation

◆ Image() [1/4]

template<typename PixelType >
porytiles::Image< PixelType >::Image ( )
inline

Definition at line 25 of file image.hpp.

◆ Image() [2/4]

template<typename PixelType >
porytiles::Image< PixelType >::Image ( std::size_t  width,
std::size_t  height 
)
inline

Definition at line 27 of file image.hpp.

◆ Image() [3/4]

template<typename PixelType >
porytiles::Image< PixelType >::Image ( std::size_t  width,
std::size_t  height,
std::vector< Rgba32 palette 
)
inline

Definition at line 29 of file image.hpp.

◆ Image() [4/4]

template<typename PixelType >
porytiles::Image< PixelType >::Image ( std::size_t  width,
std::size_t  height,
PixelType  fill_color 
)
inline

Constructs an image with all pixels set to a specified fill value.

Parameters
widthThe width of the image in pixels.
heightThe height of the image in pixels.
fill_colorThe pixel value to fill the entire image with.

Definition at line 41 of file image.hpp.

Member Function Documentation

◆ at() [1/2]

template<typename PixelType >
PixelType porytiles::Image< PixelType >::at ( std::size_t  i) const
inline

Fetches the pixel value at a given one-dimensional pixel index.

The one-dimensional index assumes the image as an array of pixels, where the length of the array is the image's width times height.

Parameters
iThe one-dimensional pixel index.
Returns
The pixel value at the given pixel index.

Definition at line 56 of file image.hpp.

◆ at() [2/2]

template<typename PixelType >
PixelType porytiles::Image< PixelType >::at ( std::size_t  row,
std::size_t  col 
) const
inline

Fetches the pixel value at a given row and column.

Parameters
rowThe pixel row.
colThe pixel column.
Returns
The pixel value at the given row and column.

Definition at line 71 of file image.hpp.

◆ height()

template<typename PixelType >
std::size_t porytiles::Image< PixelType >::height ( ) const
inline

Definition at line 119 of file image.hpp.

◆ palette() [1/2]

template<typename PixelType >
const std::optional< std::vector< Rgba32 > > & porytiles::Image< PixelType >::palette ( ) const
inline

Definition at line 150 of file image.hpp.

◆ palette() [2/2]

template<typename PixelType >
void porytiles::Image< PixelType >::palette ( std::vector< Rgba32 pal)
inline

Definition at line 155 of file image.hpp.

◆ set() [1/2]

template<typename PixelType >
void porytiles::Image< PixelType >::set ( std::size_t  i,
PixelType  pixel 
)
inline

Sets the pixel value at a given one-dimensional pixel index.

Parameters
iThe one-dimensional pixel index.
pixelThe pixel value to set at the given pixel index.

Definition at line 88 of file image.hpp.

◆ set() [2/2]

template<typename PixelType >
void porytiles::Image< PixelType >::set ( std::size_t  row,
std::size_t  col,
PixelType  pixel 
)
inline

Sets the pixel value at a given row and column.

Parameters
rowThe pixel row.
colThe pixel column.
pixelThe pixel value to set at the given pixel row and column.

Definition at line 103 of file image.hpp.

◆ size()

template<typename PixelType >
std::size_t porytiles::Image< PixelType >::size ( ) const
inline

Definition at line 124 of file image.hpp.

◆ size_in_tiles()

template<typename PixelType >
std::size_t porytiles::Image< PixelType >::size_in_tiles ( ) const
inline

Gets the number of 8x8 tile regions in this image.

GBA tiles are 8x8 pixels. This method calculates how many such tile regions fit in the image.

Precondition
Image width must be divisible by 8.
Image height must be divisible by 8.
Returns
The number of 8x8 tile regions in this image.

Definition at line 139 of file image.hpp.

◆ width()

template<typename PixelType >
std::size_t porytiles::Image< PixelType >::width ( ) const
inline

Definition at line 114 of file image.hpp.


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