Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::Image Class Reference

A class for representing and manipulating 2D images. More...

#include <vclib/space/core/image.h>

Public Types

enum class  ColorSpace { UNKNOWN , LINEAR , SRGB }
 

Public Member Functions

ColorSpace & colorSpace ()
 Gets a reference to the image's color space property.
 
ColorSpace colorSpace () const
 Gets the color space of the image.
 
const unsigned chardata () const
 Provides direct, read-only access to the raw pixel data.
 
void deserialize (std::istream &is)
 Deserializes image data from an input stream.
 
int height () const
 Gets the height of the image in pixels.
 
 Image ()
 Default constructor. Creates an empty, null image.
 
 Image (Array2< uint > &&img)
 Constructs an Image by moving an existing Array2 of pixels.
 
 Image (const Array2< uint > &img)
 Constructs an Image by copying an existing Array2 of pixels.
 
 Image (const void *data, uint w, uint h, bool yFlip=false, Color::Format format=Color::Format::ABGR)
 Constructs an Image from a raw pixel buffer.
 
bool isNull () const
 Checks if the image is null or empty.
 
void mirror (bool horizontal=false, bool vertical=true)
 Flips the image horizontally and/or vertically in-place.
 
Color pixel (uint i, uint j) const
 Retrieves the color of a specific pixel.
 
void serialize (std::ostream &os) const
 Serializes the image data to an output stream.
 
std::size_t sizeInBytes () const
 Calculates the total size of the image data in bytes.
 
int width () const
 Gets the width of the image in pixels.
 

Private Attributes

ColorSpace mColorSpace = ColorSpace::UNKNOWN
 
Array2< uint > mImg
 

Detailed Description

A class for representing and manipulating 2D images.

The Image class stores pixel data in a 2D array of 32-bit unsigned integers. Each pixel is internally stored in ABGR (Alpha, Blue, Green, Red) format, with 8 bits per channel.

The class provides constructors to load images from raw data buffers with various pixel formats, automatically converting them to the internal ABGR representation. It also includes functionalities for color space management, transformations like mirroring, and serialization.

Constructor & Destructor Documentation

◆ Image() [1/3]

vcl::Image::Image ( const void data,
uint  w,
uint  h,
bool  yFlip = false,
Color::Format  format = Color::Format::ABGR 
)
inline

Constructs an Image from a raw pixel buffer.

This constructor initializes the image with data from a provided buffer. It can handle various input pixel formats and optionally flip the image vertically.

Parameters
[in]dataA pointer to the raw pixel data.
[in]wThe width of the image in pixels.
[in]hThe height of the image in pixels.
[in]yFlipIf true, the image is flipped vertically after loading. This is often needed for compatibility with graphics APIs like OpenGL where the origin is at the bottom-left.
[in]formatThe pixel format of the input data buffer. The data will be converted from this format to the internal ABGR format.

◆ Image() [2/3]

vcl::Image::Image ( const Array2< uint > &  img)
inline

Constructs an Image by copying an existing Array2 of pixels.

Parameters
[in]imgThe Array2 containing pixel data in ABGR format.

◆ Image() [3/3]

vcl::Image::Image ( Array2< uint > &&  img)
inline

Constructs an Image by moving an existing Array2 of pixels.

Parameters
[in]imgThe Array2 to move, containing pixel data in ABGR format.

Member Function Documentation

◆ colorSpace() [1/2]

ColorSpace & vcl::Image::colorSpace ( )
inline

Gets a reference to the image's color space property.

Returns
A writable reference to the color space, allowing modification.

◆ colorSpace() [2/2]

ColorSpace vcl::Image::colorSpace ( ) const
inline

Gets the color space of the image.

Returns
The color space of the image.

◆ data()

const unsigned char * vcl::Image::data ( ) const
inline

Provides direct, read-only access to the raw pixel data.

Returns
A const pointer to the beginning of the pixel buffer.
Note
The data is a contiguous block of memory where each pixel is a 32-bit integer in ABGR format.

◆ deserialize()

void vcl::Image::deserialize ( std::istream &  is)
inline

Deserializes image data from an input stream.

Parameters
[in]isThe input stream to read from.

◆ height()

int vcl::Image::height ( ) const
inline

Gets the height of the image in pixels.

Returns
The image height.

◆ isNull()

bool vcl::Image::isNull ( ) const
inline

Checks if the image is null or empty.

Returns
True if the image has no pixels (width or height is zero), false otherwise.

◆ mirror()

void vcl::Image::mirror ( bool  horizontal = false,
bool  vertical = true 
)
inline

Flips the image horizontally and/or vertically in-place.

Parameters
[in]horizontalIf true, flips the image along the vertical axis (mirror).
[in]verticalIf true, flips the image along the horizontal axis (upside-down). Defaults to true.

◆ pixel()

Color vcl::Image::pixel ( uint  i,
uint  j 
) const
inline

Retrieves the color of a specific pixel.

Parameters
[in]iThe row index (Y-coordinate) of the pixel.
[in]jThe column index (X-coordinate) of the pixel.
Returns
A vcl::Color object representing the pixel at the specified coordinates.

◆ serialize()

void vcl::Image::serialize ( std::ostream &  os) const
inline

Serializes the image data to an output stream.

Parameters
[in]osThe output stream to write to.

◆ sizeInBytes()

std::size_t vcl::Image::sizeInBytes ( ) const
inline

Calculates the total size of the image data in bytes.

Returns
The size in bytes (width * height * 4).

◆ width()

int vcl::Image::width ( ) const
inline

Gets the width of the image in pixels.

Returns
The image width.

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