template<typename T, unsigned int N = 1>
OrbitEngine::Graphics::Bitmap class

A 2D bitmap image with N channels of elements T.

Example: filling a Bitmap with magenta and saving it to the disk

Bitmap<unsigned char, 3> bitmap(128, 128); // or BitmapRGB

for(int y = 0; y < bitmap.height(); y++) {
    for(int x = 0; x < bitmap.width(); x++) {
        bitmap(x, y, 0) = 255;
        bitmap(x, y, 1) = 0;
        bitmap(x, y, 2) = 255;
    }
}

bitmap.savePNG("magenta.png");

Derived classes

template<typename T, unsigned int N = 1>
class BitmapAtlas
A 2D bitmap atlas.

Public static functions

static auto Load(const std::string& path) -> Bitmap<T, N>
Loads an image into a Bitmap.
static auto FromTexture(Texture* texture) -> Bitmap<T, N>
Generate a Bitmap from a Texture.

Constructors, destructors, conversion operators

Bitmap()
Creates an invalid bitmap.
Bitmap(unsigned int w, unsigned int h)
Creates an empty WxH bitmap with N channels.
Bitmap(unsigned int w, unsigned int h, T* source)
Creates a WxH bitmap with N channels copying the pixels from source.
Bitmap(T* source, unsigned int w, unsigned int h)
Creates a WxH bitmap with N channels using the pixels from source. The bitmap will not take ownership of the input pixels.
Bitmap(const Bitmap<T, N>& other)
copy constructor
Bitmap(Bitmap<T, N>&& other) noexcept
move constructor
~Bitmap()
destructor

Public functions

auto valid() const -> bool
returns whether the bitmap has valid data
auto width() const -> unsigned int
width in pixels
auto height() const -> unsigned int
height in pixels
auto bpp() const -> unsigned int
bits per pixel
auto operator()(int x, int y, int ith) -> T&
reference to the ith element at x, y
auto operator()(int x, int y, int ith) const -> const T&
const reference to the ith element at x, y
auto operator=(Bitmap<T, N>&& other) -> Bitmap<T, N>& noexcept
move assignment operator
auto data() const -> T*
pixel data
void write(const Bitmap<T, N>& input, int x, int y)
Writes the input Bitmap at x, y.
void fill(const T input[N])
Fill the entire bitmap with the provided elements.
void clear()
Clear the entire bitmap (sets all the pixels to zero)
void flipVertically()
In-place flip vertically.
void flipHorizontally()
In-place flip horizontally.
void flipBoth()
In-place flip horizontally and vertically.
auto rotate90clockwise() const -> Bitmap<T, N>
Returns a rotated copy of the bitmap 90 degrees clockwise.
auto crop(int x, int y, unsigned int w, unsigned int h) const -> Bitmap<T, N>
Crop the bitmap.
void destroy()
Deletes the pixel data and makes the bitmap invalid.
auto savePNG(const std::string& path) const -> bool
Saves the bitmap as a PNG file.
auto toTexture(const TextureSampleProperties& sample_properties = TextureSampleProperties()) -> Texture*
Generate a Texture from the Bitmap.

Protected variables

T* m_Pixels
unsigned int m_Width
unsigned int m_Height
bool m_Ownership
Determinates if the Bitmap object owns m_Pixels and it should delete them after its destruction.

Function documentation

template<typenameT, unsigned intN>
static Bitmap<T, N> OrbitEngine::Graphics::Bitmap<T, N>::Load(const std::string& path)

Loads an image into a Bitmap.

template<typenameT, unsigned intN>
OrbitEngine::Graphics::Bitmap<T, N>::Bitmap(unsigned int w, unsigned int h, T* source)

Creates a WxH bitmap with N channels copying the pixels from source.

source must have at least W*H*N elements

template<typenameT, unsigned intN>
OrbitEngine::Graphics::Bitmap<T, N>::Bitmap(T* source, unsigned int w, unsigned int h)

Creates a WxH bitmap with N channels using the pixels from source. The bitmap will not take ownership of the input pixels.

source must have at least W*H*N elements

template<typenameT, unsigned intN>
void OrbitEngine::Graphics::Bitmap<T, N>::write(const Bitmap<T, N>& input, int x, int y)

Writes the input Bitmap at x, y.

If the coordinates provided are outside bounds, the function will only write the pixels that remain inside the boundaries

template<typenameT, unsigned intN>
bool OrbitEngine::Graphics::Bitmap<T, N>::savePNG(const std::string& path) const

Saves the bitmap as a PNG file.

template<typenameT, unsigned intN>
Texture* OrbitEngine::Graphics::Bitmap<T, N>::toTexture(const TextureSampleProperties& sample_properties = TextureSampleProperties())

Generate a Texture from the Bitmap.