nCine::PngCodec class

Reads and writes PNG images.

Reads all of PNG — grayscale, true color, indexed, with alpha or without, 1 to 16 bits per channel, with the transparency of a palette or of a color, and interlaced images. 16 bits are rounded to the nearest of 8. Writes an indexed image with its palette and the transparency of its entries, everything else as RGBA, 8 bits per channel; only with WITH_PNG_ENCODER.

Images can come from anywhere, so nothing is allocated before the data shows it's there: chunks are read as their data comes, an image with more pixels than allowed, or with less data than its size needs, is refused, and the image is inflated a row at a time straight into its pixels, with only the row before it kept. All of it is read byte by byte, the same on machines of either order of bytes.

Public static functions

static auto Decode(Death::IO::Stream& s, PngImage& image, const PngDecodeOptions& options = {}) -> PngError
Reads an image, an indexed one as indices with its palette, everything else as RGBA, the image is empty if it fails.
static auto DecodeRgba(Death::IO::Stream& s, PngRgbaImage& image, const PngDecodeOptions& options = {}) -> PngError
Reads an image as RGBA whatever it holds, the image is empty if it fails.
static auto GetErrorText(PngError error) -> const char*
Returns what an error means, in English, for logs.
static auto Encode(Death::IO::Stream& s, const PngImage& image) -> bool
Writes an image, returns false if it couldn't, or any write to the stream failed.
static auto EncodeRgba(Death::IO::Stream& s, std::int32_t width, std::int32_t height, const std::uint8_t* pixels) -> bool
Writes RGBA pixels, four bytes per pixel row by row, returns false if it couldn't, or any write failed.

Constructors, destructors, conversion operators

PngCodec() deleted

Function documentation

static PngError nCine::PngCodec::DecodeRgba(Death::IO::Stream& s, PngRgbaImage& image, const PngDecodeOptions& options = {})

Reads an image as RGBA whatever it holds, the image is empty if it fails.

An indexed image gets the colors of its palette, an entry the file doesn't list is opaque black.