Skip to main content

Crate otf_pixels_codec_raw

Crate otf_pixels_codec_raw 

Source
Expand description

Raw (uncompressed) pixel codec for otf-pixels.

Raw is the degenerate format: there is no container, no header and no magic bytes, so the caller supplies width, height, pixel format and stride (SPEC §Formats). That makes it the simplest possible exercise of the Decoder/Encoder contracts, and the format M1’s round-trip test uses at both ends of the pipeline.

Because there is no header, “malformed” raw input means exactly one thing: the stream is shorter than the declared dimensions require. That is reported as a malformed-input error, never a panic.

§Streaming

Both directions are strictly row-at-a-time. RawDecoder reads exactly one row per Decoder::read_row call and never buffers the image; RawEncoder writes each row straight through to the sink. Raw is therefore a true constant-memory format in both directions (SPEC §Formats).

use otf_pixels_codec_raw::{RawDecoder, RawFormat};
use otf_pixels_core::{Decoder, ImageDescriptor, PixelFormat};

let descriptor = ImageDescriptor::new(2, 2, PixelFormat::Gray8)?;
let pixels: &[u8] = &[1, 2, 3, 4];

let mut decoder = RawDecoder::new(RawFormat::packed(descriptor), pixels)?;
let mut row = vec![0_u8; descriptor.row_bytes()];
decoder.read_row(&mut row)?;
assert_eq!(row, [1, 2]);

Structs§

RawCodec
Format sniffing for raw streams.
RawDecoder
Decodes a raw pixel stream, one row per call.
RawEncoder
Encodes rows of pixels as a raw stream.
RawFormat
The layout of a raw pixel stream.