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

Container for a 2D image. More...

#include <GREM/resource/Image.hpp>

Public Member Functions

 Image () noexcept=default
 Construct an empty image without a value.
 Image (ImageType type, ImageFormat format, Extent3D size3D, uint32_t mipLevelCount, Span< const byte > contents={})
 Construct an image.
 Image (ImageType type, ImageFormat format, Extent3D size3D, uint32_t mipLevelCount, Allocation< byte > contents)
 Construct an image.
 Image (const ImageView &image)
 Construct an image copied from an image view.
 Image (const Filesystem &filesystem, CStringView filepath, const ImageOptions &options={})
 Load an image from a file.
 Image (Span< const byte > fileContents, const ImageOptions &options={})
 Load an image from an in-memory file.
 operator ImageView () const noexcept
 Get a read-only view over this image.
 operator ImageReference () noexcept
 Get a view over this image.
void reset () noexcept
 Remove the value from this image and reset it to an empty image.
void transcodeTo (byte *output, ImageFormat outputFormat) const
 Transcode the image data to a specific format.
void transformFromStraightToPremultipliedAlpha (Color::TransferFunction transferFunction)
 Transform the RGBA image pixel colors from straight to pre-multiplied alpha.
void transformFromPremultipliedToStraightAlpha (Color::TransferFunction transferFunction)
 Transform the RGBA image pixel colors from pre-multiplied to straight alpha.
ImageType getType () const noexcept
 Get the type of the image.
ImageFormat getFormat () const noexcept
 Get the format of the image.
Extent2D getSize2D () const noexcept
 Get the size, in pixels, of the image layers.
Extent3D getSize3D () const noexcept
 Get the size, in pixels, and the depth, in layers, of the image.
uint32_t getWidth () const noexcept
 Get the width of the image.
uint32_t getHeight () const noexcept
 Get the height of the image.
uint32_t getDepth () const noexcept
 Get the depth of the image.
uint32_t getMipLevelCount () const noexcept
 Get the number of mip levels in the image referenced by this view.
Span< byte > getContents () noexcept
 Get the data of this image.
Span< const byte > getContents () const noexcept
 Get the data of this image.
byte * data () noexcept
 Get a pointer to the data of this image.
const byte * data () const noexcept
 Get a pointer to the data of this image.
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.
ImageView getPixel (Offset3D position, uint32_t mipLevel=0) const
 Get a view over a specific pixel of the image.
ImageReference getPixel (Offset3D position, uint32_t mipLevel=0)
 Get a view over a specific pixel of the image.
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.
ImageReference getLayer (uint32_t layer, uint32_t mipLevel=0)
 Get a view over a specific layer of a specific mip level of the image.
ImageView getMipLevel (uint32_t mipLevel) const
 Get a view over all layers in a specific mip level of the image.
ImageReference getMipLevel (uint32_t mipLevel)
 Get a view over all layers in a specific mip level of the image.
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.
ImageReference getMipLevels (uint32_t firstMipLevel, uint32_t mipLevels)
 Get a view over all layers in a specific range of mip levels of the image.
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.
ImageReference getMipLevels (uint32_t firstMipLevel)
 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 paddingBottom, uint32_t paddingTop) const
 Get a uniformly padded version of the image.
Image getPadded (uint32_t padding) const
 Get a uniformly padded version of the image.

Static Public Member Functions

static constexpr uint32_t getMaxMipLevelCount (Extent2D size2D) noexcept
 Get the maximum number of mip levels for a specific 2D image size.
