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 >:

## Public Member Functions

template<typename ostream >
void | write (ostream &stream)
| Writes an image to the stream. More...
Public Member Functions inherited from png::streaming_base< pixel, info_holder >
| streaming_base (image_info &info)
| streaming_base (uint_32 width, uint_32 height)
image_info const & | get_info () const

## 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. More...
| generator (size_t width, size_t height)
| Constructs a generator object prepared to generate an image of specified width and height. More...
Protected Member Functions inherited from png::streaming_base< pixel, info_holder >
void | reset (size_t)
image_info & | get_info ()

## Additional Inherited Members

Public Types inherited from png::streaming_base< pixel, info_holder >
typedef pixel_traits< pixel > | traits
Protected Attributes inherited from png::streaming_base< pixel, info_holder >
info_holder | m_info_holder

## 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 a 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(png::uint_32 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

## base

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

## generator() [1/2]

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.

## generator() [2/2]

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

## write()

template<typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false>
template<typename ostream >

void png::generator< pixel, pixgen, info_holder, interlacing_supported >::write | ( | 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.

Referenced by png::image< pixel, pixel_buffer_type >::write_stream().

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

- generator.hpp