Allolib  1.0
C++ Components For Interactive Multimedia
al::Image Struct Reference

Interface for loading image files. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/graphics/al_Image.hpp>

Classes

struct  RGBAPix
 

Public Member Functions

 Image (const Image &)=default
 
 Image (Image &&)=default
 
Image & operator= (const Image &)=default
 
Image & operator= (Image &&)=default
 
 Image (const std::string &filename)
 
bool load (const std::string &filePath)
 Load image from disk. More...
 
bool save (const std::string &filePath)
 Save image to disk. More...
 
const std::string & filepath () const
 File path to image.
 
bool loaded () const
 Whether image was loaded from file.
 
std::vector< uint8_t > & array ()
 Get pixels as an Array.
 
const std::vector< uint8_t > & array () const
 Get pixels as an Array (read-only)
 
template<typename T = RGBAPix>
T * pixels ()
 Get pointer to pixels.
 
template<typename T = RGBAPix>
const T * pixels () const
 Get pointer to pixels (read-only)
 
unsigned width () const
 Get number of bytes per pixel. More...
 
unsigned height () const
 Get height, in pixels.
 
int compression () const
 Get compression flags for saving.
 
Image & compression (int flags)
 Set compression flags for saving. More...
 
template<typename Pix = RGBAPix>
const Pix & at (unsigned x, unsigned y) const
 Get read-only reference to a pixel. More...
 
template<typename Pix = RGBAPix>
Pix & at (unsigned x, unsigned y)
 Get mutable reference to a pixel. More...
 
template<typename Pix = RGBAPix>
void write (const Pix &pix, unsigned x, unsigned y)
 Write a pixel to an Image. More...
 
template<typename Pix = RGBAPix>
void read (Pix &pix, unsigned x, unsigned y) const
 Read a pixel from an Image. More...
 
template<typename T >
bool resize (int dimX, int dimY)
 Resize internal pixel buffer. Erases any existing data. More...
 

Static Public Member Functions

static bool saveImage (std::string fileName, unsigned char *pixs, int width, int height, bool flipVertically=false, int numComponents=3)
 saveImage More...
 

Public Attributes

unsigned int mWidth = 0
 
unsigned int mHeight = 0
 
std::vector< uint8_t > mArray
 
std::string mFilename = ""
 
int mCompression = 50
 
bool mLoaded = false
 

Detailed Description

Interface for loading image files.

Loads image as 8-bit 4 channels RGBA. Supported formats: PNG, JPG, ... Implementation uses stb_image.h >> https://github.com/nothings/stb

Definition at line 62 of file al_Image.hpp.

Member Function Documentation

◆ at() [1/2]

template<typename Pix = RGBAPix>
Pix& al::Image::at ( unsigned  x,
unsigned  y 
)
inline

Get mutable reference to a pixel.

Warning: doesn't check that Pix has matching type/component count. Warning: no bounds checking performed on x and y.

Definition at line 172 of file al_Image.hpp.

◆ at() [2/2]

template<typename Pix = RGBAPix>
const Pix& al::Image::at ( unsigned  x,
unsigned  y 
) const
inline

Get read-only reference to a pixel.

Warning: doesn't check that Pix has matching type/component count. Warning: no bounds checking performed on x and y.

Definition at line 162 of file al_Image.hpp.

◆ compression()

Image& al::Image::compression ( int  flags)
inline

Set compression flags for saving.

The flags consist of a bitwise-or of the level of compression in [0,100] and other flags which may be specific to the image format.

Definition at line 152 of file al_Image.hpp.

◆ load()

bool al::Image::load ( const std::string &  filePath)

Load image from disk.

Parameters
[in]filePathFile to load. Image type determined by file extension.
Returns
true for success or print error message and return false

◆ read()

template<typename Pix = RGBAPix>
void al::Image::read ( Pix &  pix,
unsigned  x,
unsigned  y 
) const
inline

Read a pixel from an Image.

Warning: doesn't check that Pix has matching type/component count Warning: no bounds checking performed on x and y

Definition at line 197 of file al_Image.hpp.

◆ resize()

template<typename T >
bool al::Image::resize ( int  dimX,
int  dimY 
)
inline

Resize internal pixel buffer. Erases any existing data.

Parameters
[in]dimXnumber of pixels in x direction
[in]dimYnumber of pixels in y direction
[in]formatpixel color format
Returns
True on success; false otherwise.

Definition at line 212 of file al_Image.hpp.

◆ save()

bool al::Image::save ( const std::string &  filePath)

Save image to disk.

Parameters
[in]filePathFile to save. Image type determined by file extension.
Returns
true for success or print error message and return false

◆ saveImage()

static bool al::Image::saveImage ( std::string  fileName,
unsigned char *  pixs,
int  width,
int  height,
bool  flipVertically = false,
int  numComponents = 3 
)
static

saveImage

Parameters
fileName
pixs
width
height
flipVertically
numComponentsuse 3 for RGB and 4 for RGBA
Returns

◆ width()

unsigned al::Image::width ( ) const
inline

Get number of bytes per pixel.

Get pixel format Get width, in pixels

Definition at line 140 of file al_Image.hpp.

◆ write()

template<typename Pix = RGBAPix>
void al::Image::write ( const Pix &  pix,
unsigned  x,
unsigned  y 
)
inline

Write a pixel to an Image.

Warning: doesn't check that Pix has matching type/component count Warning: no bounds checking performed on x and y

Definition at line 183 of file al_Image.hpp.


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