Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | List of all members
Image Class Reference

Represents an image composed of pixels with values in [0,1]. Provide image loading/saving utilities, for both LDR and HDR images. More...

#include <Image.hpp>

Public Types

enum class  Save : uint { NONE = 0 , FLIP = 1 << 0 , IGNORE_ALPHA = 1 << 1 , SRGB_LDR = 1 << 2 }
 Options for saving an image to disk. More...
 

Public Member Functions

 Image ()=default
 
 Image (unsigned int awidth, unsigned int aheight, unsigned int acomponents, float value=0.0f)
 
glm::vec4 & rgba (int x, int y)
 
glm::vec3 & rgb (int x, int y)
 
float & r (int x, int y)
 
const glm::vec4 & rgba (int x, int y) const
 
const glm::vec3 & rgb (int x, int y) const
 
const float & r (int x, int y) const
 
glm::vec3 rgbl (float x, float y) const
 
glm::vec3 rgbn (float x, float y) const
 
glm::vec4 rgbal (float x, float y) const
 
int load (const std::string &path, unsigned int channels, bool flip, bool externalFile)
 
int save (const std::string &path, Save options) const
 
Imageoperator= (const Image &)=delete
 
 Image (const Image &)=delete
 
Imageoperator= (Image &&)=default
 
 Image (Image &&)=default
 

Static Public Member Functions

static bool isFloat (const std::string &path)
 

Public Attributes

unsigned int width = 0
 The width of the image.
 
unsigned int height = 0
 The height of the image.
 
unsigned int components = 0
 Number of components/channels.
 
std::vector< float > pixels
 The pixels values of the image.
 

Private Member Functions

int saveAsLDR (const std::string &path, Save options) const
 
int saveAsHDR (const std::string &path, Save options) const
 
int loadLDR (const std::string &path, unsigned int channels, bool flip, bool externalFile)
 
int loadHDR (const std::string &path, unsigned int channels, bool flip, bool externalFile)
 

Detailed Description

Represents an image composed of pixels with values in [0,1]. Provide image loading/saving utilities, for both LDR and HDR images.

Member Enumeration Documentation

◆ Save

enum class Image::Save : uint
strong

Options for saving an image to disk.

Enumerator
NONE 

No specific options.

FLIP 

Flip the image vertically.

IGNORE_ALPHA 

Force alpha to 1.

SRGB_LDR 

Apply gamma sRGB correction before saving, ignored for HDR images.

Constructor & Destructor Documentation

◆ Image() [1/4]

Image::Image ( )
default

Default constructor.

◆ Image() [2/4]

Image::Image ( unsigned int  awidth,
unsigned int  aheight,
unsigned int  acomponents,
float  value = 0.0f 
)

Constructor that allocates an empty image with the given dimensions.

Parameters
awidththe width of the image
aheightthe height of the image
acomponentsthe number of components of the image
valuethe default value to use

◆ Image() [3/4]

Image::Image ( const Image )
delete

Copy constructor (disabled).

◆ Image() [4/4]

Image::Image ( Image &&  )
default

Move constructor.

Member Function Documentation

◆ isFloat()

bool Image::isFloat ( const std::string &  path)
static

Query if a path points to an image loaded in floating point, based on the extension.

Parameters
paththe path to the image
Returns
true if the file is loaded as a floating point numbers image
Note
Extensions checked: .exr

◆ load()

int Image::load ( const std::string &  path,
unsigned int  channels,
bool  flip,
bool  externalFile 
)

Load an image from disk. Will contain the image raw data as [0,1] floats.

Parameters
paththe path to the image
channelsthe number of channels to load from the image
flipshould the image be vertically flipped
externalFileif true, skip the resources manager and load directly from disk
Returns
a success/error flag

◆ loadHDR()

int Image::loadHDR ( const std::string &  path,
unsigned int  channels,
bool  flip,
bool  externalFile 
)
private

Load a HDR image from disk using tiny_exr, assuming 3-channels.

Parameters
paththe path to the image
channelswill contain the number of channels of the loaded image
flipshould the image be vertically flipped
externalFileif true, skip the resources manager and load directly from disk
Returns
a success/error flag

