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
{
...
};
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.
- See Also
- image, consumer