Skip to main content

Crate zenpng

Crate zenpng 

Source
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§

ApngDecodeOutput
APNG decode output containing fully composed frames.
ApngEncodeConfig
APNG encode configuration.
ApngEncodeParams
Bundled parameters for APNG encoding with any Quantizer backend.
ApngFrame
A single composed APNG frame (canvas-sized pixels).
ApngFrameInfo
Per-frame APNG timing metadata.
ApngFrameInput
A single frame for APNG encoding.
AutoEncodeResult
Result of encode_auto, indicating which encoding path was chosen.
EncodeConfig
PNG encode configuration.
MultiFrameOutput
Output of multi-frame quantization with a shared palette.
PngAnimationFrameDecoder
APNG frame-by-frame decoder implementing AnimationFrameDecoder.
PngAnimationFrameEncoder
APNG frame-by-frame encoder implementing AnimationFrameEncoder.
PngChromaticities
PNG chromaticity values (cHRM chunk).
PngDecodeConfig
Decode configuration for PNG operations.
PngDecodeJob
Per-operation PNG decode job.
PngDecodeOutput
PNG decode output.
PngDecoder
Single-image PNG decoder.
PngDecoderConfig
PNG decoder configuration implementing DecoderConfig.
PngEncodeJob
Per-operation PNG encode job.
PngEncoder
Single-image PNG encoder.
PngEncoderConfig
PNG encoder configuration implementing EncoderConfig.
PngInfo
PNG image metadata from probing.
PngTime
Last modification time from tIME chunk.
QuantizeOutput
Output of a single-image quantization.
TextChunk
A text chunk from tEXt or zTXt.
ZenquantQuantizer
zenquant quantizer — perceptual median-cut with dithering and quality metrics.

Enums§

Compression
PNG compression effort.
Filter
PNG row filter strategy.
PhysUnit
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.
QualityGate
Quality gate for auto-encode: indexed (smaller) vs truecolor (lossless).
SignificantBits
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 Quantizer backend.
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§

PngLimitsDeprecated
Deprecated: use PngDecodeConfig instead.