PngReader Class Reference

#include <Pt/Gfx/PngReader.h>

PNG image reader. More...

Public Member Functions

 PngReader ()
 Default Constructor.
 PngReader (std::istream &is, Image &image)
 Construct with target stream and image.
 ~PngReader ()
 Destructor.
void attach (std::istream &is, Image &image)
 Attach to target stream and image.
void detach ()
 Detach from target stream.
void reset ()
 Reset to begin new decompression.
Image * advance (std::streamsize importSize=0)
 Reads image data from the target stream.
Image & get ()
 Reads the whole image from the stream.

Detailed Description

PngReader decodes PNG data from an iostream into an Image. Attach a stream and an image, then call get() to read the whole image, or advance() to consume bytes as they become available. The reader does not own the stream or the image.

When advance() is called with import size 0, only bytes already in the stream buffer are consumed. A positive import size may block on the underlying stream.

Member Function Documentation

◆ advance()

Image * advance ( std::streamsize importSize = 0)

Consumes bytes currently available in the stream buffer and feeds them to the PNG decoder.

When importSize is 0 (default), only bytes already available via in_avail() are consumed (non-blocking, suitable for event-loop use). When importSize is greater than 0, up to that many bytes are read from the underlying stream via sgetn(), which may block until data arrives (suitable for file or thread use).

Returns
Pointer to the completed Image once all PNG data has been decoded, nullptr when more data is needed.