template<UnsignedInt dimensions>
Magnum::Image class

Image.

Stores multi-dimensional image data together with layout and pixel format description. See ImageView for a non-owning alternative.

This class can act as a drop-in replacement for ImageView and Trade::ImageData APIs and is implicitly convertible to ImageView. Particular graphics API wrappers provide additional image classes, for example GL::BufferImage. See also CompressedImage for equivalent functionality targeted on compressed image formats.

Basic usage

The image takes ownership of a passed Corrade::Containers::Array, together with storing image size and one of the generic PixelFormat values:

Containers::Array<char> data;
Image2D image{PixelFormat::RGBA8Unorm, {512, 256}, std::move(data)};

On construction, the image internally calculates pixel size corresponding to given pixel format using pixelSize(). This value is needed to check that the passed data array is large enough and is also required by most image manipulation operations.

It's also possible to create just an image placeholder, storing only the image properties without data or size. That is useful for example to specify desired format of image queries in graphics APIs:

GL::Texture2D texture;
Image2D image = texture.image(0, {GL::PixelFormat::DepthComponent,
                                  GL::PixelType::UnsignedInt});

As with ImageView, this class supports extra storage parameters and implementation-specific pixel format specification. See the ImageView documentation for more information.

Public types

enum (anonymous): UnsignedInt { Dimensions = dimensions }

Constructors, destructors, conversion operators