static constexpr size_t getLogicalChannelCount (ImageFormat format)
 Get the number of logical pixel component channels in a specific image format (which doesn't necessarily correspond to the physical pixel size of the format).
static constexpr bool isRGBAColorFormat (ImageFormat format)
 Check if a specific image format is an RGBA color format with an alpha channel.
static constexpr bool isRawFormat (ImageFormat format)
 Check if a specific image format is a raw format.
static constexpr bool isPackedFormat (ImageFormat format)
 Check if a specific image format is a bit-packed format.
static constexpr bool isCompressedFormat (ImageFormat format)
 Check if a specific image format is a (potentially containerized) compressed format.
static constexpr bool isContainerizedFormat (ImageFormat format)
 Check if a specific image format is a containerized format.
static constexpr ImageFormat getRawFormat (ImageFormat format)
 Get the raw format corresponding to a specific image format.
static constexpr ImageFormat getUncompressedFormat (ImageFormat format)
 Get the uncompressed format corresponding to a specific image format.
static constexpr size_t getPixelStride (ImageFormat format)
 Get the stride in bytes of the pixels in a specific uncompressed image format.
static constexpr Extent2D getBlockSize2D (ImageFormat format)
 Get the raw uncompressed size of the 2D blocks in a specific non-containerized image format, in pixels.
static constexpr size_t getBlockStride (ImageFormat format)
 Get the stride in bytes of the blocks in a specific non-containerized image format.
static constexpr Extent3D getMipLevelSize3D (Extent3D size3D, uint32_t mipLevel)
 Get the 3D size, in pixels, of all layers in a specific mip level of an image.
static constexpr Extent2D getMipLevelSize2D (Extent2D size2D, uint32_t mipLevel)
 Get the 2D size, in pixels, of a single layer in a specific mip level of an image.
static constexpr size_t getRowStride (ImageFormat format, uint32_t width)
 Get the stride in bytes of the rows in a specific uncompressed image format.
static constexpr size_t getLayerStride (ImageFormat format, Extent2D size2D)
 Get the stride in bytes of the layers in a specific non-containerized image format.
static constexpr size_t getMipLevelStride (ImageFormat format, Extent3D size3D)
 Get the size in bytes of a single-mip-level image in a specific non-containerized image format.
static constexpr size_t getSizeInBytes (ImageFormat format, Extent3D size3D, uint32_t mipLevelCount)
 Get the size in bytes of an image in a specific non-containerized image format.
template<typename OutputComponent, typename InputComponent>
static OutputComponent convertPixelComponent (const InputComponent &value) noexcept
 Convert a single pixel component of a raw image to another pixel component type.
template<typename OutputComponent, size_t OutputComponentCount, typename InputComponent, size_t InputComponentCount>
static void convertPixel (byte *output, const byte *input)
 Convert a single pixel of a raw image to another raw pixel format.
template<typename OutputComponent, size_t OutputComponentCount, typename InputComponent, size_t InputComponentCount>
static void convertPixels (Extent3D outputSize, byte *output, Offset3D outputOffset, Extent3D inputSize, const byte *input, Region3D inputRegion)
 Convert the pixels in a region of a raw image to another raw pixel format.
template<typename OutputComponent, size_t OutputComponentCount, typename InputComponent, size_t InputComponentCount>
static void convertPixels (Extent3D size3D, uint32_t mipLevelCount, byte *output, const byte *input)
 Convert all pixels of a full raw image to another raw pixel format.
static void copyPixels (Extent3D outputSize, byte *output, Offset3D outputOffset, Extent3D inputSize, const byte *input, Region3D inputRegion, size_t pixelStride)
 Copy the pixels in a region of a raw image to another image region in the same format.
static void copyPixels (Extent3D size3D, uint32_t mipLevelCount, byte *output, const byte *input, size_t pixelStride)
 Copy all pixels of a full raw image to another image in the same format.
static void transformPixels (Extent3D size, byte *pixels, Region3D region, size_t pixelStride, auto op)
 Transform the pixels in a region of a raw image by a given operation.
static void transformPixels (Extent3D size3D, uint32_t mipLevelCount, byte *pixels, size_t pixelStride, auto op)
 Transform all pixels of a full raw image by a given operation.
static void fillPixels (Extent3D outputSize, byte *output, Region3D outputRegion, size_t pixelStride, const byte *inputPixel)
 Set the pixels in a region of a raw image to a specific pixel value.
static void fillPixels (Extent3D size3D, uint32_t mipLevelCount, byte *output, size_t pixelStride, const byte *inputPixel)
 Set all pixels of a full raw image to a specific pixel value.
template<typename OutputComponent, size_t OutputComponentCount, size_t ComponentIndex>
static void setPixelsComponent (Extent3D outputSize, byte *output, Region3D outputRegion, const OutputComponent &value)
 Set a component of the pixels in a region of a raw image to a specific value.
template<typename OutputComponent, size_t OutputComponentCount, size_t ComponentIndex>
static void setPixelsComponent (Extent3D size3D, uint32_t mipLevelCount, byte *output, const OutputComponent &value)
 Set a component of all pixels of a full raw image to a specific value.
template<typename PixelComponent, Color::TransferFunction TransferFunction>
static void transformRGBAPixelsFromStraightToPremultipliedAlpha (Extent3D size3D, uint32_t mipLevelCount, byte *pixels)
 Transform all pixels of a full raw RGBA image from straight to pre-multiplied alpha.
template<typename PixelComponent, Color::TransferFunction TransferFunction>
static void transformRGBAPixelsFromPremultipliedToStraightAlpha (Extent3D size3D, uint32_t mipLevelCount, byte *pixels)
 Transform all pixels of a full raw RGBA image from pre-multiplied to straight alpha.
static void flipVertically (Extent2D size2D, byte *pixels, size_t pixelStride)
 Flip a layer of a raw image on the Y axis.
static ImageFileType determineFileType (Span< const byte > fileContents)
 Determine which image file type a file should be parsed as based on the contents at the beginning of the file.
static void savePNG (const ImageView &image, Filesystem &filesystem, CStringView filepath, const ImageSavePNGOptions &options={})
 Save an 8-bit-per-channel image to a PNG file.
static Allocation< byte > savePNG (const ImageView &image, const ImageSavePNGOptions &options={})
 Save an 8-bit-per-channel image to an in-memory PNG file.
static void saveJPEG (const ImageView &image, Filesystem &filesystem, CStringView filepath, const ImageSaveJPEGOptions &options={})
 Save an 8-bit-per-channel image to a JPEG file.
static Allocation< byte > saveJPEG (const ImageView &image, const ImageSaveJPEGOptions &options={})
 Save an 8-bit-per-channel image to an in-memory JPEG file.
static void saveHDR (const ImageView &image, Filesystem &filesystem, CStringView filepath, const ImageSaveHDROptions &options={})
 Save a floating-point 32-bit-per-channel image to an RGBE/Radiance HDR file.
static Allocation< byte > saveHDR (const ImageView &image, const ImageSaveHDROptions &options={})
 Save a floating-point 32-bit-per-channel image to an in-memory RGBE/Radiance HDR file.
static void saveKTX2 (const ImageView &image, Filesystem &filesystem, CStringView filepath, const ImageSaveKTX2Options &options={})
 Save an image to a Khronos TeXture, version 2.0 file.
static Allocation< byte > saveKTX2 (const ImageView &image, const ImageSaveKTX2Options &options={})
 Save an image to an in-memory Khronos Texture, version 2.0 file.
static void save (const ImageView &image, Filesystem &filesystem, CStringView filepath, const ImageSaveOptions &options={})
 Save an image to a file.

Detailed Description

Container for a 2D image.

See also
ImageView

Constructor & Destructor Documentation

◆ Image() [1/6]

grem::resource::Image::Image ( )
defaultnoexcept

Construct an empty image without a value.

◆ Image() [2/6]

grem::resource::Image::Image ( ImageType type,
ImageFormat format,
Extent3D size3D,
uint32_t mipLevelCount,
Span< const byte > contents = {} )

Construct an image.

Parameters
typeimage type.
formatimage format.
size3Dsize of the image to allocate, 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
  1. 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 2D size.
contentsread-only view over the image data to copy, or an empty span to leave the data uninitialized. Must either be empty or have a valid size for the given shape of the image.
Exceptions
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ Image() [3/6]

grem::resource::Image::Image ( ImageType type,
ImageFormat format,
Extent3D size3D,
uint32_t mipLevelCount,
Allocation< byte > contents )

Construct an image.

Parameters
typeimage type.
formatimage format.
size3Dsize of the image to allocate, 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
  1. 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 2D size.
contentsarray containing the image data, or an empty array to allocate new data and leave it uninitialized. Must either be empty or have a valid size for the given shape of the image.
Exceptions
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ Image() [4/6]

grem::resource::Image::Image ( const ImageView & image)
explicit

Construct an image copied from an image view.

Parameters
imageread-only view over the image to copy.
Exceptions
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ Image() [5/6]

grem::resource::Image::Image ( const Filesystem & filesystem,
CStringView filepath,
const ImageOptions & options = {} )

Load an image from a file.

The supported file formats are:

  • JPEG (.jpg/.jpeg)
  • PNG (.png)
  • RGBE/Radiance HDR (.hdr)
  • Khronos TeXture, version 2.0 (.ktx2)
Parameters
filesystemfilesystem to load the file from.
filepathinput filepath of the image file to load.
optionsimage options, see ImageOptions.
Exceptions
File::Erroron failure to open or read from the file.
resource::Erroron failure to load a valid image from the file.
std::length_errorif the maximum image or file size was exceeded.
std::bad_allocon allocation failure.
Note
The file format is determined entirely from the file contents; the filename extension is not taken into account.
The image format is determined by its source format, unless ImageOptions::requiredFormat is specified.
PNG files support 1/2/4/8/16 bits per channel (always converted to 8), as well as PLTE (palette) and tRNS (transparency) chunks.
HDR files support 32-bit_rle_rgbe format and +Y +X or -Y +X layout only.

◆ Image() [6/6]

grem::resource::Image::Image ( Span< const byte > fileContents,
const ImageOptions & options = {} )
explicit

Load an image from an in-memory file.

The supported file formats are:

  • JPEG (.jpg/.jpeg)
  • PNG (.png)
  • RGBE/Radiance HDR (.hdr)
  • Khronos TeXture, version 2.0 (.ktx2)
Parameters
fileContentscontents of the image file to load.
optionsimage options, see ImageOptions.
Exceptions
resource::Erroron failure to load a valid image from the file.
std::length_errorif the maximum image or file size was exceeded.
std::bad_allocon allocation failure.
Note
The file format is determined entirely from the file contents.
The image format is determined by its source format, unless ImageOptions::requiredFormat is specified.
PNG files support 1/2/4/8/16 bits per channel (always converted to 8), as well as PLTE (palette) and tRNS (transparency) chunks.
HDR files support 32-bit_rle_rgbe format and +Y +X or -Y +X layout only.

Member Function Documentation

◆ getMaxMipLevelCount()

constexpr uint32_t grem::resource::Image::getMaxMipLevelCount ( Extent2D size2D)
inlinestaticnodiscardconstexprnoexcept

Get the maximum number of mip levels for a specific 2D image size.

Parameters
size2Dsize of the 2D image at mip level 0.
Returns
the maximum number of mip levels for the given image size.

◆ getLogicalChannelCount()

constexpr size_t grem::resource::Image::getLogicalChannelCount ( ImageFormat format)
inlinestaticnodiscardconstexpr

Get the number of logical pixel component channels in a specific image format (which doesn't necessarily correspond to the physical pixel size of the format).

Parameters
formatimage format to get the number of channels in.
Returns
the number of logical component channels in the given format.

◆ isRGBAColorFormat()

constexpr bool grem::resource::Image::isRGBAColorFormat ( ImageFormat format)
inlinestaticnodiscardconstexpr

Check if a specific image format is an RGBA color format with an alpha channel.

Parameters
formatimage format to check.
Returns
true if the image format is an RGBA color format with an alpha channel, false otherwise.

◆ isRawFormat()

constexpr bool grem::resource::Image::isRawFormat ( ImageFormat format)
inlinestaticnodiscardconstexpr

Check if a specific image format is a raw format.

Parameters
formatimage format to check.
Returns
true if the image format is raw, false otherwise.

◆ isPackedFormat()

constexpr bool grem::resource::Image::isPackedFormat ( ImageFormat format)
inlinestaticnodiscardconstexpr

Check if a specific image format is a bit-packed format.

Parameters
formatimage format to check.
Returns
true if the image format is packed, false otherwise.
Note
Compressed formats without any further bit-packing do not count as packed formats.

◆ isCompressedFormat()

constexpr bool grem::resource::Image::isCompressedFormat ( ImageFormat format)
inlinestaticnodiscardconstexpr

Check if a specific image format is a (potentially containerized) compressed format.

Parameters
formatimage format to check.
Returns
true if the image format is compressed, false otherwise.
Note
Bit-packed formats without any further compression do not count as compressed formats.

◆ isContainerizedFormat()

constexpr bool grem::resource::Image::isContainerizedFormat ( ImageFormat format)
inlinestaticnodiscardconstexpr

Check if a specific image format is a containerized format.

Parameters
formatimage format to check.
Returns
true if the image format is containerized, false otherwise.

◆ getRawFormat()

constexpr ImageFormat grem::resource::Image::getRawFormat ( ImageFormat format)
inlinestaticnodiscardconstexpr

Get the raw format corresponding to a specific image format.

Parameters
formatimage format to get the raw image format of.
Returns
the corresponding raw image format.

◆ getUncompressedFormat()

constexpr ImageFormat grem::resource::Image::getUncompressedFormat ( ImageFormat format)
inlinestaticnodiscardconstexpr

Get the uncompressed format corresponding to a specific image format.

Parameters
formatimage format to get the uncompressed image format of.
Returns
the corresponding uncompressed image format.
Note
The corresponding uncompressed format may still be packed. To get the raw format, use getRawFormat() instead.

◆ getPixelStride()

constexpr size_t grem::resource::Image::getPixelStride ( ImageFormat format)
inlinestaticnodiscardconstexpr

Get the stride in bytes of the pixels in a specific uncompressed image format.

Parameters
formatimage format.
Returns
the number of bytes to advance to get from one pixel to the next, or 0 if the given format is not an uncompressed format.

◆ getBlockSize2D()

constexpr Extent2D grem::resource::Image::getBlockSize2D ( ImageFormat format)
inlinestaticnodiscardconstexpr

Get the raw uncompressed size of the 2D blocks in a specific non-containerized image format, in pixels.

Parameters
formatimage format.
Returns
the raw uncompressed size of each block in the given format, in pixels, or (0, 0) if the given format is unknown or containerized.
Note
For uncompressed formats, this function always returns (1, 1), since each pixel is its own block.

◆ getBlockStride()

constexpr size_t grem::resource::Image::getBlockStride ( ImageFormat format)
inlinestaticnodiscardconstexpr

Get the stride in bytes of the blocks in a specific non-containerized image format.

Parameters
formatimage format.
Returns
the number of bytes to advance to get from one block to the next, or 0 if the given format is unknown or containerized.
Note
For uncompressed formats, this function is equivalent to getPixelStride().

◆ getMipLevelSize3D()

constexpr Extent3D grem::resource::Image::getMipLevelSize3D ( Extent3D size3D,
uint32_t mipLevel )
inlinestaticnodiscardconstexpr

Get the 3D size, in pixels, of all layers in a specific mip level of an image.

Parameters
size3Dsize of the full image, in pixels.
mipLevelindex of the mip level to get the size of. Must be less than the result of Image::getMaxMipLevelCount() for the given 2D size.
Returns
the 3D size, in pixels, of the full mip level, including all layers.

◆ getMipLevelSize2D()

constexpr Extent2D grem::resource::Image::getMipLevelSize2D ( Extent2D size2D,
uint32_t mipLevel )
inlinestaticnodiscardconstexpr

Get the 2D size, in pixels, of a single layer in a specific mip level of an image.

Parameters
size2Dsize of the full image, in pixels.
mipLevelindex of the mip level to get the size of. Must be less than the result of Image::getMaxMipLevelCount() for the given 2D size.
Returns
the 2D size, in pixels, of a single layer at the given mip level.

◆ getRowStride()

constexpr size_t grem::resource::Image::getRowStride ( ImageFormat format,
uint32_t width )
inlinestaticnodiscardconstexpr

Get the stride in bytes of the rows in a specific uncompressed image format.

Parameters
formatimage format.
widthwidth of the image, in pixels.
Returns
the number of bytes to advance to get from one row to the next, or 0 if the given format is not an uncompressed format.
Exceptions
std::length_errorif the maximum image size was exceeded.

◆ getLayerStride()

constexpr size_t grem::resource::Image::getLayerStride ( ImageFormat format,
Extent2D size2D )
inlinestaticnodiscardconstexpr

Get the stride in bytes of the layers in a specific non-containerized image format.

Parameters
formatimage format.
size2Dsize of the full image layer, in pixels.
Returns
the number of bytes to advance to get from one layer to the next, or 0 if the given format is unknown or containerized.
Exceptions
std::length_errorif the maximum image size was exceeded.

◆ getMipLevelStride()

constexpr size_t grem::resource::Image::getMipLevelStride ( ImageFormat format,
Extent3D size3D )
inlinestaticnodiscardconstexpr

Get the size in bytes of a single-mip-level image in a specific non-containerized image format.

Parameters
formatimage format.
size3Dsize of the full image mip level, in pixels.
Returns
the total size of the full image mip level, including all layers, or 0 if the given format is unknown or containerized.
Exceptions
std::length_errorif the maximum image size was exceeded.

◆ getSizeInBytes()

constexpr size_t grem::resource::Image::getSizeInBytes ( ImageFormat format,
Extent3D size3D,
uint32_t mipLevelCount )
inlinestaticnodiscardconstexpr

Get the size in bytes of an image in a specific non-containerized image format.

Parameters
formatimage format.
size3Dsize of the full image, in pixels.
mipLevelCountnumber of mip levels in the image.
Returns
the total size of the full image, including all layers and mip levels, or 0 if the given format is unknown or containerized.
Exceptions
std::length_errorif the maximum image size was exceeded.

◆ convertPixelComponent()

template<typename OutputComponent, typename InputComponent>
OutputComponent grem::resource::Image::convertPixelComponent ( const InputComponent & value)
inlinestaticnodiscardnoexcept

Convert a single pixel component of a raw image to another pixel component type.

Template Parameters
OutputComponentcomponent type to convert to. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
InputComponentcomponent type to convert from. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
Parameters
valuecomponent value to convert.
Returns
the converted component value.

◆ convertPixel()

template<typename OutputComponent, size_t OutputComponentCount, typename InputComponent, size_t InputComponentCount>
void grem::resource::Image::convertPixel ( byte * output,
const byte * input )
inlinestatic

Convert a single pixel of a raw image to another raw pixel format.

Template Parameters
OutputComponentcomponent type to convert to. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
OutputComponentCountnumber of component channels in the output image. Must be in the range [1, 4] (inclusive).
InputComponentcomponent type to convert from. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
InputComponentCountnumber of component channels in the input image. Must be in the range [1, 4] (inclusive).
Parameters
outputnon-owning pointer to a block of memory containing the output image. Must point to a valid block of memory of at least the size required for a pixel in the specified output pixel format, and must not be nullptr.
inputnon-owning read-only pointer to a block of memory containing the input image. Must point to a valid block of memory of at least the size required for a pixel in the specified input pixel format, and must not be nullptr.
Warning
The referenced input and output memory regions must not overlap.

◆ convertPixels() [1/2]

template<typename OutputComponent, size_t OutputComponentCount, typename InputComponent, size_t InputComponentCount>
void grem::resource::Image::convertPixels ( Extent3D outputSize,
byte * output,
Offset3D outputOffset,
Extent3D inputSize,
const byte * input,
Region3D inputRegion )
inlinestatic

Convert the pixels in a region of a raw image to another raw pixel format.

Template Parameters
OutputComponentcomponent type to convert to. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
OutputComponentCountnumber of component channels in the output image. Must be in the range [1, 4] (inclusive).
InputComponentcomponent type to convert from. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
InputComponentCountnumber of component channels in the input image. Must be in the range [1, 4] (inclusive).
Parameters
outputSizesize of the full mip level in the output image, in pixels.
outputnon-owning pointer to a block of memory containing a full mip level of the output image. Must point to a valid block of memory of at least the size required for the full specified mip level in the specified output pixel format, including all layers, and must not be nullptr.
outputOffsetoffset, in pixels, from the top left corner of the first layer of the output image to start pasting at, where the top left corner of the first layer of the converted image region will begin.
inputSizesize of the full mip level in the input image, in pixels.
inputnon-owning read-only pointer to a block of memory containing a full mip level of the input image. Must point to a valid block of memory of at least the size required for the full specified mip level in the specified input pixel format, including all layers, and must not be nullptr.
inputRegionregion of the input mip level to convert from, relative to the top left corner of its first layer.
Warning
The referenced input and output memory regions must not overlap.

◆ convertPixels() [2/2]

template<typename OutputComponent, size_t OutputComponentCount, typename InputComponent, size_t InputComponentCount>
void grem::resource::Image::convertPixels ( Extent3D size3D,
uint32_t mipLevelCount,
byte * output,
const byte * input )
inlinestatic

Convert all pixels of a full raw image to another raw pixel format.

Template Parameters
OutputComponentcomponent type to convert to. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
OutputComponentCountnumber of component channels in the output image. Must be in the range [1, 4] (inclusive).
InputComponentcomponent type to convert from. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
InputComponentCountnumber of component channels in the input image. Must be in the range [1, 4] (inclusive).
Parameters
size3Dsize of the full input and output images, in pixels and layers.
mipLevelCountnumber of mip levels in the input and output images.
outputnon-owning pointer to a block of memory containing the output image. Must point to a valid block of memory of at least the size required for the full image in the specified output pixel format, including all layers and mip levels, and must not be nullptr.
inputnon-owning read-only pointer to a block of memory containing the input image. Must point to a valid block of memory of at least the size required for the full image in the specified input pixel format, including all layers, and mip levels, and must not be nullptr.
Warning
The referenced input and output memory regions must not overlap.

◆ copyPixels() [1/2]

void grem::resource::Image::copyPixels ( Extent3D outputSize,
byte * output,
Offset3D outputOffset,
Extent3D inputSize,
const byte * input,
Region3D inputRegion,
size_t pixelStride )
inlinestatic

Copy the pixels in a region of a raw image to another image region in the same format.

Parameters
outputSizesize of the full mip level in the output image, in pixels.
outputnon-owning pointer to a block of memory containing a full mip level of the output image. Must point to a valid block of memory of at least the size required for the full specified mip level in the specified output pixel format, including all layers, and must not be nullptr.
outputOffsetoffset, in pixels, from the top left corner of the first layer of the output image to start pasting at, where the top left corner of the first layer of the copied image region will begin.
inputSizesize of the full mip level in the input image, in pixels.
inputnon-owning read-only pointer to a block of memory containing a full mip level of the input image. Must point to a valid block of memory of at least the size required for the full specified mip level in the specified input pixel format, including all layers, and must not be nullptr.
inputRegionregion of the input mip level to copy from, relative to the top left corner of its first layer.
pixelStridesize of a single pixel, in bytes. Must be positive.
Warning
The referenced input and output memory regions must not overlap.

◆ copyPixels() [2/2]

void grem::resource::Image::copyPixels ( Extent3D size3D,
uint32_t mipLevelCount,
byte * output,
const byte * input,
size_t pixelStride )
inlinestatic

Copy all pixels of a full raw image to another image in the same format.

Parameters
size3Dsize of the full input and output images, in pixels and layers.
mipLevelCountnumber of mip levels in the input and output images.
outputnon-owning pointer to a block of memory containing the output image. Must point to a valid block of memory of at least the size required for the full image in the specified output pixel format, including all layers and mip levels, and must not be nullptr.
inputnon-owning read-only pointer to a block of memory containing the input image. Must point to a valid block of memory of at least the size required for the full image in the specified input pixel format, including all layers, and mip levels, and must not be nullptr.
pixelStridesize of a single pixel, in bytes. Must be positive.
Warning
The referenced input and output memory regions must not overlap.

◆ transformPixels() [1/2]

void grem::resource::Image::transformPixels ( Extent3D size,
byte * pixels,
Region3D region,
size_t pixelStride,
auto op )
inlinestatic

Transform the pixels in a region of a raw image by a given operation.

Parameters
sizesize of the full mip level in the image, in pixels.
pixelsnon-owning pointer to a block of memory containing a full mip level of the image to transform. Must point to a valid block of memory of at least the size required for the full specified mip level in the specified pixel format, including all layers, and must not be nullptr.
regionregion, in pixels, relative to the top left corner of the first layer of the image, to transform.
pixelStridesize of a single pixel, in bytes. Must be positive.
optransformation to execute for each pixel in the specified region. Should return void and accept a byte pointer to the pixel's memory.

◆ transformPixels() [2/2]

void grem::resource::Image::transformPixels ( Extent3D size3D,
uint32_t mipLevelCount,
byte * pixels,
size_t pixelStride,
auto op )
inlinestatic

Transform all pixels of a full raw image by a given operation.

Parameters
size3Dsize of the full image, in pixels and layers.
mipLevelCountnumber of mip levels in the image.
pixelsnon-owning pointer to a block of memory containing the image to transform. Must point to a valid block of memory of at least the size required for the full image in the specified pixel format, including all layers and mip levels, and must not be nullptr.
pixelStridesize of a single pixel, in bytes. Must be positive.
optransformation to execute for each pixel. Should return void and accept a byte pointer to the pixel's memory.
Warning
The referenced input and output memory regions must not overlap.

◆ fillPixels() [1/2]

void grem::resource::Image::fillPixels ( Extent3D outputSize,
byte * output,
Region3D outputRegion,
size_t pixelStride,
const byte * inputPixel )
inlinestatic

Set the pixels in a region of a raw image to a specific pixel value.

Parameters
outputSizesize of the full mip level in the output image, in pixels.
outputnon-owning pointer to a block of memory containing a full mip level of the output image. Must point to a valid block of memory of at least the size required for the full specified mip level in the specified output pixel format, including all layers, and must not be nullptr.
outputRegionregion, in pixels, relative to the top left corner of the first layer of the output image, to fill.
pixelStridesize of a single pixel, in bytes. Must be positive.
inputPixelnon-owning read-only pointer to a block of memory containing the input pixel. Must point to a valid block of memory of at least the size required for the stride of one pixel in the specified input pixel format, and must not be nullptr.
Warning
The referenced input and output memory regions must not overlap.

◆ fillPixels() [2/2]

void grem::resource::Image::fillPixels ( Extent3D size3D,
uint32_t mipLevelCount,
byte * output,
size_t pixelStride,
const byte * inputPixel )
inlinestatic

Set all pixels of a full raw image to a specific pixel value.

Parameters
size3Dsize of the full output image, in pixels and layers.
mipLevelCountnumber of mip levels in the output image.
outputnon-owning pointer to a block of memory containing the output image. Must point to a valid block of memory of at least the size required for the full image in the specified output pixel format, including all layers and mip levels, and must not be nullptr.
pixelStridesize of a single pixel, in bytes. Must be positive.
inputPixelnon-owning read-only pointer to a block of memory containing the input pixel. Must point to a valid block of memory of at least the size required for the stride of one pixel in the specified input pixel format, and must not be nullptr.
Warning
The referenced input and output memory regions must not overlap.

◆ setPixelsComponent() [1/2]

template<typename OutputComponent, size_t OutputComponentCount, size_t ComponentIndex>
void grem::resource::Image::setPixelsComponent ( Extent3D outputSize,
byte * output,
Region3D outputRegion,
const OutputComponent & value )
inlinestatic

Set a component of the pixels in a region of a raw image to a specific value.

Template Parameters
OutputComponentcomponent type of the image. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
OutputComponentCountnumber of component channels in the image. Must be in the range [1, 4] (inclusive).
ComponentIndexindex of the component to set the value of. Must be less than OutputComponentCount.
Parameters
outputSizesize of the full mip level in the output image, in pixels.
outputnon-owning pointer to a block of memory containing a full mip level of the output image. Must point to a valid block of memory of at least the size required for the full specified mip level in the specified output pixel format, including all layers, and must not be nullptr.
outputRegionregion, in pixels, relative to the top left corner of the first layer of the output image, to fill.
valuevalue to set the given component of each pixel to.
Warning
The referenced input and output memory regions must not overlap.

◆ setPixelsComponent() [2/2]

template<typename OutputComponent, size_t OutputComponentCount, size_t ComponentIndex>
void grem::resource::Image::setPixelsComponent ( Extent3D size3D,
uint32_t mipLevelCount,
byte * output,
const OutputComponent & value )
inlinestatic

Set a component of all pixels of a full raw image to a specific value.

Template Parameters
OutputComponentcomponent type of the image. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
OutputComponentCountnumber of component channels in the image. Must be in the range [1, 4] (inclusive).
ComponentIndexindex of the component to set the value of. Must be less than OutputComponentCount.
Parameters
size3Dsize of the full output image, in pixels and layers.
mipLevelCountnumber of mip levels in the output image.
outputnon-owning pointer to a block of memory containing the output image. Must point to a valid block of memory of at least the size required for the full image in the specified output pixel format, including all layers and mip levels, and must not be nullptr.
valuevalue to set the given component of each pixel to.
Warning
The referenced input and output memory regions must not overlap.

◆ transformRGBAPixelsFromStraightToPremultipliedAlpha()

template<typename PixelComponent, Color::TransferFunction TransferFunction>
void grem::resource::Image::transformRGBAPixelsFromStraightToPremultipliedAlpha ( Extent3D size3D,
uint32_t mipLevelCount,
byte * pixels )
inlinestatic

Transform all pixels of a full raw RGBA image from straight to pre-multiplied alpha.

Template Parameters
PixelComponentcomponent type of the pixels in the image. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
TransferFunctiontransfer function of the pixels in the image.
Parameters
size3Dsize of the full image, in pixels and layers.
mipLevelCountnumber of mip levels in the image.
pixelsnon-owning pointer to a block of memory containing the image to transform. Must point to a valid block of memory of at least the size required for the full image in the specified pixel format, including all layers and mip levels, and must not be nullptr.

◆ transformRGBAPixelsFromPremultipliedToStraightAlpha()

template<typename PixelComponent, Color::TransferFunction TransferFunction>
void grem::resource::Image::transformRGBAPixelsFromPremultipliedToStraightAlpha ( Extent3D size3D,
uint32_t mipLevelCount,
byte * pixels )
inlinestatic

Transform all pixels of a full raw RGBA image from pre-multiplied to straight alpha.

Template Parameters
PixelComponentcomponent type of the pixels in the image. Must be a valid raw pixel component type (u8norm, float16_t or float32_t).
TransferFunctiontransfer function of the pixels in the image.
Parameters
size3Dsize of the full image, in pixels and layers.
mipLevelCountnumber of mip levels in the image.
pixelsnon-owning pointer to a block of memory containing the image to transform. Must point to a valid block of memory of at least the size required for the full image in the specified pixel format, including all layers and mip levels, and must not be nullptr.

◆ flipVertically()

void grem::resource::Image::flipVertically ( Extent2D size2D,
byte * pixels,
size_t pixelStride )
inlinestatic

Flip a layer of a raw image on the Y axis.

Parameters
size2Dsize of the full image layer, in pixels.
pixelsnon-owning pointer to a block of memory containing the raw image to flip. Must point to a valid block of memory of at least the size required for the full image layer in the specified pixel format, and must not be nullptr.
pixelStridesize of a single pixel in the image layer, in bytes. Must be positive.
Exceptions
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ determineFileType()

ImageFileType grem::resource::Image::determineFileType ( Span< const byte > fileContents)
staticnodiscard

Determine which image file type a file should be parsed as based on the contents at the beginning of the file.

Parameters
fileContentsfile contents to be parsed.
Returns
the determined image file type, or ImageFileType::UNKNOWN if a type could not be determined.

◆ savePNG() [1/2]

void grem::resource::Image::savePNG ( const ImageView & image,
Filesystem & filesystem,
CStringView filepath,
const ImageSavePNGOptions & options = {} )
static

Save an 8-bit-per-channel image to a PNG file.

Parameters
imageview over the image to save.
filesystemfilesystem to save the file to.
filepathoutput filepath at which to save the image.
optionssaving options, see ImageSavePNGOptions.
Note
This function will fail if the image is not in a raw 8-bit unsigned integer format.
Exceptions
File::Erroron failure to create or write to the file.
resource::Erroron failure to write a valid image to the file.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.
Note
Any parent directories of the specified output filepath will be created if they don't already exist.

◆ savePNG() [2/2]

Allocation< byte > grem::resource::Image::savePNG ( const ImageView & image,
const ImageSavePNGOptions & options = {} )
staticnodiscard

Save an 8-bit-per-channel image to an in-memory PNG file.

Parameters
imageview over the image to save.
optionssaving options, see ImageSavePNGOptions.
Returns
a contiguous container of the PNG file contents.
Note
This function will fail if the image is not in a raw 8-bit unsigned integer format.
Exceptions
resource::Erroron failure to write a valid image.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ saveJPEG() [1/2]

void grem::resource::Image::saveJPEG ( const ImageView & image,
Filesystem & filesystem,
CStringView filepath,
const ImageSaveJPEGOptions & options = {} )
static

Save an 8-bit-per-channel image to a JPEG file.

Parameters
imageview over the image to save.
filesystemfilesystem to save the file to.
filepathoutput filepath at which to save the image.
optionssaving options, see ImageSaveJPEGOptions.
Note
This function will fail if the image is not in a raw 8-bit unsigned integer format.
Exceptions
File::Erroron failure to create or write to the file.
resource::Erroron failure to write a valid image to the file.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.
Note
Any parent directories of the specified output filepath will be created if they don't already exist.

◆ saveJPEG() [2/2]

Allocation< byte > grem::resource::Image::saveJPEG ( const ImageView & image,
const ImageSaveJPEGOptions & options = {} )
staticnodiscard

Save an 8-bit-per-channel image to an in-memory JPEG file.

Parameters
imageview over the image to save.
optionssaving options, see ImageSaveJPEGOptions.
Returns
a contiguous container of the JPEG file contents.
Note
This function will fail if the image is not in a raw 8-bit unsigned integer format.
Exceptions
resource::Erroron failure to write a valid image.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ saveHDR() [1/2]

void grem::resource::Image::saveHDR ( const ImageView & image,
Filesystem & filesystem,
CStringView filepath,
const ImageSaveHDROptions & options = {} )
static

Save a floating-point 32-bit-per-channel image to an RGBE/Radiance HDR file.

Parameters
imageview over the image to save.
filesystemfilesystem to save the file to.
filepathoutput filepath at which to save the image.
optionssaving options, see ImageSaveHDROptions.
Note
This function will fail if the image is not in a raw 32-bit floating-point format.
Exceptions
File::Erroron failure to create or write to the file.
resource::Erroron failure to write a valid image to the file.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.
Note
Any parent directories of the specified output filepath will be created if they don't already exist.

◆ saveHDR() [2/2]

Allocation< byte > grem::resource::Image::saveHDR ( const ImageView & image,
const ImageSaveHDROptions & options = {} )
staticnodiscard

Save a floating-point 32-bit-per-channel image to an in-memory RGBE/Radiance HDR file.

Parameters
imageview over the image to save.
optionssaving options, see ImageSaveHDROptions.
Returns
a contiguous container of the HDR file contents.
Note
This function will fail if the image is not in a raw 32-bit floating-point format.
Exceptions
resource::Erroron failure to write a valid image.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ saveKTX2() [1/2]

void grem::resource::Image::saveKTX2 ( const ImageView & image,
Filesystem & filesystem,
CStringView filepath,
const ImageSaveKTX2Options & options = {} )
static

Save an image to a Khronos TeXture, version 2.0 file.

Parameters
imageview over the image to save.
filesystemfilesystem to save the file to.
filepathoutput filepath at which to save the image.
optionssaving options, see ImageSaveKTX2Options.
Exceptions
File::Erroron failure to create or write to the file.
resource::Erroron failure to write a valid image to the file.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.
Note
Any parent directories of the specified output filepath will be created if they don't already exist.

◆ saveKTX2() [2/2]

Allocation< byte > grem::resource::Image::saveKTX2 ( const ImageView & image,
const ImageSaveKTX2Options & options = {} )
staticnodiscard

Save an image to an in-memory Khronos Texture, version 2.0 file.

Parameters
imageview over the image to save.
optionssaving options, see ImageSaveKTX2Options.
Returns
a contiguous container of the KTX2 file contents.
Exceptions
resource::Erroron failure to write a valid image.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ save()

void grem::resource::Image::save ( const ImageView & image,
Filesystem & filesystem,
CStringView filepath,
const ImageSaveOptions & options = {} )
static

Save an image to a file.

If the given filepath has a file extension, then the image will be saved in the file format corresponding to the extension, or throw an error if the image cannot be saved in that format.

Otherwise, the file format will be chosen automatically based on the type and format of the image, and the corresponding file extension will be added to the filepath.

The supported file formats are:

  • JPEG (.jpg/.jpeg)
  • PNG (.png)
  • RGBE/Radiance HDR (.hdr)
  • Khronos TeXture, version 2.0 (.ktx2)
Parameters
imageview over the image to save.
filesystemfilesystem to save the file to.
filepathoutput filepath at which to save the image.
optionssaving options, see ImageSaveOptions.
Exceptions
File::Erroron failure to create or write to the file.
resource::Erroron failure to write a valid image to the file.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.
Note
Any parent directories of the specified output filepath will be created if they don't already exist.

◆ operator ImageView()

grem::resource::Image::operator ImageView ( ) const
inlinenoexcept

Get a read-only view over this image.

Returns
if the image has a value, returns a non-owning read-only view over it. Otherwise, returns a view that doesn't reference an image.

◆ operator ImageReference()

grem::resource::Image::operator ImageReference ( )
inlinenoexcept

Get a view over this image.

Returns
if the image has a value, returns a non-owning view over it. Otherwise, returns a view that doesn't reference an image.

◆ reset()

void grem::resource::Image::reset ( )
inlinenoexcept

Remove the value from this image and reset it to an empty image.

◆ transcodeTo()

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

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 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

◆ transformFromStraightToPremultipliedAlpha()

void grem::resource::Image::transformFromStraightToPremultipliedAlpha ( Color::TransferFunction transferFunction)
inline

Transform the RGBA image pixel colors from straight to pre-multiplied alpha.

Parameters
transferFunctiontransfer function of the pixels stored in the image.
Exceptions
std::invalid_argumentif the image is not in a raw color format with an alpha channel.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ transformFromPremultipliedToStraightAlpha()

void grem::resource::Image::transformFromPremultipliedToStraightAlpha ( Color::TransferFunction transferFunction)
inline

Transform the RGBA image pixel colors from pre-multiplied to straight alpha.

Parameters
transferFunctiontransfer function of the pixels stored in the image.
Exceptions
std::invalid_argumentif the image is not in a raw color format with an alpha channel.
std::length_errorif the maximum image size was exceeded.
std::bad_allocon allocation failure.

◆ getType()

ImageType grem::resource::Image::getType ( ) const
inlinenodiscardnoexcept

Get the type of the image.

Returns
the image type.

◆ getFormat()

ImageFormat grem::resource::Image::getFormat ( ) const
inlinenodiscardnoexcept

Get the format of the image.

Returns
the image format.

◆ getSize2D()

Extent2D grem::resource::Image::getSize2D ( ) const
inlinenodiscardnoexcept

Get the size, in pixels, of the image layers.

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::Image::getSize3D ( ) const
inlinenodiscardnoexcept

Get the size, in pixels, and the depth, in layers, of the image.

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

◆ getWidth()

uint32_t grem::resource::Image::getWidth ( ) const
inlinenodiscardnoexcept

Get the width of the image.

Returns
the width of the image, in pixels.

◆ getHeight()

uint32_t grem::resource::Image::getHeight ( ) const
inlinenodiscardnoexcept

Get the height of the image.

Returns
the height of the image, in pixels.

◆ getDepth()

uint32_t grem::resource::Image::getDepth ( ) const
inlinenodiscardnoexcept

Get the depth of the image.

Returns
the depth of the image, in layers.

◆ getMipLevelCount()

uint32_t grem::resource::Image::getMipLevelCount ( ) const
inlinenodiscardnoexcept

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

Returns
the number of mip levels in the image.

◆ getContents() [1/2]

Span< byte > grem::resource::Image::getContents ( )
inlinenodiscardnoexcept

Get the data of this image.

Returns
a view over the image data.
See also
getType()
getFormat()
getWidth()
getHeight()
getDepth()
data()
size()

◆ getContents() [2/2]

Span< const byte > grem::resource::Image::getContents ( ) const
inlinenodiscardnoexcept

Get the data of this image.

Returns
a read-only view over the image data.
See also
getType()
getFormat()
getWidth()
getHeight()
getDepth()
data()
size()

◆ data() [1/2]

byte * grem::resource::Image::data ( )
inlinenodiscardnoexcept

Get a pointer to the data of this image.

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

◆ data() [2/2]

const byte * grem::resource::Image::data ( ) const
inlinenodiscardnoexcept

Get a pointer to the data of this image.

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

◆ size()

size_t grem::resource::Image::size ( ) const
inlinenodiscardnoexcept

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::Image::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() [1/2]

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

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.

◆ getPixel() [2/2]

ImageReference grem::resource::Image::getPixel ( Offset3D position,
uint32_t mipLevel = 0 )
inlinenodiscard

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 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() [1/2]

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

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.

◆ getLayer() [2/2]

ImageReference grem::resource::Image::getLayer ( uint32_t layer,
uint32_t mipLevel = 0 )
inlinenodiscard

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 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() [1/2]

ImageView grem::resource::Image::getMipLevel ( uint32_t mipLevel) const
inlinenodiscard

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.

◆ getMipLevel() [2/2]

ImageReference grem::resource::Image::getMipLevel ( uint32_t mipLevel)
inlinenodiscard

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 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/4]

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

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/4]

ImageReference grem::resource::Image::getMipLevels ( uint32_t firstMipLevel,
uint32_t mipLevels )
inlinenodiscard

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 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() [3/4]

ImageView grem::resource::Image::getMipLevels ( uint32_t firstMipLevel) const
inlinenodiscard

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.

◆ getMipLevels() [4/4]

ImageReference grem::resource::Image::getMipLevels ( uint32_t firstMipLevel)
inlinenodiscard

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 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::Image::getPadded ( uint32_t paddingLeft,
uint32_t paddingRight,
uint32_t paddingBottom,
uint32_t paddingTop ) const
inlinenodiscard

Get a uniformly padded version of the image.

The image must be in a raw format.

Parameters
paddingLeftpadding to add on the left side of the image, in pixels.
paddingRightpadding to add on the right side of the image, in pixels.
paddingBottompadding to add on the bottom of the image, in pixels.
paddingToppadding to add on the top 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.

◆ getPadded() [2/2]

Image grem::resource::Image::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: