libdonut  2.3.2
Application framework for cross-platform game development in C++20
Public Member Functions | List of all members
donut::graphics::ImageView Class Reference

Read-only non-owning view over a 2D image. More...

#include <donut/graphics/Image.hpp>

Public Member Functions

constexpr ImageView () noexcept=default
 Construct a view that does not reference an image. More...
 
constexpr ImageView (std::size_t width, std::size_t height, PixelFormat pixelFormat, PixelComponentType pixelComponentType, const void *pixels) noexcept
 Construct an image view over arbitrary 2D pixel data. More...
 
 operator bool () const noexcept
 Check if this view references an image. More...
 
constexpr std::size_t getWidth () const noexcept
 Get the width of the image referenced by this view. More...
 
constexpr std::size_t getHeight () const noexcept
 Get the height of the image referenced by this view. More...
 
constexpr PixelFormat getPixelFormat () const noexcept
 Get the pixel format of the image referenced by this view. More...
 
constexpr PixelComponentType getPixelComponentType () const noexcept
 Get the pixel component type of the image referenced by this view. More...
 
constexpr const void * getPixels () const noexcept
 Get the pixel data referenced by this view. More...
 
constexpr std::size_t getChannelCount () const noexcept
 Get the number of component channels in the pixel format of the image referenced by this view. More...
 
constexpr std::size_t getPixelComponentSize () const noexcept
 Get the size in bytes of a single component of a pixel in the image referenced by this view. More...
 
constexpr std::size_t getPixelStride () const noexcept
 Get the stride in bytes of the pixels in the image referenced by this view. More...
 
constexpr std::size_t getSizeInBytes () const noexcept
 Get the size in bytes of the image referenced by this view. More...
 

Detailed Description

Read-only non-owning view over a 2D image.

See also
Image

Constructor & Destructor Documentation

◆ ImageView() [1/2]

constexpr donut::graphics::ImageView::ImageView ( )
constexprdefaultnoexcept

Construct a view that does not reference an image.

◆ ImageView() [2/2]

constexpr donut::graphics::ImageView::ImageView ( std::size_t  width,
std::size_t  height,
PixelFormat  pixelFormat,
PixelComponentType  pixelComponentType,
const void *  pixels 
)
inlineconstexprnoexcept

Construct an image view over arbitrary 2D pixel data.

Parameters
widthwidth of the image, in pixels. Must be 0 if pixels is nullptr.
heightheight of the image, in pixels. Must be 0 if pixels is nullptr.
pixelFormatpixel format of the image. Must be PixelFormat::R if pixels is nullptr.
pixelComponentTypepixel component data type of the image. Must be PixelComponentType::U8 if pixels is nullptr.
pixelsread-only non-owning pointer to the pixel data, or nullptr to create a view that doesn't reference an image.

Member Function Documentation

◆ operator bool()

donut::graphics::ImageView::operator bool ( ) const
inlineexplicitnoexcept

Check if this view references an image.

Returns
true if the view references an image, false otherwise.

◆ getWidth()

constexpr std::size_t donut::graphics::ImageView::getWidth ( ) const
inlineconstexprnoexcept

Get the width of the image referenced by this view.

Returns
the width of the image, in pixels, or 0 if the view does not reference an image.
See also
getHeight()
getSizeInBytes()

◆ getHeight()

constexpr std::size_t donut::graphics::ImageView::getHeight ( ) const
inlineconstexprnoexcept

Get the height of the image referenced by this view.

Returns
the height of the image, in pixels, or 0 if the view does not reference an image.
See also
getWidth()
getSizeInBytes()

◆ getPixelFormat()

constexpr PixelFormat donut::graphics::ImageView::getPixelFormat ( ) const
inlineconstexprnoexcept

Get the pixel format of the image referenced by this view.

Returns
the pixel format, or PixelFormat::R if the view does not reference an image.
See also
getChannelCount()

◆ getPixelComponentType()

constexpr PixelComponentType donut::graphics::ImageView::getPixelComponentType ( ) const
inlineconstexprnoexcept

Get the pixel component type of the image referenced by this view.

Returns
the pixel component type, or PixelComponentType::U8 if the view does not reference an image.
See also
getPixelComponentSize()

◆ getPixels()

constexpr const void* donut::graphics::ImageView::getPixels ( ) const
inlineconstexprnoexcept

Get the pixel data referenced by this view.

The pixel data is tightly packed and fully contiguous, so the total size of the image in bytes is:

width * height * pixelSize
```.
The size of a single pixel, `pixelSize`, is

pixelFormatChannelCount * pixelComponentTypeSize `` wherepixelFormatChannelCountis the number of component channels in the pixel format, andpixelComponentTypeSize` is the size in bytes of a single pixel component.

The pixels are stored in row-major order, starting at the bottom left of the image (unless the image is flipped).

Returns
a read-only non-owning pointer to the pixel data, or nullptr if the view does not reference an image.
See also
getWidth()
getHeight()
getPixelFormat()
getPixelComponentType()

◆ getChannelCount()

constexpr std::size_t donut::graphics::ImageView::getChannelCount ( ) const
inlineconstexprnoexcept

Get the number of component channels in the pixel format of the image referenced by this view.

Returns
the number of channels, or 0 if the view does not reference an image.
See also
getPixelFormat()
getPixelStride()

◆ getPixelComponentSize()

constexpr std::size_t donut::graphics::ImageView::getPixelComponentSize ( ) const
inlineconstexprnoexcept

Get the size in bytes of a single component of a pixel in the image referenced by this view.

Returns
the size of the pixel component type, or 0 if the view does not reference an image.
See also
getPixelComponentType()
getPixelStride()

◆ getPixelStride()

constexpr std::size_t donut::graphics::ImageView::getPixelStride ( ) const
inlineconstexprnoexcept

Get the stride in bytes of the pixels in the image referenced by this view.

Returns
the number of bytes to advance to get from one pixel to the next, or 0 if the view does not reference an image.
See also
getChannelCount()
getPixelComponentSize()
getSizeInBytes()

◆ getSizeInBytes()

constexpr std::size_t donut::graphics::ImageView::getSizeInBytes ( ) const
inlineconstexprnoexcept

Get the size in bytes of the image referenced by this view.

Returns
the total size of the image, or 0 if the view does not reference an image.
See also
getWidth()
getHeight()
getPixelStride()

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