Pixel generator class template. More...
#include <generator.hpp>
Public Member Functions | |
template<typename ostream > | |
void | write (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. |
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:
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.
typedef streaming_base< pixel, info_holder > png::generator< pixel, pixgen, info_holder, interlacing_supported >::base [protected] |
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.
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.
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.