template<class T>
glpp::core::object::image_t class

storage class for image data in cpu memory.

Template parameters
T pixel format

The image_t can be used to load and store images from disk to cpu memory. The internal pixel format is specified by the template parameter T. Scalar arithmetic types and vector types from the glm library can be used for T.

Public types

using const_iterator = typename std::vector<value_type>::const_iterator
const iterator type
using iterator = typename std::vector<value_type>::iterator
iterator type
using value_type = T
type alias value_type

Constructors, destructors, conversion operators

image_t() defaulted constexpr
default constructor
image_t(const image_t& cpy) defaulted constexpr
copy constructor
image_t(image_t&& mov) defaulted constexpr noexcept
move constructor
template<class U>
image_t(const image_t<U>& conv) explicit constexpr
conversion operator
image_t(size_t width, size_t height) constexpr
constructor with dimensions
image_t(size_t width, size_t height, const value_type value) constexpr
constructor with dimensions and default value
image_t(size_t width, size_t height, const value_type* begin) constexpr
constructor with dimensions and pointer to buffer
image_t(size_t width, size_t height, std::initializer_list<T> init_list) constexpr
constructor with dimensions and initializer_list
template<class Range, std::enable_if_t<std::is_same_v<typename Range::value_type, value_type>, int> = 0>
image_t(size_t width, size_t height, const Range& range) constexpr
constructor with dimensions and generic container reference
template<class Iterator, std::enable_if_t<std::is_same_v<typename std::iterator_traits<Iterator>::value_type, value_type>, int> = 0>
image_t(size_t width, size_t height, const Iterator& begin, const Iterator& end) constexpr
constructor with dimensions and iterator range
image_t(const char* filename)
construct image_t from file

Public functions

auto at(size_t x, size_t y) -> value_type& constexpr
get pixel
auto at(size_t x, size_t y) const -> constvalue_type& constexpr
get pixel
auto begin() -> iterator constexpr noexcept
get iterator to pixel data
auto begin() const -> const_iterator constexpr noexcept
get iterator to pixel data
auto channels() const -> int constexpr noexcept
get number of color channels
auto data() -> T* constexpr noexcept
pointer to pixel data
auto data() const -> const T* constexpr noexcept
pointer to pixel data
auto end() -> iterator constexpr noexcept
get iterator to end of pixel data
auto end() const -> const_iterator constexpr noexcept
get iterator to end of pixel data
auto format() const -> image_format_t constexpr noexcept
get image format
auto get(size_t x, size_t y) -> value_type& constexpr
get pixel
auto get(size_t x, size_t y) const -> constvalue_type& constexpr
get pixel
auto height() const -> size_t constexpr noexcept
get height
void load(const char* filename)
load an image from file
auto operator=(const image_t& cpy) -> image_t& defaulted constexpr
copy assigment operator
auto operator=(image_t&& mov) -> image_t& defaulted constexpr noexcept
move assignment operator
auto resize(size_t width, size_t height) const -> image_t
resize image
auto size() const -> size_t constexpr noexcept
get size
auto type() const -> GLenum constexpr noexcept
get base type
auto update(size_t x, size_t y, const image_t<T>& update) -> image_t& constexpr noexcept
update subimage
auto width() const -> size_t constexpr noexcept
get width
void write(const char* filename) const
write image to file

Function documentation

template<class T>
glpp::core::object::image_t<T>::image_t() defaulted constexpr

default constructor

The default constructor will create an empty image with the dimensions [0, 0].

template<class T>
glpp::core::object::image_t<T>::image_t(const image_t& cpy) defaulted constexpr

copy constructor

The image_t type is copy-constructible.

template<class T>
glpp::core::object::image_t<T>::image_t(image_t&& mov) defaulted constexpr noexcept

move constructor

The image_t type is move-constructible. The image_t will be constructed with the contents of mov. The mov object is in an invalid state after the call of the constructor.

