GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::resource::ImageView Class Reference

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

#include <GREM/resource/Image.hpp>

Public Member Functions

constexpr ImageView () noexcept=default
 Construct a view that does not reference an image.
constexpr ImageView (ImageType type, ImageFormat format, Extent3D size3D, uint32_t mipLevelCount, Span< const byte > contents)
 Construct an image view over arbitrary 2D pixel data.
void transcodeTo (byte *output, ImageFormat outputFormat) const
 Transcode the image data to a specific format.
constexpr ImageType getType () const noexcept
 Get the type of the image referenced by this view.
constexpr ImageFormat getFormat () const noexcept
 Get the format of the image referenced by this view.
constexpr Extent2D getSize2D () const noexcept
 Get the size, in pixels, of the image layers referenced by this view.
constexpr Extent3D getSize3D () const noexcept
 Get the size, in pixels, and the depth, in layers, of the image referenced by this view.
constexpr uint32_t getWidth () const noexcept
 Get the width of the image referenced by this view.
constexpr uint32_t getHeight () const noexcept
 Get the height of the image referenced by this view.
constexpr uint32_t getDepth () const noexcept
 Get the depth of the image referenced by this view.
constexpr uint32_t getMipLevelCount () const noexcept
 Get the number of mip levels in the image referenced by this view.
constexpr Span< const byte > getContents () const noexcept
 Get the image data referenced by this view.
constexpr const byte * data () const noexcept
 Get a pointer to the image data referenced by this view.
constexpr size_t size () const noexcept
 Get the size of the image data.
template<typename Pixel>
constexpr Pixel readPixel (Offset3D position, uint32_t mipLevel=0) const
 Read a specific pixel of the image.
constexpr ImageView getPixel (Offset3D position, uint32_t mipLevel=0) const
 Get a view over a specific pixel of the image.
constexpr ImageView getLayer (uint32_t layer, uint32_t mipLevel=0) const
 Get a view over a specific layer of a specific mip level of the image.
constexpr ImageView getMipLevel (uint32_t mipLevel) const
 Get a view over all layers in a specific mip level of the image.
constexpr ImageView getMipLevels (uint32_t firstMipLevel, uint32_t mipLevels) const
 Get a view over all layers in a specific range of mip levels of the image.
constexpr ImageView getMipLevels (uint32_t firstMipLevel) const
 Get a view over all layers of all mip levels of the image at or above a specific mip level.
Image getPadded (uint32_t paddingLeft, uint32_t paddingRight, uint32_t paddingTop, uint32_t paddingBottom) const
 Get a padded version of the image.
Image getPadded (uint32_t padding) const
 Get a uniformly padded version of the image.

Detailed Description

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

See also
ImageReference
Image

Constructor & Destructor Documentation

◆ ImageView() [1/2]

grem::resource::ImageView::ImageView ( )
constexprdefaultnoexcept

Construct a view that does not reference an image.

◆ ImageView() [2/2]

grem::resource::ImageView::ImageView ( ImageType type,
ImageFormat format,
Extent3D size3D,
uint32_t mipLevelCount,
Span< const byte > contents )
inlineconstexpr

Construct an image view over arbitrary 2D pixel data.

Parameters
typeimage type.
formatimage format.
size3Dsize3D of the image, in pixels and layers. If type is ImageType::IMAGE_CUBE or ImageType::IMAGE_CUBE_ARRAY, width must be equal to height. If type is ImageType::IMAGE_2D, depth must be
  1. If type is ImageType::IMAGE_CUBE, depth must be 6. If type is ImageType::IMAGE_CUBE_ARRAY, depth must be a multiple of 6.
mipLevelCountnumber of mip levels stored for the image. Must be less than or equal to the result of Image::getMaxMipLevelCount() for the given width and height.
contentsread-only view over the image data, or an empty span to create a view that doesn't reference an image. Must have a valid size for the given type and shape of the image, including all layers and mip levels.

Member Function Documentation

◆ transcodeTo()

void grem::resource::ImageView::transcodeTo ( byte * output,
ImageFormat outputFormat ) const

Transcode the image data to a specific format.

