[][src]Crate ilda_idtf

A complete implementation of the ILDA Image Data Transfer Format Specification, Revision 011, 2014-11-16.

This library provides efficient reading and writing of IDTF. The reader implementation uses a zero-copy approach where structures are mapped directly to the memory from which they are read.

Usage

The SectionReader type can be used to read IDTF sections from any type implementing std::io::Read. This allows for efficiently reading the format from any byte source (e.g. file, memory, socket, etc).

let mut reader = ilda_idtf::SectionReader::new(reader);

The open function is provided as a convenience for opening a buffered IDTF SectionReader for the file at the given path.

let mut reader = ilda_idtf::open(path).unwrap();

The SectionReader::read_next method allows for iteration over the sections contained within.

while let Ok(Some(section)) = reader.read_next() {
    // ...
}

Each yielded Section provides access to the Header and the inner reader. The exact reader kind is determined via the Format specified within the header. The user must pattern match on the section's reader field in order to retrieve an instance of the correct subsection reader type. The user may then read the associated subsection data.

match section.reader {
    ilda_idtf::SubsectionReaderKind::Coords3dIndexedColor(mut r) => {
        while let Some(point) = r.read_next().unwrap() {
            // ...
        }
    }
    ilda_idtf::SubsectionReaderKind::Coords2dIndexedColor(mut r) => {
        while let Some(point) = r.read_next().unwrap() {
            // ...
        }
    }
    ilda_idtf::SubsectionReaderKind::ColorPalette(mut r) => {
        while let Some(palette) = r.read_next().unwrap() {
            // ...
        }
    }
    ilda_idtf::SubsectionReaderKind::Coords3dTrueColor(mut r) => {
        while let Some(point) = r.read_next().unwrap() {
            // ...
        }
    }
    ilda_idtf::SubsectionReaderKind::Coords2dTrueColor(mut r) => {
        while let Some(point) = r.read_next().unwrap() {
            // ...
        }
    }
}

In order to interpret the indexed color data formats, a color palette must be used. A color palette is an ordered list of RGB colors. While the palette should be specified by a preceding Section, this is not always the case. The ILDA IDTF specification recommends a default palette. This palette is provided via the DEFAULT_PALETTE constant.

Modules

layout

An ILDA file consists of sections which either contain a frame or a color palette. Eachsection consists of a fixed length header followed by a variable number of data records, which are either frame points or color palette colors.

Structs

Section

Contains a verified Header and a reader for the section contents.

SectionReader

Reads a sequence of frames from the ILDA IDTF spec from a stream of bytes.

SubsectionReader

Reads len consecutive subsections of type T.

Enums

SubsectionReaderKind

The subsection reader kind determined via the header's format field.

Constants

DEFAULT_PALETTE

As recommended in the specification appendix.

Traits

LayoutBuffer

A helper trait for producing and working with precisely sized buffers for IDTF layout.

Functions

open

Open the file at the given path as a SectionReader.

Type Definitions

BufFileSectionReader

A SectionReader that reads from a buffered file.

ColorPaletteReader
Coords2dIndexedColorReader
Coords2dTrueColorReader
Coords3dIndexedColorReader
Coords3dTrueColorReader