Skip to main content

Crate pltrs_codec

Crate pltrs_codec 

Source
Expand description

Self-contained image and compression codecs for pltrs.

The crate has no dependencies and no unsafe code. It provides:

  • av1 — an intra-only AV1 encoder for still pictures: 4:2:0, 4:4:4 and monochrome, lossy or lossless.
  • avif — AVIF files of RGBA pixels, coded with av1 and laid out as Pillow writes them through libavif.
  • base64 — base64 encoding for embedding binary data in text, and decoding.
  • checksum — CRC-32 (PNG, gzip) and Adler-32 (zlib) checksums, both as incremental hashers and as one-shot helpers.
  • gif — animated GIF encoding with a shared, quantised palette, and decoding of a file’s first frame as Pillow opens it.
  • jpeg — baseline JPEG encoding matching Pillow’s output byte for byte, and baseline, extended and progressive decoding whose pixels are Pillow’s (libjpeg-turbo’s arithmetic, ported).
  • deflate — raw DEFLATE (RFC 1951): a compressor writing zlib-ng 2.3’s bytes at levels 0–9 and every strategy, and a strictly validating, table-driven decompressor.
  • tiff — uncompressed RGBA TIFF files, laid out as Pillow writes them, and decoding of the TIFF layouts and compressions Pillow reads.
  • raster — decoded JPEG, TIFF, GIF and WebP images in the Pillow mode the same file opens in, convertible to RGBA as Pillow converts them.
  • sha1 — the SHA-1 digest, as the WebSocket handshake needs it.
  • sha256 — the SHA-256 digest (SVG ids, the text.usetex cache).
  • webp — decoding of WebP files as Pillow opens them, lossless (VP8L) and lossy (VP8, with alpha) bitstreams, still or animated, and lossless encoding of still images and animations.
  • zlib — the RFC 1950 container (header and Adler-32 trailer) around DEFLATE, in both directions.
  • png — a PNG encoder (grey, grey + alpha, RGB and RGBA at 8 or 16 bits, rows filtered and compressed as Pillow does with zlib-ng, pHYs resolution and text metadata) and a decoder for every standard PNG flavour: all colour types and bit depths, palettes, tRNS transparency and Adam7 interlacing.

Every decoder in this crate treats its input as untrusted: malformed data produces a descriptive error value, never a panic, and declared image sizes are checked against the input before anything is allocated.

§Example

use pltrs_codec::png::{self, ImageRef, PhysicalDimensions};

// A 2×1 RGBA image: an opaque red pixel and a half-transparent blue one.
let pixels = [255, 0, 0, 255, 0, 0, 255, 128];
let image = ImageRef::rgba8(2, 1, &pixels)?;
let bytes = png::Encoder::new().dpi(100.0).encode(image)?;

let decoded = png::decode(&bytes)?;
assert_eq!(decoded.to_rgba8(), pixels);
assert_eq!(decoded.metadata().physical, PhysicalDimensions::from_dpi(100.0));

Re-exports§

pub use deflate::CompressionLevel;

Modules§

av1
AV1 still pictures: an intra-only encoder that writes the sequence header and the key frame of a still picture, following the AV1 Bitstream & Decoding Process Specification.
avif
AVIF files: AV1 still pictures in the HEIF container, written as Pillow writes them through libavif (matplotlib’s print_avif).
base64
Base64 (RFC 4648, standard alphabet with padding), as used to embed images in HTML and SVG documents: encoding, and decoding.
checksum
Checksums used by the zlib and PNG formats.
deflate
Raw DEFLATE (RFC 1951) compression and decompression.
gif
GIF files.
jpeg
JPEG encoding and decoding, both mirroring libjpeg-turbo’s arithmetic as Pillow uses it.
png
PNG encoding and decoding.
raster
Decoded images as Pillow presents them: the JPEG, TIFF and GIF decoders all produce a Raster whose Pixels variant is the Pillow image mode the same file opens in, holding the same values. Raster::to_rgba8 is Pillow’s convert("RGBA").
sha1
SHA-1 (RFC 3174), the digest the WebSocket handshake (RFC 6455) uses to derive Sec-WebSocket-Accept from the client’s key.
sha256
SHA-256 (FIPS 180-4): the SVG backend’s content-derived ids and the names of the files text.usetex caches.
tiff
TIFF files.
webp
WebP files.
zlib
The zlib format (RFC 1950): a two-byte header, a DEFLATE stream and an Adler-32 trailer.