SpatiumLib
Static Public Member Functions | Static Protected Member Functions | List of all members
spatium::ImageIO Class Reference

Read and write images. More...

#include <ImageIO.h>

Static Public Member Functions

static bool writeBinaryImageAsPbm (const Image< unsigned char, 1 > &image, const std::string &pbmPath)
 Write binary image to file as PBM (Portable Bit Map). More...
 
static bool writeGrayscaleImageAsPgm (const Image< unsigned char, 1 > &image, const std::string &pgmPath)
 Write 8-bit grayscale image to file as PGM (Portable Gray Map) More...
 
static bool writeGrayscaleImageAsPgm (const Image< unsigned short, 1 > &image, const std::string &pgmPath)
 Write 16-bit grayscale image to file as PGM (Portable Gray Map) More...
 
static bool writeRgbImageAsPpm (const Image< unsigned char, 3 > &image, const std::string &ppmPath)
 Write 24-bit RGB image to file as PPM (Portable Pixel Map) More...
 
static bool writeRgbaImageAsPpm (const Image< unsigned char, 4 > &image, const std::string &ppmPath)
 Write 32-bit RGBA image to file as PPM (Portable Pixel Map) More...
 
static bool writeRgbImageAsPam (const Image< unsigned char, 3 > &image, const std::string &pamPath)
 Write 24-bit RGB image to file as PAM (Portable Arbitrary Map) More...
 
static bool writeRgbaImageAsPam (const Image< unsigned char, 4 > &image, const std::string &pamPath)
 Write 32-bit RGBA image to file as PAM (Portable Arbitrary Map) More...
 
static bool readBinaryImageFromPbm (const std::string &pbmPath, Image< unsigned char, 1 > &image)
 Read 1-bit binary image from PBM file (Portable Bit Map). More...
 
static bool readGrayscaleImageFromPgm (const std::string &pgmPath, Image< unsigned char, 1 > &image)
 Read 8-bit grayscale image from PGM file (Portable Gray Map) More...
 
static bool readRgbImageFromPpm (const std::string &ppmPath, Image< unsigned char, 3 > &image)
 Read 24-bit RGB image from PPM file (Portable Pixel Map) More...
 

Static Protected Member Functions

static bool readPnmFileHeader (std::ifstream &ifile, std::string magicNumber, size_t &width, size_t &height, unsigned long &maxVal)
 Read header of a PNM file (PBM, PGM or PPM) More...
 

Detailed Description

Read and write images.

This class supports 4 file formats:

Beware! These functions have not been tested on endianness; big-endian vs little-endian.

Member Function Documentation

◆ readBinaryImageFromPbm()

static bool spatium::ImageIO::readBinaryImageFromPbm ( const std::string &  pbmPath,
Image< unsigned char, 1 > &  image 
)
inlinestatic

Read 1-bit binary image from PBM file (Portable Bit Map).

Parameters
[in]pbmPathPath to PBM file. Should have file extension *.pbm
[out]imageImage
Returns
True on success, false otherwise

◆ readGrayscaleImageFromPgm()

static bool spatium::ImageIO::readGrayscaleImageFromPgm ( const std::string &  pgmPath,
Image< unsigned char, 1 > &  image 
)
inlinestatic

Read 8-bit grayscale image from PGM file (Portable Gray Map)

Beware! This file format also supports 16-bit grayscale format (2 bytes per channel). This is not implemented and function will return false in that situation.

Parameters
[in]pgmPathPath to PGM file. Should have file extension *.pgm
[out]imageImage
Returns
True on success, false otherwise

◆ readPnmFileHeader()

static bool spatium::ImageIO::readPnmFileHeader ( std::ifstream &  ifile,
std::string  magicNumber,
size_t &  width,
size_t &  height,
unsigned long &  maxVal 
)
inlinestaticprotected

Read header of a PNM file (PBM, PGM or PPM)