template<class T>
template<class U>
glpp::core::object::image_t<T>::image_t(const image_t<U>& conv) explicit constexpr

conversion operator

Parameters
conv [in] image_t object to get pixel values and dimensions from

The convertion operator will initialise the image_t with the contents of conv. The pixel values of conv will be converted according to the pixel format of conv [U] to the pixel format of the image_t [T].

template<class T>
glpp::core::object::image_t<T>::image_t(size_t width, size_t height) constexpr

constructor with dimensions

Parameters
width [in] new width of image_t
height [in] new height of image_t

This constructor will initialise a image_t with the dimensions of [width, height] and zero values for the pixels values.

template<class T>
glpp::core::object::image_t<T>::image_t(size_t width, size_t height, const value_type value) constexpr

constructor with dimensions and default value

Parameters
width [in] new width of image_t
height [in] new height of image_t
value [in] default value for pixel data

This constructor will initialise a image_t with the dimensions of [width, height] and pixels values matching the value parameter.

template<class T>
glpp::core::object::image_t<T>::image_t(size_t width, size_t height, const value_type* begin) constexpr

constructor with dimensions and pointer to buffer

Parameters
width [in] new width of image_t
height [in] new height of image_t
begin [in] pointer to pixel data

This constructor will initialise a image_t with the dimensions of [width, height]. The pixel data will be copied from the position pointed to by begin.

template<class T>
glpp::core::object::image_t<T>::image_t(size_t width, size_t height, std::initializer_list<T> init_list) constexpr

constructor with dimensions and initializer_list

Parameters
width [in] new width of image_t
height [in] new height of image_t
init_list [in] initializer_list with values

This constructor will initialise a image_t with the dimensions of [width, height]. The pixel data will be copied from the initializer_list init_list

template<class T>
template<class Range, std::enable_if_t<std::is_same_v<typename Range::value_type, value_type>, int> = 0>
glpp::core::object::image_t<T>::image_t(size_t width, size_t height, const Range& range) constexpr

constructor with dimensions and generic container reference

Parameters
width [in] new width of image_t
height [in] new height of image_t
range [in] container with pixel data

This constructor will initialise a image_t with the dimensions of [width, height]. The pixel data will be copied from a range or forward iteratable container.

template<class T>
template<class Iterator, std::enable_if_t<std::is_same_v<typename std::iterator_traits<Iterator>::value_type, value_type>, int> = 0>
glpp::core::object::image_t<T>::image_t(size_t width, size_t height, const Iterator& begin, const Iterator& end) constexpr

constructor with dimensions and iterator range

Parameters
width [in] new width of image_t
height [in] new height of image_t
begin [in] begin of init range
end [in] end of init range

This constructor will initialise a image_t with the dimensions of [width, height]. The pixel data will be copied from the range between begin and end, including begin and excluding end.

template<class T>
glpp::core::object::image_t<T>::image_t(const char* filename)

construct image_t from file

Parameters
filename [in] name or path of file to load

This constructor will load a image from file. The width and height is fetched from the file. If the pixel format of the file does not match the one of the image_t template parameter, the pixel data will be converted. To use this function it is required to link against glpp::image.

template<class T>
value_type& glpp::core::object::image_t<T>::at(size_t x, size_t y) constexpr

get pixel

Parameters
x [in] x coordinate of pixel to fetch
y [in] y coordinate of pixel to fetch

Get reference the data of a single pixel. This function will perform bounds checking and throw if x and y are no valid coordinates with respect to the image.

template<class T>
constvalue_type& glpp::core::object::image_t<T>::at(size_t x, size_t y) const constexpr

get pixel

Parameters
x [in] x coordinate of pixel to fetch
y [in] y coordinate of pixel to fetch

Get reference the data of a single pixel. This function will perform bounds checking and throw if x and y are no valid coordinates with respect to the image.

template<class T>
iterator glpp::core::object::image_t<T>::begin() constexpr noexcept

