PhotoGENius V1.0.0
A basic library for generating photorealistic images, developed for the course Numerical techniques for photorealistic image generation.
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | List of all members
PGENLib.HdrImage Class Reference

A High-Dynamic-Range 2D image. This class has 3 members:

Width number (int) of columns in the 2D matrix of colors
Height number (int) of rows in the 2D matrix of colors
Pixel the 2D matrix (array of Color), represented as a 1D array
More...

Public Member Functions

 HdrImage (int WidthConstr, int HeightConstr, Color[]? pixels=null)
 Constructor, empty or with pixels. More...
 
bool ValidCoord (int x, int y)
 Check that given coordinates have values between 0 and the number of rows / columns. More...
 
void SetPixel (int x, int y, Color newCol)
 Sets the color of a pixel of given coordinates. More...
 
Color GetPixel (int x, int y)
 Given a pair of coordinates, it returns the color of the corresponding pixel. More...
 
HdrImage ReadPFMFile (Stream input)
 Function that reads a PFM file and writes the content to a new HDR image. More...
 
string ReadLine (Stream input)
 Reads a line of a stream. More...
 
int[] ParseImgSize (string str)
 Image size reading function. More...
 
int ParseEndianness (string input)
 Reads the endianness and returns if it is little or big. More...
 
void WritePFMFile (Stream output, Endianness endian)
 Function that writes a PFM file from an HDR image. More...
 
float AverageLum (double delta=1e-10)
 Returns the average brightness of the image. The delta parameter is used to prevent numerical problems for underilluminated pixels. More...
 
void NormalizeImage (float factor, float? luminosity=null)
 Calculate the average brightness of an image according to the axRi / <l> formula. More...
 
float ClampFloat (float x)
 Maps a float from [0, + inf) to [0,1]. More...
 
void ClampImage ()
 Apply correction for bright spots.
 
void WriteLdrImage (String output, String format, float gamma=1.0f)
 Convert an HDR image to LDR format. Before calling this function, you should apply a tone-mapping algorithm to the image and be sure that the R, G, and B values of the colors in the image are all in the range [0, 1]. Use HdrImage.NormalizeImage and HdrImage.ClampImage to do this. More...
 

Static Public Member Functions

static float ReadFloat (Stream input, Endianness end)
 Reads a 32-bit sequence from a stream and converts it to a floating-point number. More...
 

Public Attributes

int Width
 
int Height
 
Color[] Pixels
 

Private Member Functions

int PixelOffset (int x, int y)
 Given a pair of coordinates, it returns the position of the pixel in the storage vector. More...
 

Static Private Member Functions

static void WriteFloat (Stream outputStream, float value, Endianness end)
 Method of writing a 32-bit floating-point number in binary. More...
 

Detailed Description

A High-Dynamic-Range 2D image. This class has 3 members:

Width number (int) of columns in the 2D matrix of colors
Height number (int) of rows in the 2D matrix of colors
Pixel the 2D matrix (array of Color), represented as a 1D array

Constructor & Destructor Documentation

◆ HdrImage()

PGENLib.HdrImage.HdrImage ( int  WidthConstr,
int  HeightConstr,
Color?[]  pixels = null 
)

Constructor, empty or with pixels.

Parameters
WidthConstr
HeightConstr
pixels

Member Function Documentation

◆ AverageLum()

float PGENLib.HdrImage.AverageLum ( double  delta = 1e-10)

Returns the average brightness of the image. The delta parameter is used to prevent numerical problems for underilluminated pixels.

Parameters
delta
Returns

◆ ClampFloat()

float PGENLib.HdrImage.ClampFloat ( float  x)

Maps a float from [0, + inf) to [0,1].

Parameters
x
Returns

◆ GetPixel()

Color PGENLib.HdrImage.GetPixel ( int  x,
int  y 
)

Given a pair of coordinates, it returns the color of the corresponding pixel.

Parameters
xtype int
ytype int
Returns
Pixel's Color in coordinates (x,y)

◆ NormalizeImage()

void PGENLib.HdrImage.NormalizeImage ( float  factor,
float?  luminosity = null 
)

Calculate the average brightness of an image according to the axRi / <l> formula.

Parameters
factor
luminosity

◆ ParseEndianness()

int PGENLib.HdrImage.ParseEndianness ( string  input)

Reads the endianness and returns if it is little or big.

Parameters
inputstring
Returns
+1 if endianness=big or -1 if endianness=small

◆ ParseImgSize()

int[] PGENLib.HdrImage.ParseImgSize ( string  str)

Image size reading function.

Parameters
strinput string
Returns
int[2] containing Width and Height

◆ PixelOffset()

int PGENLib.HdrImage.PixelOffset ( int  x,
int  y 
)
private

Given a pair of coordinates, it returns the position of the pixel in the storage vector.

Parameters
x
y
Returns
the position in the 1D array of the specified pixel

◆ ReadFloat()

static float PGENLib.HdrImage.ReadFloat ( Stream  input,
Endianness  end 
)
static

Reads a 32-bit sequence from a stream and converts it to a floating-point number.

Parameters
inputStream
endEndianness
Returns
float

◆ ReadLine()

string PGENLib.HdrImage.ReadLine ( Stream  input)

Reads a line of a stream.

Parameters
inputtype Stream
Returns
String containing the line of the input stream

◆ ReadPFMFile()

HdrImage PGENLib.HdrImage.ReadPFMFile ( Stream  input)

Function that reads a PFM file and writes the content to a new HDR image.

Parameters
inputtype Stream
Returns
a HdrImage object containing the image. If an error occurs, raise a InvalidPfmFileFormat exception.

◆ SetPixel()

void PGENLib.HdrImage.SetPixel ( int  x,
int  y,
Color  newCol 
)

Sets the color of a pixel of given coordinates.

Parameters
xtype int
ytype int
newColtype Color

◆ ValidCoord()

bool PGENLib.HdrImage.ValidCoord ( int  x,
int  y 
)

Check that given coordinates have values between 0 and the number of rows / columns.

Parameters
x
y
Returns
True if (x, y) are coordinates within the 2D matrix

◆ WriteFloat()

static void PGENLib.HdrImage.WriteFloat ( Stream  outputStream,
float  value,
Endianness  end 
)
staticprivate

Method of writing a 32-bit floating-point number in binary.

Parameters
outputStream
value
end

◆ WriteLdrImage()

void PGENLib.HdrImage.WriteLdrImage ( String  output,
String  format,
float  gamma = 1.0f 
)

Convert an HDR image to LDR format. Before calling this function, you should apply a tone-mapping algorithm to the image and be sure that the R, G, and B values of the colors in the image are all in the range [0, 1]. Use HdrImage.NormalizeImage and HdrImage.ClampImage to do this.

Parameters
output
format
gamma

◆ WritePFMFile()

void PGENLib.HdrImage.WritePFMFile ( Stream  output,
Endianness  endian 
)

Function that writes a PFM file from an HDR image.

Parameters
output
endian

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