png::generator< pixel, pixgen, info_holder, interlacing_supported > Class Template Reference

Pixel generator class template. More...

#include <generator.hpp>

Inheritance diagram for png::generator< pixel, pixgen, info_holder, interlacing_supported >:

png::streaming_base< pixel, info_holder > List of all members.

Public Member Functions

void write (std::ostream &stream)
 Writes an image to the stream.

Protected Types

typedef streaming_base< pixel,
info_holder > 
base

Protected Member Functions

 generator (image_info &info)
 Constructs a generator object using passed image_info object to store image information.
 generator (size_t width, size_t height)
 Constructs a generator object prepared to generate an image of specified width and height.

Detailed Description

template<typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false>
class png::generator< pixel, pixgen, info_holder, interlacing_supported >

Pixel generator class template.

Used as a base class for custom pixel generator classes as well as inside image class implementation to write pixels from the pixel buffer.

A usage example can be found in example/pixel_generator.cpp.

Encapsulates PNG image writing procedure. In order to create custom pixel generator, use CRTP trick:

 class pixel_generator
     : public png::generator< pixel, pixel_generator >
 {
     ...
 };

Your pixel generator 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 needed by the writer. The position of the row being written 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 storing an appropriate amount of pixels (i.e. the width of the image being written). 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. You do not have to implement this method unless you are going to support interlaced image generation.

An optional template parameter info_holder encapsulated image_info storage policy. Please refer to consumer class documentation for the detailed description of this parameter.

An optional bool template parameter interlacing_supported specifies whether writing interlacing images is supported by your generator class. It defaults to false. An attempt to write an interlaced image will result in throwing std::logic_error.

In order to fully support interlacing specify true for interlacing_supported parameter and implement reset() method. You _must_ generate the same pixels for every pass to get the correct PNG image output.

See also:
image, consumer


Member Typedef Documentation

template<typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false>
typedef streaming_base< pixel, info_holder > png::generator< pixel, pixgen, info_holder, interlacing_supported >::base [protected]


Constructor & Destructor Documentation

template<typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false>
png::generator< pixel, pixgen, info_holder, interlacing_supported >::generator ( image_info info  )  [inline, explicit, protected]

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

template<typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false>
png::generator< pixel, pixgen, info_holder, interlacing_supported >::generator ( size_t  width,
size_t  height 
) [inline, protected]

Constructs a generator object prepared to generate an image of specified width and height.


Member Function Documentation

template<typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false>
void png::generator< pixel, pixgen, info_holder, interlacing_supported >::write ( std::ostream &  stream  )  [inline]

Writes an image to the stream.

Essentially, this method constructs a writer object and instructs it to write the image to the stream. It handles writing interlaced images as long as your generator class supports this.


The documentation for this class was generated from the following file:
Generated on Sun Jul 8 19:33:01 2007 for png++ by  doxygen 1.5.2