Reads PNG metadata and image data for embedding in PDF image XObjects.
PNG image data is stored as zlib-compressed scanlines in IDAT
chunks. PDF can consume non-alpha image data directly through
/FlateDecode when paired with PNG predictor decode parameters.
For alpha PNGs, this module decodes PNG scanline filters, separates color bytes from alpha bytes, and returns a separate soft-mask stream.
This module supports non-interlaced 8-bit grayscale, RGB, grayscale with alpha, and RGBA PNG images. Adam7 interlacing and palette PNGs are intentionally unsupported.
Summary
Functions
Reads PNG metadata and concatenated compressed IDAT data.
Reads PNG metadata and raises when the binary is invalid or unsupported.
Returns whether a binary begins with the PNG signature.
Types
@type color_space() :: :device_gray | :device_rgb
@type error_reason() :: :invalid_png | :missing_ihdr | :missing_idat | :truncated_chunk | :invalid_ihdr | :unsupported_compression | :unsupported_filter | :unsupported_interlace | :invalid_image_data | {:unsupported_color_type, non_neg_integer()} | {:unsupported_bit_depth, non_neg_integer(), non_neg_integer()}
@type metadata() :: %{ width: pos_integer(), height: pos_integer(), color_type: non_neg_integer(), bits_per_component: pos_integer(), components: pos_integer(), color_space: color_space(), compressed_data: binary(), smask_compressed_data: binary() | nil }
Functions
@spec parse(binary()) :: {:ok, metadata()} | {:error, error_reason()}
Reads PNG metadata and concatenated compressed IDAT data.
Reads PNG metadata and raises when the binary is invalid or unsupported.
Returns whether a binary begins with the PNG signature.