get iterator to pixel data

Returns random access iterator to the first pixel in the image.

template<class T>
const_iterator glpp::core::object::image_t<T>::begin() const constexpr noexcept

get iterator to pixel data

Returns random access iterator to the first pixel in the image.

template<class T>
int glpp::core::object::image_t<T>::channels() const constexpr noexcept

get number of color channels

Returns the number of color channels present in the picture. Can be 1, 2, 3 or 4.

template<class T>
T* glpp::core::object::image_t<T>::data() constexpr noexcept

pointer to pixel data

Returns a pointer to the underlying memory of the pixel data.

template<class T>
const T* glpp::core::object::image_t<T>::data() const constexpr noexcept

pointer to pixel data

Returns a pointer to the underlying memory of the pixel data.

template<class T>
iterator glpp::core::object::image_t<T>::end() constexpr noexcept

get iterator to end of pixel data

Returns iterator referring to the past-the-end pixel of the image.

template<class T>
const_iterator glpp::core::object::image_t<T>::end() const constexpr noexcept

get iterator to end of pixel data

Returns iterator referring to the past-the-end pixel of the image.

template<class T>
image_format_t glpp::core::object::image_t<T>::format() const constexpr noexcept

get image format

Returns the format description value of the used pixel format.

template<class T>
value_type& glpp::core::object::image_t<T>::get(size_t x, size_t y) constexpr

get pixel

Parameters
x [in] x coordinate of pixel to fetch
y [in] y coordinate of pixel to fetch

Get reference the data of a single pixel.

template<class T>
constvalue_type& glpp::core::object::image_t<T>::get(size_t x, size_t y) const constexpr

get pixel

Parameters
x [in] x coordinate of pixel to fetch
y [in] y coordinate of pixel to fetch

Get reference the data of a single pixel.

template<class T>
void glpp::core::object::image_t<T>::load(const char* filename)

load an image from file

Parameters
filename [in] name or path of file to load

This function will load a image from file and overwrite the members of this class. The width and height is fetched from the file. If the pixel format of the file does not match the one of the image_t template parameter, the pixel data will be converted. To use this function it is required to link against glpp::image.

template<class T>
image_t& glpp::core::object::image_t<T>::operator=(const image_t& cpy) defaulted constexpr

copy assigment operator

The image_t type is copy-assignable.

template<class T>
image_t& glpp::core::object::image_t<T>::operator=(image_t&& mov) defaulted constexpr noexcept

move assignment operator

The image_t type is move-assignable. The image_t will be constructed with the contents of mov. The mov object is in an invalid state after the call of the move assignment operator.

template<class T>
image_t glpp::core::object::image_t<T>::resize(size_t width, size_t height) const

resize image

Parameters
width [in] width of the resulting image
height [in] height of the resulting image
Returns newly allocated image with the dimensions [width, height]

Returns a copy of the stored image resize to fit the resulution supplied by the paramets.

template<class T>
GLenum glpp::core::object::image_t<T>::type() const constexpr noexcept

get base type

Returns the OpenGL specifier for the base type of the pixel format.

template<class T>
image_t& glpp::core::object::image_t<T>::update(size_t x, size_t y, const image_t<T>& update) constexpr noexcept

update subimage

Parameters
x [in] x position of the patch that shall be updated
y [in] y position of the patch that shall be updated
update [in] image with new pixel values
Returns reference to self to enable chaining

This function will overwrite a patch of the image. This patch starts at [x, y] and extends in positive x and y direction. The width of the patch is smaller or equal [update.width(), update.height()]. If [x, y] is out side of the image, no pixels will be updated. If the patch would extend over the right or bottom border, the update image will be cropped to match the bounds of this image.

template<class T>
void glpp::core::object::image_t<T>::write(const char* filename) const

write image to file

Parameters
filename [in] name or path of file to write

This function will write the contents of this class to a file. To use this function it is required to link against glpp::image.