Parameters
outputnon-owning pointer to a block of memory to write the transcoded image data to. Must point to a valid block of memory of at least the size required for the full image in the given output format, including all layers and mip levels, and must not be nullptr.
outputFormatimage format to transcode to.
Exceptions
std::invalid_argumentif transcoding failed, or if transcoding from the image's current format to the given format is not supported.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.
Note
The following transcodings are supported:
  • Copying any non-containerized format to the same format
  • KTX2 ETC1S/UASTC -> ASTC 4x4 LDR/BC1-5/Unsigned BC6H/BC7/ETC1/ETC2/EAC/PVRTC1
  • KTX2 ETC1S/UASTC -> Raw format
  • Raw 32-bit float format -> Raw 16-bit float format
  • Raw 16-bit float format -> Raw 32-bit float format

◆ getType()

ImageType grem::resource::ImageView::getType ( ) const
inlinenodiscardconstexprnoexcept

Get the type of the image referenced by this view.

Returns
the image type.

◆ getFormat()

ImageFormat grem::resource::ImageView::getFormat ( ) const
inlinenodiscardconstexprnoexcept

Get the format of the image referenced by this view.

Returns
the image format.

◆ getSize2D()

Extent2D grem::resource::ImageView::getSize2D ( ) const
inlinenodiscardconstexprnoexcept

Get the size, in pixels, of the image layers referenced by this view.

Returns
the size of a layer of the image, in pixels.
Note
For 2D array images, this function returns the width and height of a single image layer in the array.
For cube images, this function returns the size of a single side of the cubemap.
See also
getSize3D()
getWidth()
getHeight()

◆ getSize3D()

Extent3D grem::resource::ImageView::getSize3D ( ) const
inlinenodiscardconstexprnoexcept

Get the size, in pixels, and the depth, in layers, of the image referenced by this view.

Returns
the size of the image, in pixels and layers.
See also
getSize2D()
getWidth()
getHeight()
getDepth()

◆ getWidth()

uint32_t grem::resource::ImageView::getWidth ( ) const
inlinenodiscardconstexprnoexcept

Get the width of the image referenced by this view.

Returns
the width of the image, in pixels.

◆ getHeight()

uint32_t grem::resource::ImageView::getHeight ( ) const
inlinenodiscardconstexprnoexcept

Get the height of the image referenced by this view.

Returns
the height of the image, in pixels.

◆ getDepth()

uint32_t grem::resource::ImageView::getDepth ( ) const
inlinenodiscardconstexprnoexcept

Get the depth of the image referenced by this view.

Returns
the depth of the image, in layers.

◆ getMipLevelCount()

uint32_t grem::resource::ImageView::getMipLevelCount ( ) const
inlinenodiscardconstexprnoexcept

Get the number of mip levels in the image referenced by this view.

Returns
the number of mip levels in the image.

◆ getContents()

Span< const byte > grem::resource::ImageView::getContents ( ) const
inlinenodiscardconstexprnoexcept

Get the image data referenced by this view.

Returns
a read-only view over the image data.
See also
getType()
getFormat()
getSize3D()
getMipLevelCount()
data()
size()

◆ data()

const byte * grem::resource::ImageView::data ( ) const
inlinenodiscardconstexprnoexcept

Get a pointer to the image data referenced by this view.

Returns
a non-owning read-only pointer to the image data.
See also
size()

◆ size()

size_t grem::resource::ImageView::size ( ) const
inlinenodiscardconstexprnoexcept

Get the size of the image data.

Returns
the size of the image data, in bytes.
See also
getSize2D()
getSize3D()
data()

◆ readPixel()

template<typename Pixel>
Pixel grem::resource::ImageView::readPixel ( Offset3D position,
uint32_t mipLevel = 0 ) const
nodiscardconstexpr

Read a specific pixel of the image.

Template Parameters
Pixelpixel type to read. Must be a default-initializable, trivially copyable type that is binary-compatible with the current pixel format of the image.
Parameters
positioncoordinates of the pixel to get. Must be a valid position within the specified mip level.
mipLevelindex of the mip level to get the pixel from. Must be a valid mip level index that is less than getMipLevelCount().
Returns
a copy of the specified pixel of the image.
Exceptions
std::invalid_argumentif the image is not in a raw uncompressed format.

◆ getPixel()