Parameters
[in]ifileInput file stream
[in]magicNumberExpected magic number
[out]widthImage width
[out]heightImage height
[out]maxValMaximum pixel value (ignored for PBM images)
Returns
True on success, false otherwise

◆ readRgbImageFromPpm()

static bool spatium::ImageIO::readRgbImageFromPpm ( const std::string &  ppmPath,
Image< unsigned char, 3 > &  image 
)
inlinestatic

Read 24-bit RGB image from PPM file (Portable Pixel Map)

Beware! This file format also supports 48-bit RGB format (2 bytes per channel). This is not implemented and function will return false in that situation.

Parameters
[in]ppmPathPath to PPM file. Should have file extension *.ppm
[out]imageImage
Returns
True on success, false otherwise

◆ writeBinaryImageAsPbm()

static bool spatium::ImageIO::writeBinaryImageAsPbm ( const Image< unsigned char, 1 > &  image,
const std::string &  pbmPath 
)
inlinestatic

Write binary image to file as PBM (Portable Bit Map).

In this file each pixel is represented by 1 bit. In the Image object each pixel is represented by 1 byte.

Parameters
[in]imageImage
[in]pbmPathPath to PBM file. Should have file extension *.pbm
Returns
True on success, false otherwise

◆ writeGrayscaleImageAsPgm() [1/2]

static bool spatium::ImageIO::writeGrayscaleImageAsPgm ( const Image< unsigned char, 1 > &  image,
const std::string &  pgmPath 
)
inlinestatic

Write 8-bit grayscale image to file as PGM (Portable Gray Map)

Parameters
[in]imageImage
[in]pgmPathPath to PGM file. Should have file extension *.pgm
Returns
True on success, false otherwise

◆ writeGrayscaleImageAsPgm() [2/2]

static bool spatium::ImageIO::writeGrayscaleImageAsPgm ( const Image< unsigned short, 1 > &  image,
const std::string &  pgmPath 
)
inlinestatic

Write 16-bit grayscale image to file as PGM (Portable Gray Map)

Parameters
[in]imageImage
[in]pgmPathPath to PGM file. Should have file extension *.pgm
Returns
True on success, false otherwise

◆ writeRgbaImageAsPam()

static bool spatium::ImageIO::writeRgbaImageAsPam ( const Image< unsigned char, 4 > &  image,
const std::string &  pamPath 
)
inlinestatic

Write 32-bit RGBA image to file as PAM (Portable Arbitrary Map)

Parameters
[in]imageImage
[in]pamPathPath to PAM file. Should have file extension *.pam
Returns
True on success, false otherwise

◆ writeRgbaImageAsPpm()

static bool spatium::ImageIO::writeRgbaImageAsPpm ( const Image< unsigned char, 4 > &  image,
const std::string &  ppmPath 
)
inlinestatic

Write 32-bit RGBA image to file as PPM (Portable Pixel Map)

This file format does not support transparancy. The alpha channel is omitted. Use PAM instead.

Parameters
[in]imageImage
[in]ppmPathPath to PPM file. Should have file extension *.ppm
Returns
True on success, false otherwise

◆ writeRgbImageAsPam()

static bool spatium::ImageIO::writeRgbImageAsPam ( const Image< unsigned char, 3 > &  image,
const std::string &  pamPath 
)
inlinestatic

Write 24-bit RGB image to file as PAM (Portable Arbitrary Map)

Parameters
[in]imageImage
[in]pamPathPath to PAM file. Should have file extension *.pam
Returns
True on success, false otherwise

◆ writeRgbImageAsPpm()

static bool spatium::ImageIO::writeRgbImageAsPpm ( const Image< unsigned char, 3 > &  image,
const std::string &  ppmPath 
)
inlinestatic

Write 24-bit RGB image to file as PPM (Portable Pixel Map)

Parameters
[in]imageImage
[in]ppmPathPath to PPM file. Should have file extension *.ppm
Returns
True on success, false otherwise

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