Expand description
PNG encoding and decoding with zencodec trait integration.
Uses zenflate for both compression and decompression, typed pixel buffers
(imgref + rgb), metadata roundtrip (ICC/EXIF/XMP), and optional palette
quantization via zenquant.
§Quick start
use zenpng::{decode, probe, encode_rgb8, EncodeConfig, PngDecodeConfig};
use enough::Unstoppable;
use imgref::ImgVec;
use rgb::Rgb;
// Decode
let data: &[u8] = &[]; // your PNG bytes
let output = decode(data, &PngDecodeConfig::default(), &Unstoppable)?;
println!("{}x{}", output.info.width, output.info.height);
// Encode
let pixels = ImgVec::new(vec![Rgb { r: 0u8, g: 0, b: 0 }; 64], 8, 8);
let encoded = encode_rgb8(pixels.as_ref(), None, &EncodeConfig::default(), &Unstoppable, &Unstoppable)?;§zencodec traits
PngEncoderConfig implements [zencodec::EncoderConfig] and PngDecoderConfig
implements [zencodec::DecoderConfig] for use with multi-codec dispatchers.
Note: PngDecodeConfig (used in the quick start) is the lower-level decode config;
PngDecoderConfig wraps it for the zencodec trait interface.
Modules§
- detect
- PNG source analysis, compression assessment, and re-encoding recommendations. PNG source analysis and re-encoding recommendations.
Structs§
- Apng
Decode Output - APNG decode output containing fully composed frames.
- Apng
Encode Config - APNG encode configuration.
- Apng
Encode Params - Bundled parameters for APNG encoding with any
Quantizerbackend. - Apng
Frame - A single composed APNG frame (canvas-sized pixels).
- Apng
Frame Info - Per-frame APNG timing metadata.
- Apng
Frame Input - A single frame for APNG encoding.
- Auto
Encode Result - Result of
encode_auto, indicating which encoding path was chosen. - Encode
Config - PNG encode configuration.
- Multi
Frame Output - Output of multi-frame quantization with a shared palette.
- PngAnimation
Frame Decoder - APNG frame-by-frame decoder implementing
AnimationFrameDecoder. - PngAnimation
Frame Encoder - APNG frame-by-frame encoder implementing
AnimationFrameEncoder. - PngChromaticities
- PNG chromaticity values (cHRM chunk).
- PngDecode
Config - Decode configuration for PNG operations.
- PngDecode
Job - Per-operation PNG decode job.
- PngDecode
Output - PNG decode output.
- PngDecoder
- Single-image PNG decoder.
- PngDecoder
Config - PNG decoder configuration implementing
DecoderConfig. - PngEncode
Job - Per-operation PNG encode job.
- PngEncoder
- Single-image PNG encoder.
- PngEncoder
Config - PNG encoder configuration implementing
EncoderConfig. - PngInfo
- PNG image metadata from probing.
- PngTime
- Last modification time from tIME chunk.
- Quantize
Output - Output of a single-image quantization.
- Text
Chunk - A text chunk from tEXt or zTXt.
- Zenquant
Quantizer - zenquant quantizer — perceptual median-cut with dithering and quality metrics.
Enums§
- Compression
- PNG compression effort.
- Filter
- PNG row filter strategy.
- Phys
Unit - Physical pixel dimensions unit (pHYs chunk).
- PngBackground
- Background color from bKGD chunk.
- PngError
- Errors from PNG encode/decode operations.
- PngWarning
- Non-fatal issues detected during PNG decoding.
- Quality
Gate - Quality gate for auto-encode: indexed (smaller) vs truecolor (lossless).
- Significant
Bits - Significant bits per channel from sBIT chunk.
Traits§
- Quantizer
- A color quantizer that reduces RGBA8 images to ≤256 indexed colors.
Functions§
- available_
backends - List available quantizer backend names (based on enabled features).
- decode
- Decode PNG to pixels.
- decode_
apng - Decode APNG with full compositing, returning canvas-sized frames.
- default_
quantizer - Create a default quantizer (zenquant if available, else first enabled backend).
- encode_
apng - Encode canvas-sized RGBA8 frames into a truecolor APNG file.
- encode_
apng_ auto - Encode APNG frames, auto-choosing indexed or truecolor, with any
Quantizer. - encode_
apng_ indexed - Encode canvas-sized RGBA8 frames into an indexed APNG with any
Quantizer. - encode_
auto - Encode RGBA8 pixels, automatically choosing indexed or truecolor PNG.
- encode_
gray8 - Encode Gray8 pixels to PNG.
- encode_
gray16 - Encode Gray16 pixels to PNG.
- encode_
indexed - Encode RGBA8 pixels to indexed PNG using any
Quantizerbackend. - encode_
rgb8 - Encode RGB8 pixels to PNG.
- encode_
rgb16 - Encode RGB16 pixels to PNG.
- encode_
rgba8 - Encode RGBA8 pixels to PNG.
- encode_
rgba16 - Encode RGBA16 pixels to PNG.
- probe
- Probe PNG metadata without decoding pixels.
- quantizer_
by_ name - Create a quantizer by name at runtime.
Type Aliases§
- PngLimits
Deprecated - Deprecated: use
PngDecodeConfiginstead.