Avara3D 0.2.0
C++ API reference
a3d::Image Class Reference

Owns decoded pixel data and its dimensions. More...

#include <a3d/Image.h>

Public Member Functions

 Image (const std::filesystem::path &path, bool flipVertical=true, bool flipHorizontal=false)
 Loads and decodes an image from path. More...
 
 Image (const Buffer &buffer, bool flipVertical=true, bool flipHorizontal=false)
 Decodes encoded image data from buffer. More...
 
 Image (std::unique_ptr< Buffer > buffer, unsigned width, unsigned height, unsigned bytesPerPixel, bool flipVertical=true, bool flipHorizontal=false)
 Takes ownership of an existing pixel buffer and its dimensions. More...
 
unsigned width () const
 Returns the image width in pixels. More...
 
unsigned height () const
 Returns the image height in pixels. More...
 
unsigned bytesPerPixel () const
 Returns the number of bytes stored for each pixel. More...
 
std::unique_ptr< Imageinverted () const
 Returns a new Image with its color bytes inverted. More...
 
const Bufferbuffer () const
 Returns the Buffer containing the owned pixel data. More...
 
bool writePNG (const std::filesystem::path &path) const
 Writes the image pixels to a PNG file at path. More...
 

Detailed Description

Owns decoded pixel data and its dimensions.

Images decoded from encoded file or Buffer data are converted to four-byte RGBA pixels. They are vertically flipped by default to match A3D texture coordinates. Copying an Image deep-copies its pixel buffer; moving transfers the owned storage.

Definition at line 27 of file Image.h.

Constructor & Destructor Documentation

◆ Image() [1/3]

a3d::Image::Image ( const std::filesystem::path &  path,
bool  flipVertical = true,
bool  flipHorizontal = false 
)
explicit

Loads and decodes an image from path.

Parameters
flipVerticalvertically flips the decoded pixels when true.
flipHorizontalhorizontally mirrors the decoded pixels when true.
Exceptions
std::runtime_errorif the file cannot be read or its image data cannot be decoded.

◆ Image() [2/3]

a3d::Image::Image ( const Buffer buffer,
bool  flipVertical = true,
bool  flipHorizontal = false 
)
explicit

Decodes encoded image data from buffer.

Parameters
flipVerticalvertically flips the decoded pixels when true.
flipHorizontalhorizontally mirrors the decoded pixels when true.
Exceptions
std::runtime_errorif the image data cannot be decoded.

◆ Image() [3/3]

a3d::Image::Image ( std::unique_ptr< Buffer buffer,
unsigned  width,
unsigned  height,
unsigned  bytesPerPixel,
bool  flipVertical = true,
bool  flipHorizontal = false 
)

Takes ownership of an existing pixel buffer and its dimensions.

The caller is responsible for supplying a buffer compatible with width, height, and bytesPerPixel.

Parameters
flipVerticalvertically flips the pixels when true.
flipHorizontalhorizontally mirrors the pixels when true.
Exceptions
std::runtime_errorif horizontal flipping is requested for data that is not four bytes per pixel.

Member Function Documentation

◆ buffer()

const Buffer & a3d::Image::buffer ( ) const

Returns the Buffer containing the owned pixel data.

◆ bytesPerPixel()

unsigned a3d::Image::bytesPerPixel ( ) const

Returns the number of bytes stored for each pixel.

◆ height()

unsigned a3d::Image::height ( ) const

Returns the image height in pixels.

◆ inverted()

std::unique_ptr< Image > a3d::Image::inverted ( ) const

Returns a new Image with its color bytes inverted.

For four-byte pixels, RGB is inverted while alpha is preserved. For other pixel sizes, every stored byte is inverted.

◆ width()

unsigned a3d::Image::width ( ) const

Returns the image width in pixels.

◆ writePNG()

bool a3d::Image::writePNG ( const std::filesystem::path &  path) const

Writes the image pixels to a PNG file at path.

Returns
true on success; false if the PNG could not be written.

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