◆ loadLDR()

int Image::loadLDR ( const std::string &  path,
unsigned int  channels,
bool  flip,
bool  externalFile 
)
private

Load a LDR image from disk using stb_image.

Parameters
paththe path to the image
channelsthe number of channels to load from the image
flipshould the image be vertically flipped
externalFileif true, skip the resources manager and load directly from disk
Returns
a success/error flag

◆ operator=() [1/2]

Image & Image::operator= ( const Image )
delete

Copy assignment operator (disabled).

Returns
a reference to the object assigned to

◆ operator=() [2/2]

Image & Image::operator= ( Image &&  )
default

Move assignment operator .

Returns
a reference to the object assigned to

◆ r() [1/2]

float & Image::r ( int  x,
int  y 
)

Accessor to the red/first component of a pixel

Parameters
xhorizontal coordinate
yvertical coordinate
Returns
reference to the given pixel first component
Warning
no access or component check is done

◆ r() [2/2]

const float & Image::r ( int  x,
int  y 
) const

Const accessor to the red/first component of a pixel

Parameters
xhorizontal coordinate
yvertical coordinate
Returns
reference to the given pixel first component
Warning
no access or component check is done

◆ rgb() [1/2]

glm::vec3 & Image::rgb ( int  x,
int  y 
)

Accessor to the RGB part of a pixel

Parameters
xhorizontal coordinate
yvertical coordinate
Returns
reference to the given pixel
Warning
no access or component check is done

◆ rgb() [2/2]

const glm::vec3 & Image::rgb ( int  x,
int  y 
) const

Const accessor to the RGB part of a pixel

Parameters
xhorizontal coordinate
yvertical coordinate
Returns
reference to the given pixel
Warning
no access or component check is done

◆ rgba() [1/2]

glm::vec4 & Image::rgba ( int  x,
int  y 
)

Accessor to a RGBA pixel

Parameters
xhorizontal coordinate
yvertical coordinate
Returns
reference to the given pixel
Warning
no access or component check is done

◆ rgba() [2/2]

const glm::vec4 & Image::rgba ( int  x,
int  y 
) const

Const accessor to a RGBA pixel

Parameters
xhorizontal coordinate
yvertical coordinate
Returns
reference to the given pixel
Warning
no access or component check is done

◆ rgbal()

glm::vec4 Image::rgbal ( float  x,
float  y 
) const

Bilinear UV image read.

Parameters
xhorizontal unit float coordinate
yvertical unit float coordinate
Returns
the bilinearly interpolated color value
Note
Wrapping is applied on both axis.

◆ rgbl()

glm::vec3 Image::rgbl ( float  x,
float  y 
) const

Bilinear UV image read.

Parameters
xhorizontal unit float coordinate
yvertical unit float coordinate
Returns
the bilinearly interpolated color value
Note
Wrapping is applied on both axis.

◆ rgbn()

glm::vec3 Image::rgbn ( float  x,
float  y 
) const

Nearest-neighbour UV image read.

Parameters
xhorizontal unit float coordinate
yvertical unit float coordinate
Returns
the color of the nearest pixel
Note
Wrapping is applied on both axis.

◆ save()

int Image::save ( const std::string &  path,
Image::Save  options 
) const

Save an image to disk, either in HDR (when using "exr" extension) or in LDR (any other extension).

Parameters
paththe path to the image
optionsoptions to use when writing the image on disk
Returns
a success/error flag

◆ saveAsHDR()

int Image::saveAsHDR ( const std::string &  path,
Image::Save  options 
) const
private

Save a HDR image to disk using tiny_exr.

Parameters
paththe path to the image
optionsoptions to use when writing the image on disk
Returns
a success/error flag

◆ saveAsLDR()

int Image::saveAsLDR ( const std::string &  path,
Image::Save  options 
) const
private

Save a LDR image to disk using stb_image.

Parameters
paththe path to the image
optionsoptions to use when writing the image on disk
Returns
a success/error flag

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