Crate tiff_encoder

source ·
Expand description

A crate for encoding TIFF files.

This crate allows to create any hierarchy of IFDs and to add any tags with any values to each. It does so while avoiding that the user needs to worry about the position of each structure in the file and to point to it with the correct offset.

The main structure of this crate, used to actually write the TIFF file, the is TiffFile. This structure writes the file in little endian by default (but that can be changed) and requires an IfdChain. This IfdChain consists of the first Ifd of the file, the one it points to (if any), and so on. Each Ifd has one or more entries, which are represented by a pair of FieldTag and FieldValues.

Examples

Creating a 256x256 bilevel image with every pixel black.

use tiff_encoder::*;
use tiff_encoder::tiff_type::*;
 
// 256*256/8 = 8192
// The image data will have 8192 bytes with 0 in every bit (each representing a
// black pixel).
let image_data = vec![0x00; 8192];
 
TiffFile::new(
    Ifd::new()
        .with_entry(tag::PhotometricInterpretation, SHORT::single(1)) // Black is zero
        .with_entry(tag::Compression, SHORT::single(1)) // No compression

        .with_entry(tag::ImageLength, LONG::single(256))
        .with_entry(tag::ImageWidth, LONG::single(256))

        .with_entry(tag::ResolutionUnit, SHORT::single(1)) // No resolution unit
        .with_entry(tag::XResolution, RATIONAL::single(1, 1))
        .with_entry(tag::YResolution, RATIONAL::single(1, 1))

        .with_entry(tag::RowsPerStrip, LONG::single(256)) // One strip for the whole image
        .with_entry(tag::StripByteCounts, LONG::single(8192)) 
        .with_entry(tag::StripOffsets, ByteBlock::single(image_data))
        .single() // This is the only Ifd in its IfdChain
).write_to("example.tif").unwrap();

Modules

Constants for commonly used tags in TIFF files, baseline or extended.
Representations of TIFF field data types.

Structs

Datablock that consists of a list of bytes.
A helper structure that provides convenience methods to write to a fs::File, being aware of the file’s Endianness.
A structure that holds both an IFD and all the values pointed at by its entries.
An ordered list of Ifds, each pointing to the next one.
A list of LONG values, each pointing to a specific Datablock.
A list of IFD values, each pointing to a specific Ifd.
Representation of a Tagged Image File.
A list of values of any given TiffType.

Enums

The byte order used within the TIFF file.

Traits

A block of data in the file pointed to by a field value, but that isn’t part of the field itself (such as image strips).
The values contained or pointed at by an IFD Field.

Type Definitions

16-bit identifier of a field entry.