Image(PixelStorage storage, PixelFormat format, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept
Constructor.
Image(PixelFormat format, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept
Constructor.
Image(PixelStorage storage, PixelFormat format) noexcept
Construct an image placeholder.
Image(PixelFormat format) noexcept
Construct an image placeholder.
Image(PixelStorage storage, UnsignedInt format, UnsignedInt formatExtra, UnsignedInt pixelSize, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept
Construct an image with implementation-specific pixel format.
Image(PixelStorage storage, PixelFormat format, UnsignedInt formatExtra, UnsignedInt pixelSize, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept
Image(PixelStorage storage, UnsignedInt format, UnsignedInt formatExtra, UnsignedInt pixelSize) explicit noexcept
Construct an image placeholder with implementation-specific pixel format.
Image(PixelStorage storage, PixelFormat format, UnsignedInt formatExtra, UnsignedInt pixelSize) explicit noexcept
template<class T, class U>
Image(PixelStorage storage, T format, U formatExtra, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept
Construct an image with implementation-specific pixel format.
template<class T>
Image(PixelStorage storage, T format, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept
Construct an image with implementation-specific pixel format.
template<class T, class U>
Image(T format, U formatExtra, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept
Construct an image with implementation-specific pixel format.
template<class T>
Image(T format, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept
Construct an image with implementation-specific pixel format.
template<class T, class U>
Image(PixelStorage storage, T format, U formatExtra) noexcept
Construct an image placeholder with implementation-specific pixel format.
template<class T, class U>
Image(T format, U formatExtra) noexcept
Construct an image placeholder with implementation-specific pixel format.
template<class T>
Image(PixelStorage storage, T format) noexcept
Construct an image placeholder with implementation-specific pixel format.
template<class T>
Image(T format) noexcept
Construct an image placeholder with implementation-specific pixel format.
Image(const Image<dimensions>&) deleted
Copying is not allowed.
Image(Image<dimensions>&& other) noexcept
Move constructor.
operator ImageView<dimensions>() const
Conversion to view.

Public functions

auto operator=(const Image<dimensions>&) -> Image<dimensions>& deleted
Copying is not allowed.
auto operator=(Image<dimensions>&& other) -> Image<dimensions>& noexcept
Move assignment.
auto storage() const -> PixelStorage
Storage of pixel data.
auto format() const -> PixelFormat
Format of pixel data.
auto formatExtra() const -> UnsignedInt
Additional pixel format specifier.
auto type() const -> GL::PixelType deprecated
Data type of pixel data.
auto pixelSize() const -> UnsignedInt
Pixel size (in bytes)
auto size() const -> VectorTypeFor<dimensions, Int>
Image size.
auto dataProperties() const -> std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>>
Image data properties.
auto data() & -> Containers::ArrayView<char>
Raw data.
auto data() && -> Containers::ArrayView<char> deleted
auto data() const & -> Containers::ArrayView<const char>
auto data() const && -> Containers::ArrayView<const char> deleted
template<class T = char>
auto data() -> T*
template<class T = char>
auto data() const -> const T*
template<class T, class U>
void setData(PixelStorage storage, T format, U formatExtra, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) deprecated
Set image data.
template<class T, class U>
void setData(T format, U formatExtra, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) deprecated
Set image data.
auto release() -> Containers::Array<char>
Release data storage.

Enum documentation

template<UnsignedInt dimensions>
enum Magnum::Image<dimensions>::(anonymous): UnsignedInt

Enumerators
Dimensions

Image dimension count

Function documentation

template<UnsignedInt dimensions>
Magnum::Image<dimensions>::Image(PixelStorage storage, PixelFormat format, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept

Constructor.

Parameters
storage Storage of pixel data
format Format of pixel data
size Image size
data Image data

The data array is expected to be of proper size for given parameters.

template<UnsignedInt dimensions>
Magnum::Image<dimensions>::Image(PixelFormat format, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept

Constructor.

Parameters
format Format of pixel data
size Image size
data Image data

Equivalent to calling Image(PixelStorage, PixelFormat, const VectorTypeFor<dimensions, Int>&, Containers::Array<char>&&) with default-constructed PixelStorage.

template<UnsignedInt dimensions>
Magnum::Image<dimensions>::Image(PixelStorage storage, PixelFormat format) noexcept

Construct an image placeholder.

Parameters
storage Storage of pixel data
format Format of pixel data

Size is set to zero and data pointer to nullptr. Move over a non-empty instance to make it useful.

template<UnsignedInt dimensions>
Magnum::Image<dimensions>::Image(PixelFormat format) noexcept

Construct an image placeholder.

Parameters
format Format of pixel data

Equivalent to calling Image(PixelStorage, PixelFormat) with default-constructed PixelStorage.

template<UnsignedInt dimensions>
Magnum::Image<dimensions>::Image(PixelStorage storage, UnsignedInt format, UnsignedInt formatExtra, UnsignedInt pixelSize, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept

Construct an image with implementation-specific pixel format.

Parameters
storage Storage of pixel data
format Format of pixel data
formatExtra Additional pixel format specifier
pixelSize Size of a pixel in given format
size Image size
data Image data

Unlike with Image(PixelStorage, PixelFormat, const VectorTypeFor<dimensions, Int>&, Containers::Array<char>&&), where pixel size is calculated automatically using pixelSize(PixelFormat), this allows you to specify an implementation-specific pixel format and pixel size directly. Uses pixelFormatWrap() internally to wrap format in PixelFormat.

The data array is expected to be of proper size for given parameters.

template<UnsignedInt dimensions>
Magnum::Image<dimensions>::Image(PixelStorage storage, PixelFormat format, UnsignedInt formatExtra, UnsignedInt pixelSize, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Equivalent to the above for format already wrapped with pixelFormatWrap().

template<UnsignedInt dimensions>
Magnum::Image<dimensions>::Image(PixelStorage storage, UnsignedInt format, UnsignedInt formatExtra, UnsignedInt pixelSize) explicit noexcept

Construct an image placeholder with implementation-specific pixel format.

Parameters
storage Storage of pixel data
format Format of pixel data
formatExtra Additional pixel format specifier
pixelSize Size of a pixel in given format

Unlike with Image(PixelStorage, PixelFormat), where pixel size is calculated automatically using pixelSize(PixelFormat), this allows you to specify an implementation-specific pixel format and pixel size directly. Uses pixelFormatWrap() internally to wrap format in PixelFormat.

template<UnsignedInt dimensions>
Magnum::Image<dimensions>::Image(PixelStorage storage, PixelFormat format, UnsignedInt formatExtra, UnsignedInt pixelSize) explicit noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Equivalent to the above for format already wrapped with pixelFormatWrap().

template<UnsignedInt dimensions> template<class T, class U>
Magnum::Image<dimensions>::Image(PixelStorage storage, T format, U formatExtra, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept

Construct an image with implementation-specific pixel format.

Parameters
storage Storage of pixel data
format Format of pixel data
formatExtra Additional pixel format specifier
size Image size
data Image data

Uses ADL to find a corresponding pixelSize(T, U) overload, then calls Image(PixelStorage, UnsignedInt, UnsignedInt, UnsignedInt, const VectorTypeFor<dimensions, Int>&, Containers::Array<char>&&) with calculated pixel size.

template<UnsignedInt dimensions> template<class T>
Magnum::Image<dimensions>::Image(PixelStorage storage, T format, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept

Construct an image with implementation-specific pixel format.

Parameters
storage Storage of pixel data
format Format of pixel data
size Image size
data Image data

Uses ADL to find a corresponding pixelSize(T) overload, then calls Image(PixelStorage, UnsignedInt, UnsignedInt, UnsignedInt, const VectorTypeFor<dimensions, Int>&, Containers::Array<char>&&) with calculated pixel size and formatExtra set to 0.

template<UnsignedInt dimensions> template<class T, class U>
Magnum::Image<dimensions>::Image(T format, U formatExtra, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept

Construct an image with implementation-specific pixel format.

Parameters
format Format of pixel data
formatExtra Additional pixel format specifier
size Image size
data Image data

Equivalent to calling Image(PixelStorage, T, U, const VectorTypeFor<dimensions, Int>&, Containers::Array<char>&&) with default-constructed PixelStorage.

template<UnsignedInt dimensions> template<class T>
Magnum::Image<dimensions>::Image(T format, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data) explicit noexcept

Construct an image with implementation-specific pixel format.

Parameters
format Format of pixel data
size Image size
data Image data

Equivalent to calling Image(PixelStorage, T, const VectorTypeFor<dimensions, Int>&, Containers::Array<char>&&) with default-constructed PixelStorage.

template<UnsignedInt dimensions> template<class T, class U>
Magnum::Image<dimensions>::Image(PixelStorage storage, T format, U formatExtra) noexcept

Construct an image placeholder with implementation-specific pixel format.

Parameters
storage Storage of pixel data
format Format of pixel data
formatExtra Additional pixel format specifier

Uses ADL to find a corresponding pixelSize(T, U) overload, then calls Image(PixelStorage, UnsignedInt, UnsignedInt, UnsignedInt) with calculated pixel size.

template<UnsignedInt dimensions> template<class T, class U>
Magnum::Image<dimensions>::Image(T format, U formatExtra) noexcept

Construct an image placeholder with implementation-specific pixel format.

Parameters
format Format of pixel data
formatExtra Additional pixel format specifier

Equivalent to calling Image(PixelStorage, T, U) with default-constructed PixelStorage.

template<UnsignedInt dimensions> template<class T>
Magnum::Image<dimensions>::Image(PixelStorage storage, T format) noexcept

Construct an image placeholder with implementation-specific pixel format.

Parameters
storage Storage of pixel data
format Format of pixel data

Uses ADL to find a corresponding pixelSize(T) overload, then calls Image(PixelStorage, UnsignedInt, UnsignedInt, UnsignedInt) with calculated pixel size and formatExtra set to 0.

template<UnsignedInt dimensions> template<class T>
Magnum::Image<dimensions>::Image(T format) noexcept

Construct an image placeholder with implementation-specific pixel format.

Parameters
format Format of pixel data

Equivalent to calling Image(PixelStorage, T) with default-constructed PixelStorage.

template<UnsignedInt dimensions>
PixelFormat Magnum::Image<dimensions>::format() const

Format of pixel data.

Returns either a defined value from the PixelFormat enum or a wrapped implementation-specific value. Use isPixelFormatImplementationSpecific() to distinguish the case and pixelFormatUnwrap() to extract an implementation-specific value, if needed.

template<UnsignedInt dimensions>
UnsignedInt Magnum::Image<dimensions>::formatExtra() const

Additional pixel format specifier.

Some implementations (such as OpenGL) define a pixel format using two values. This field contains the second implementation-specific value verbatim, if any. See format() for more information.

template<UnsignedInt dimensions>
GL::PixelType Magnum::Image<dimensions>::type() const

Data type of pixel data.

template<UnsignedInt dimensions>
UnsignedInt Magnum::Image<dimensions>::pixelSize() const

Pixel size (in bytes)

template<UnsignedInt dimensions>
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> Magnum::Image<dimensions>::dataProperties() const

Image data properties.

See PixelStorage::dataProperties() for more information.

template<UnsignedInt dimensions>
Containers::ArrayView<char> Magnum::Image<dimensions>::data() &

Raw data.

template<UnsignedInt dimensions>
Containers::ArrayView<char> Magnum::Image<dimensions>::data() && deleted

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<UnsignedInt dimensions>
Containers::ArrayView<const char> Magnum::Image<dimensions>::data() const &

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<UnsignedInt dimensions>
Containers::ArrayView<const char> Magnum::Image<dimensions>::data() const && deleted

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<UnsignedInt dimensions> template<class T = char>
T* Magnum::Image<dimensions>::data()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<UnsignedInt dimensions> template<class T = char>
const T* Magnum::Image<dimensions>::data() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<UnsignedInt dimensions> template<class T, class U>
void Magnum::Image<dimensions>::setData(PixelStorage storage, T format, U formatExtra, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data)

Set image data.

Parameters
storage Storage of pixel data
format Format of pixel data
formatExtra Additional pixel format specifier
size Image size
data Image data

Deletes previous data and replaces them with new. The data array is expected to be of proper size for given parameters.

template<UnsignedInt dimensions> template<class T, class U>
void Magnum::Image<dimensions>::setData(T format, U formatExtra, const VectorTypeFor<dimensions, Int>& size, Containers::Array<char>&& data)

Set image data.

Parameters
format Format of pixel data
formatExtra Additional pixel format specifier
size Image size
data Image data

Equivalent to calling setData(PixelStorage, T, U, const VectorTypeFor<dimensions, Int>&, Containers::Array<char>&&) with default-constructed PixelStorage.

template<UnsignedInt dimensions>
Containers::Array<char> Magnum::Image<dimensions>::release()

Release data storage.

Releases the ownership of the data array and resets size() to zero. The state afterwards is equivalent to moved-from state.