libpniio
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
pni::io::tiff_reader Class Reference

TIFF file reader. More...

#include <tiff_reader.hpp>

Inheritance diagram for pni::io::tiff_reader:
Inheritance graph
[legend]
Collaboration diagram for pni::io::tiff_reader:
Collaboration graph
[legend]

Public Member Functions

 tiff_reader ()
 default constructor More...
 
 tiff_reader (tiff_reader &&r)
 move constructor More...
 
 tiff_reader (const pni::core::string &fname)
 standard constructor More...
 
 tiff_reader (const tiff_reader &)=delete
 copy constructor is deleted More...
 
 ~tiff_reader ()
 destructor More...
 
tiff_readeroperator= (tiff_reader &&r)
 move assignment operator More...
 
tiff_readeroperator= (const tiff_reader &r)=delete
 copy assignment operator is deleted More...
 
virtual size_t nimages () const
 get number of images More...
 
virtual image_info info (size_t i) const
 get ImageInfo More...
 
virtual void open ()
 open the file More...
 
virtual void close ()
 close the file More...
 
template<typename CTYPE >
CTYPE image (size_t i, size_t c=0)
 read image data More...
 
template<typename CTYPE >
void image (CTYPE &data, size_t i, size_t c=0)
 read image data More...
 
- Public Member Functions inherited from pni::io::image_reader
virtual ~image_reader ()
 destructor More...
 
template<typename ATYPE >
ATYPE image (size_t, size_t)
 method to read a single channel More...
 
template<typename ATYPE >
void image (ATYPE &, size_t, size_t)
 method to read a single image channel More...
 
- Public Member Functions inherited from pni::io::data_reader
virtual ~data_reader ()
 destructor More...
 
pni::core::string filename () const
 get filename More...
 
void filename (const pni::core::string &fname)
 set filename More...
 

Private Member Functions

void _read_ifds ()
 read IDF data from the file More...
 
template<typename CTYPE >
void _read_data (size_t i, size_t c, CTYPE &data)
 read data from the file More...
 

Static Private Member Functions

static bool _is_little_endian (std::ifstream &stream)
 check binary encoding More...
 
static void _check_if_tiff (std::ifstream &stream)
 check if image is TIFF More...
 
static int32 _read_ifd_offset (std::ifstream &stream)
 read IFD offset More...
 
static size_t _read_ifd_size (std::ifstream &stream)
 read IFD size More...
 
static std::vector< size_t > _get_bits_per_sample (std::ifstream &stream, const tiff::ifd &ifd)
 get bits per sample More...
 
static std::vector< size_t > _get_sample_format (std::ifstream &stream, const tiff::ifd &ifd)
 get sample format More...
 
static type_id_t _get_type_id (size_t bps, size_t sf)
 determine channel data type More...
 

Private Attributes

bool _little_endian
 true if data is stored as little endian More...
 
std::vector< tiff::ifd_ifds
 IFD list. More...
 

Friends

std::ostream & operator<< (std::ostream &o, const tiff_reader &r)
 output operator of an TIFFReader object More...
 

Additional Inherited Members

- Protected Member Functions inherited from pni::io::image_reader
 image_reader ()
 default constructor More...
 
 image_reader (const image_reader &)=delete
 copy constructor is deleted More...
 
 image_reader (image_reader &&r)
 move constructor More...
 
 image_reader (const pni::core::string &fname, bool binary=false)
 standard constructor taking the filename as string object More...
 
image_readeroperator= (const image_reader &r)=delete
 copy assignment is deleted More...
 
image_readeroperator= (image_reader &&r)
 move assignment operator More...
 
- Protected Member Functions inherited from pni::io::data_reader
std::ifstream & _get_stream () const
 get stream More...
 
void _set_binary ()
 set binary mode More...
 
 data_reader ()
 default constructor More...
 
 data_reader (const pni::core::string &fname, bool binary=false)
 standard constructor More...
 
 data_reader (data_reader &&r)
 move constructor More...
 
 data_reader (const data_reader &r)=delete
 copy constructor is deleted More...
 
data_readeroperator= (const data_reader &r)=delete
 copy assigment is deleted More...
 
data_readeroperator= (data_reader &&r)
 move assignment More...
 

Detailed Description

TIFFReader is an implementation of the Reader class for reading TIFF image files. Actually only uncompressed TIFF images are supported. The copy constructor and the copy assignment operator are deleted to prevent copy construction of this object.

Constructor & Destructor Documentation

pni::io::tiff_reader::tiff_reader ( )
pni::io::tiff_reader::tiff_reader ( tiff_reader &&  r)
Parameters
rreader from which to move data to the new instance
pni::io::tiff_reader::tiff_reader ( const pni::core::string &  fname)
explicit
pni::io::tiff_reader::tiff_reader ( const tiff_reader )
delete
pni::io::tiff_reader::~tiff_reader ( )

Member Function Documentation

void pni::io::tiff_reader::_check_if_tiff ( std::ifstream &  stream)
staticprivate

