Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
WorldStone::ImageView< Color > Struct Template Reference

A view on an image buffer of type Color. More...

#include <ImageView.h>

Public Member Functions

 ImageView (Color *_buffer, size_t _width, size_t _height, size_t _stride)
 
bool isValid () const
 Checks if the view seems to be valid based on its characteristics.
 
bool operator== (const ImageView &rhs) const
 
bool operator!= (const ImageView &rhs) const
 
 operator ImageView< const Color > () const
 Enable conversion from ImageView<Color> to ImageView<const Color>
 
ImageView subView (size_t xOffset, size_t yOffset, size_t subWidth, size_t subHeight) const
 Create an ImageView that is contained by the current view. More...
 
Color & operator() (size_t x, size_t y) const
 Access the pixel at the given coordinates. More...
 
void copyTo (ImageView destination) const
 Copy (blits) the content of an image to another. More...
 
void fill (size_t x, size_t y, size_t columns, size_t rows, Color colorValue)
 Fills a part of the image. More...
 
void fillBytes (size_t x, size_t y, size_t columns, size_t rows, uint8_t byteValue)
 Fills a part of the image using a byte pattern. More...
 

Public Attributes

Color * buffer = nullptr
 Pointer to the memory considered as the first pixel.
 
size_t width = 0
 Width of the image, can be dfferent from the one of the buffer.
 
size_t height = 0
 Number of scanlines of the image.
 
size_t stride = 0
 Actual width of the buffer scanlines.
 

Detailed Description

template<class Color>
struct WorldStone::ImageView< Color >

A view on an image buffer of type Color.

This class can be used to access a buffer of the Color type as if it was an image. It should be small enough so that you can directly copy the view instead of passing it by reference. Note that this class does not do bounds checking, and the user is the one responsible for handling the data correctly. A good way to abstract an image allocator could be to implement an IImageProvider, which returns an ImageView.

Note
Unlike the usage of the term 'view' in the standard, such as in std::string_view, an ImageView maps on a mutable buffer unless the template parameter is const. What this means is that a gsl::span is the equivalent of ImageView<uint8_t> while a std::view would be ImageView<const uint8_t> for example.

Definition at line 25 of file ImageView.h.

Member Function Documentation

template<class Color>
void WorldStone::ImageView< Color >::copyTo ( ImageView< Color >  destination) const
inline

Copy (blits) the content of an image to another.

If the current view and destination memory overlap, result is undefined.

Warning
No bounds checking done.

Definition at line 78 of file ImageView.h.

template<class Color>
void WorldStone::ImageView< Color >::fill ( size_t  x,
size_t  y,
size_t  columns,
size_t  rows,
Color  colorValue 
)
inline

Fills a part of the image.

Parameters
xFirst column to fill
yFirst row to fill
columnsNumber of pixels to fill per scanline
rowsNumber of scanlines to fill
colorValueThe value to set every byte of the pixels to
See Also
fillBytes for a faster version when all the bytes have the same value

Definition at line 95 of file ImageView.h.

template<class Color>
void WorldStone::ImageView< Color >::fillBytes ( size_t  x,
size_t  y,
size_t  columns,
size_t  rows,
uint8_t  byteValue 
)
inline

Fills a part of the image using a byte pattern.

Parameters
xFirst column to fill
yFirst row to fill
columnsNumber of pixels to fill per scanline
rowsNumber of scanlines to fill
byteValueThe value to set every byte of the pixels to

Definition at line 115 of file ImageView.h.

template<class Color>
Color& WorldStone::ImageView< Color >::operator() ( size_t  x,
size_t  y 
) const
inline

Access the pixel at the given coordinates.

Returns
A reference to the pixel of coordinates (x,y)
Warning
This function does not perform any bounds checking, the only valid inputs verify
x < width && y < height

Definition at line 72 of file ImageView.h.

template<class Color>
ImageView WorldStone::ImageView< Color >::subView ( size_t  xOffset,
size_t  yOffset,
size_t  subWidth,
size_t  subHeight 
) const
inline

Create an ImageView that is contained by the current view.

Parameters
xOffsetFirst column of the subview
yOffsetFirst row of the subview
subWidthNumber of columns, must verify
xOffset + subWidth <= width
subHeightNumber of rows, must verify
yOffset + subHeight > height
Returns
A subview of given characteristics, or an invalid view if not contained by the current one

Definition at line 61 of file ImageView.h.


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