ImageView grem::resource::ImageView::getPixel ( Offset3D position,
uint32_t mipLevel = 0 ) const
nodiscardconstexpr

Get a view over a specific pixel of the image.

Parameters
positioncoordinates of the pixel to get. Must be a valid position within the specified mip level.
mipLevelindex of the mip level to get the pixel from. Must be a valid mip level index that is less than getMipLevelCount().
Returns
a 1x1 read-only view over the specified pixel of the image, with an image type of ImageType::IMAGE_2D.
Exceptions
std::invalid_argumentif the image is not in a raw uncompressed format.

◆ getLayer()

ImageView grem::resource::ImageView::getLayer ( uint32_t layer,
uint32_t mipLevel = 0 ) const
nodiscardconstexpr

Get a view over a specific layer of a specific mip level of the image.

Parameters
layerindex of the layer to get. Must be a valid layer index that is less than getDepth().
mipLevelindex of the mip level to get the layer from. Must be a valid mip level index that is less than getMipLevelCount().
Returns
a read-only view over the specified layer of the image, with an image type of ImageType::IMAGE_2D.
Exceptions
std::invalid_argumentif the image is not in a raw format.
std::length_errorif the maximum image size was exceeded.

◆ getMipLevel()

ImageView grem::resource::ImageView::getMipLevel ( uint32_t mipLevel) const
nodiscardconstexpr

Get a view over all layers in a specific mip level of the image.

Parameters
mipLevelindex of the mip level to get. Must be a valid mip level index that is less than getMipLevelCount().
Returns
a read-only view over all layers in the specified mip level of the image.
Exceptions
std::invalid_argumentif the image is not in a raw format.
std::length_errorif the maximum image size was exceeded.

◆ getMipLevels() [1/2]

ImageView grem::resource::ImageView::getMipLevels ( uint32_t firstMipLevel,
uint32_t mipLevels ) const
nodiscardconstexpr

Get a view over all layers in a specific range of mip levels of the image.

Parameters
firstMipLevelindex of the first mip level to get. Must be less than or equal to getMipLevelCount().
mipLevelsnumber of mip levels to get. Must be less than or equal to getMipLevelCount() - firstMipLevel.
Returns
a read-only view over all layers in the specified mip levels of the image.
Exceptions
std::invalid_argumentif the image is not in a raw format.
std::length_errorif the maximum image size was exceeded.

◆ getMipLevels() [2/2]

ImageView grem::resource::ImageView::getMipLevels ( uint32_t firstMipLevel) const
nodiscardconstexpr

Get a view over all layers of all mip levels of the image at or above a specific mip level.

Parameters
firstMipLevelindex of the first mip level to get. Must be less than or equal to getMipLevelCount().
Returns
a read-only view over all layers in the mip levels at or above the specified mip level.
Exceptions
std::invalid_argumentif the image is not in a raw format.
std::length_errorif the maximum image size was exceeded.

◆ getPadded() [1/2]

Image grem::resource::ImageView::getPadded ( uint32_t paddingLeft,
uint32_t paddingRight,
uint32_t paddingTop,
uint32_t paddingBottom ) const
nodiscard

Get a padded version of the image.

The image must be in a raw format.

Parameters
paddingLeftpadding to add to the left of the image, in pixels.
paddingRightpadding to add to the right of the image, in pixels.
paddingToppadding to add above the image, in pixels.
paddingBottompadding to add below the image, in pixels.
Returns
a copy of this image with its edges padded by the given amount, using the color of the pixel closest to each point in the original image, or zeros if the original image is empty.
Exceptions
std::invalid_argumentif the image is not in a raw format.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.
Note
If there are multiple layers, each layer is padded individually.

◆ getPadded() [2/2]

Image grem::resource::ImageView::getPadded ( uint32_t padding) const
inlinenodiscard

Get a uniformly padded version of the image.

The image must be in a raw format.

Parameters
paddingpadding to add on each side of the image, in pixels.
Returns
a copy of this image with its edges padded by the given amount, using the color of the pixel closest to each point in the original image, or zeros if the original image is empty.
Exceptions
std::invalid_argumentif the image is not in a raw format.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.
Note
If there are multiple layers, each layer is padded individually.

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