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
{
...
};
Your pixel consumer 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 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:
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
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.