libpng++  v0.2.5-1
C++ library for PNG images
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
png::consumer< pixel, pixcon, info_holder, interlacing_supported > Class Template Reference

Pixel consumer class template. More...

#include <consumer.hpp>

Inheritance diagram for png::consumer< pixel, pixcon, info_holder, interlacing_supported >:
Collaboration diagram for png::consumer< pixel, pixcon, info_holder, interlacing_supported >:

Classes

struct  transform_identity
 The default io transformation: does nothing. More...
 

Public Types

typedef pixel_traits< pixel > traits
 

Public Member Functions

image_info const & get_info () const
 
template<typename istream >
void read (istream &stream)
 Reads an image from the stream using default io transformation. More...
 
template<typename istream , class transformation >
void read (istream &stream, transformation const &transform)
 Reads an image from the stream using custom io transformation. More...
 

Protected Types

typedef streaming_base< pixel,
info_holder > 
base
 

Protected Member Functions

 consumer (image_info &info)
 Constructs a consumer object using passed image_info object to store image information. More...
 
image_infoget_info ()
 
void reset (size_t)
 

Protected Attributes

info_holder m_info_holder
 

Private Member Functions

template<typename istream >
void read_rows (reader< istream > &rd, size_t pass_count, pixcon *pixel_con)
 
template<typename istream >
void skip_interlaced_rows (reader< istream > &rd, size_t pass_count)
 

Detailed Description

template<typename pixel, class pixcon, class info_holder = def_image_info_holder, bool interlacing_supported = false>
class png::consumer< pixel, pixcon, info_holder, interlacing_supported >

Pixel consumer class template.

Used as a base class for custom pixel consumer classes as well as inside image class implementation to read pixels into the pixel buffer.

Encapsulates PNG image reading procedure. In order to create a custom pixel consumer use CRTP trick:

class pixel_consumer
: public png::consumer< pixel, pixel_consumer >
{
...
};

Your pixel consumer class should implement get_next_row() method and reset() method (optional). Their signatures are as follows:

png::byte* get_next_row(size_t pos);
void reset(size_t pass);

The get_next_row() method is called every time a new row of image data is available to the reader. The position of the row being read is passed as pos parameter. The pos takes values from 0 to <image_height>-1 inclusively. The method should return the starting address of a row buffer capable of storing appropriate amount of pixels (i.e. the width of the image being read). The address should be casted to png::byte* pointer type using reinterpret_cast<> or a C-style cast.

The optional reset() method is called every time the new pass of interlaced image processing starts. The number of interlace pass is avaiable as the only parameter of the method. For non-interlaced images the method is called once prior to any calls to get_next_row(). The value of 0 is passed for the pass number.

An optional template parameter info_holder encapsulates image_info storage policy. Using def_image_info_holder results in image_info object stored as a sub-object of the consumer class. You may specify image_info_ref_holder in order to use a reference to the externally stored image_info object. This way you will have to construct the consumer object passing the reference to image_info object.

Also, you might want implement an info holder object yourself to fine-tune your code. In any case, you can access the image_info object from your consumer class methods using the following code:

png::image_info& info = m_info_holder.get_info();

An optional bool template parameter interlacing_supported specifies whether reading interlacing images is supported by your consumer class. It defaults to false. An attempt to read an interlaced image will result in discarding pixels obtained at all the interlacing passes except the last one.

In order to fully support interlacing specify true for interlacing_supported parameter and implement reset() method.

See Also
image, generator

Member Typedef Documentation

template<typename pixel, class pixcon, class info_holder = def_image_info_holder, bool interlacing_supported = false>
typedef streaming_base< pixel, info_holder > png::consumer< pixel, pixcon, info_holder, interlacing_supported >::base
protected
template<typename pixel, class pixcon, class info_holder = def_image_info_holder, bool interlacing_supported = false>
typedef pixel_traits< pixel > png::consumer< pixel, pixcon, info_holder, interlacing_supported >::traits

Constructor & Destructor Documentation

template<typename pixel, class pixcon, class info_holder = def_image_info_holder, bool interlacing_supported = false>
png::consumer< pixel, pixcon, info_holder, interlacing_supported >::consumer ( image_info info)
inlineexplicitprotected

Constructs a consumer object using passed image_info object to store image information.

Member Function Documentation

template<typename pixel, class info_holder>
image_info& png::streaming_base< pixel, info_holder >::get_info ( )
inlineprotectedinherited
template<typename pixel, class pixcon, class info_holder = def_image_info_holder, bool interlacing_supported = false>
template<typename istream >
void png::consumer< pixel, pixcon, info_holder, interlacing_supported >::read ( istream &  stream)
inline

Reads an image from the stream using default io transformation.

Referenced by png::consumer< pixel, pixel_consumer, image_info_ref_holder, true >::read().

Here is the caller graph for this function:

template<typename pixel, class pixcon, class info_holder = def_image_info_holder, bool interlacing_supported = false>
template<typename istream , class transformation >
void png::consumer< pixel, pixcon, info_holder, interlacing_supported >::read ( istream &  stream,
transformation const &  transform 
)
inline

Reads an image from the stream using custom io transformation.

Essentially, this method constructs a reader object and instructs it to read the image from the stream. It handles IO transformation, as well as interlaced image reading.

template<typename pixel, class pixcon, class info_holder = def_image_info_holder, bool interlacing_supported = false>
template<typename istream >
void png::consumer< pixel, pixcon, info_holder, interlacing_supported >::read_rows ( reader< istream > &  rd,
size_t  pass_count,
pixcon *  pixel_con 
)
inlineprivate

Referenced by png::consumer< pixel, pixel_consumer, image_info_ref_holder, true >::read().

Here is the caller graph for this function:

template<typename pixel, class info_holder>
void png::streaming_base< pixel, info_holder >::reset ( size_t  )
inlineprotectedinherited
template<typename pixel, class pixcon, class info_holder = def_image_info_holder, bool interlacing_supported = false>
template<typename istream >
void png::consumer< pixel, pixcon, info_holder, interlacing_supported >::skip_interlaced_rows ( reader< istream > &  rd,
size_t  pass_count 
)
inlineprivate

Referenced by png::consumer< pixel, pixel_consumer, image_info_ref_holder, true >::read().

Here is the caller graph for this function:

Member Data Documentation

template<typename pixel, class info_holder>
info_holder png::streaming_base< pixel, info_holder >::m_info_holder
protectedinherited

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