Checks if the stream belongs to a TIFF image. If the file is not a TIFF file an exception will be thrown. No assumption is made about the position of the stream. The methods adjusts the stream to the proper positions and resets it to its original position once finished.

Parameters
streaminput stream from which to read data
Exceptions
FileErrorif stream is not a TIFF file
std::vector< size_t > pni::io::tiff_reader::_get_bits_per_sample ( std::ifstream &  stream,
const tiff::ifd ifd 
)
staticprivate

Returns a vector whose length corresponds to the number of channels in the image. Each element holds the number of bits used to store the data for the corresponding channel.

Parameters
streamimage file stream
ifdIFD of the image
Returns
vector with pixels per channel
std::vector< size_t > pni::io::tiff_reader::_get_sample_format ( std::ifstream &  stream,
const tiff::ifd ifd 
)
staticprivate

The sample format decides how to interpret the bits stored for each channel. Depending on its value the channel data will be interpreted as unsigned integer, signed integer, or IEEE floating point number.

Parameters
streamimage file stream
ifdIFD of the image in the file
Returns
vector with sample formats for each channel
type_id_t pni::io::tiff_reader::_get_type_id ( size_t  bps,
size_t  sf 
)
staticprivate

Static method to deduce the type of an image channel from the sample format and the number of bits used for the channel data. If the type could not be deduced an exception will be thrown.

Exceptions
type_errorif the type cannot be deduced from the data
Parameters
bpsnumber of bits per sample
sfsample format
Returns
TypeID of the corresponding type
bool pni::io::tiff_reader::_is_little_endian ( std::ifstream &  stream)
staticprivate

This private method checks if the image is encoded as TIFF or not. The method makes no assumption about the position of the stream pointer. It moves it automatically to the correction position and reads the data from there. Afterwards the stream will be reset to the position where it originally was. True is returned when the TIFF file contains little endian encoded data and false otherwise.

Parameters
streaminput stream from which to read data
Returns
true file data is encoded as little endian
template<typename CTYPE >
void pni::io::tiff_reader::_read_data ( size_t  i,
size_t  c,
CTYPE &  data 
)
private

Reads data form the file and stores it into a container of type CTYPE.

Template Parameters
CTYPEcontainer type where to store the data
Parameters
iimage number
cchannel number of the selected image
datainstance of CTYPE which will hold the data
pni::core::int32 pni::io::tiff_reader::_read_ifd_offset ( std::ifstream &  stream)
staticprivate

Method obtains the offset for an IFD from the actual stream position.

Parameters
streaminput stream from which to read data
Returns
IFD offset
size_t pni::io::tiff_reader::_read_ifd_size ( std::ifstream &  stream)
staticprivate

Reads the number of IFD entries from the actual stream position

Parameters
streaminput stream from which to read data
Returns
number of IFD entries
void pni::io::tiff_reader::_read_ifds ( )
private

Read all the IDF data from the file and store them in the _idfs private member variable.

void pni::io::tiff_reader::close ( )
virtual

Reimplemented from pni::io::data_reader.

template<typename CTYPE >
CTYPE pni::io::tiff_reader::image ( size_t  i,
size_t  c = 0 
)
inline

Template method to read image data from the file. The returns an instance of the the template Array<T,BT> and does all the configuration and memory allocation work for this object.

Exceptions
memory_allocation_errorif array allocation fails
Parameters
iindex of the image in the file
cindex of the image channel to read
Returns
instance of an array template
template<typename CTYPE >
void pni::io::tiff_reader::image ( CTYPE &  data,
size_t  i,
size_t  c = 0 
)
inline

Reads the image data from the file and stores it in a user suppliedb array object. The method checks if the arrays shape and allocation state fits the requirements of the image. The advantage of this method is that memory allocation must be done only once before this method is called. This increases performance dramatically in particular if many images of equal size should be read.

Exceptions
size_mismatch_errorif the size of the container does not match the number of pixels stored in the image
Parameters
datainstance of CTYPE where data will be stored
iindex of the image in the file
cindex of the image channel to read
image_info pni::io::tiff_reader::info ( size_t  i) const
virtual

Return an instance of ImageInfo for image i stored in the file.

Parameters
iindex of the image
Returns
instance of ImageInfo for the requested image

Implements pni::io::image_reader.

size_t pni::io::tiff_reader::nimages ( ) const
virtual

Return the number of images stored in the image file.

Returns
number of images

Implements pni::io::image_reader.

void pni::io::tiff_reader::open ( )
virtual

Reimplemented from pni::io::data_reader.

tiff_reader & pni::io::tiff_reader::operator= ( tiff_reader &&  r)
tiff_reader& pni::io::tiff_reader::operator= ( const tiff_reader r)
delete

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const tiff_reader r 
)
friend

Field Documentation

std::vector<tiff::ifd> pni::io::tiff_reader::_ifds
private
bool pni::io::tiff_reader::_little_endian
private

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