Skip to main content

TiffEncoder

Struct TiffEncoder 

Source
pub struct TiffEncoder { /* private fields */ }
Expand description

Encoder for baseline TIFF images.

Writes chunky (PlanarConfiguration = 1) strips, optionally PackBits-compressed (Self::with_compression). Supports 8-bit grayscale/RGB and 1-bit bilevel; richer colour modes and compression schemes are added in later phases. Emits classic TIFF by default, or BigTIFF (64-bit offsets) when Self::with_big_tiff is set.

Implementations§

Source§

impl TiffEncoder

Source

pub fn new() -> Self

Creates an encoder that writes little-endian (II) TIFF.

Source

pub fn with_byte_order(self, order: ByteOrder) -> Self

Returns a copy of this encoder that writes in the given byte order.

Source

pub fn with_compression(self, compression: Compression) -> Self

Returns a copy of this encoder that compresses image data with compression.

Source

pub fn with_predictor(self, predictor: Predictor) -> Self

Returns a copy of this encoder that applies predictor before compression.

Predictor::HorizontalDifferencing requires 8-bit samples and pairs well with LZW.

Source

pub fn with_tiling(self, tile_width: u32, tile_height: u32) -> Self

Returns a copy of this encoder that writes the image as tiles of tile_width × tile_height pixels instead of strips.

Both dimensions must be positive multiples of 16. Tiling is currently supported for 8-bit images compressed with None/PackBits/LZW (no predictor).

Source

pub fn with_big_tiff(self, big_tiff: bool) -> Self

Returns a copy of this encoder that writes BigTIFF (magic 43, 64-bit offsets) instead of classic TIFF.

BigTIFF only widens the container’s structural fields; every colour mode, compression scheme, strip/tile layout, and multi-page feature applies unchanged, so this composes with the other builders. Its 64-bit offsets let a file exceed the 4 GiB classic limit. A reader detects the variant from the header magic, so no decoder flag is needed. Defaults to off.

Source

pub fn encode_palette8( &self, indices: ImageRef<'_, Indexed8>, palette: &Palette8, out: &mut Vec<u8>, ) -> Result<usize>

Encodes an 8-bit palette-colour image: one Indexed8 sample per pixel selecting an entry of palette.

indices is the width * height index buffer (already validated by ImageRef); palette is the 256-entry colour table. Returns the number of bytes written. Palette colour does not fit the single-buffer EncodeImage shape (it needs the separate colour table), so it stays an inherent method.

Source

pub fn encode_pages_rgb8( &self, pages: &[ImageRef<'_, Rgb8>], out: &mut Vec<u8>, ) -> Result<usize>

Encodes several 8-bit Rgb8 images as the pages of one multi-page TIFF.

Each page is a validated ImageRef. Returns the number of bytes written.

§Errors

Returns Error::InvalidInput if pages is empty.

Trait Implementations§

Source§

impl Clone for TiffEncoder

Source§

fn clone(&self) -> TiffEncoder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TiffEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TiffEncoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl EncodeImage<Bilevel> for TiffEncoder

Source§

fn encode_image( &self, image: ImageRef<'_, Bilevel>, out: &mut Vec<u8>, ) -> Result<usize>

Packs one byte per pixel (0 = black, non-zero = white) MSB-first into bits, BlackIsZero.

Source§

impl EncodeImage<Cmyk8> for TiffEncoder

Source§

fn encode_image( &self, image: ImageRef<'_, Cmyk8>, out: &mut Vec<u8>, ) -> Result<usize>

PhotometricInterpretation = Separated (5); each sample is ink coverage (0 = 0 %, 255 = 100 %).

Source§

impl EncodeImage<Gray8> for TiffEncoder

Source§

fn encode_image( &self, image: ImageRef<'_, Gray8>, out: &mut Vec<u8>, ) -> Result<usize>

Encode image into out (appended), returning the number of bytes written. Read more
Source§

impl EncodeImage<Rgb8> for TiffEncoder

Source§

fn encode_image( &self, image: ImageRef<'_, Rgb8>, out: &mut Vec<u8>, ) -> Result<usize>

Encode image into out (appended), returning the number of bytes written. Read more
Source§

impl EncodeImage<Rgba8> for TiffEncoder

Source§

fn encode_image( &self, image: ImageRef<'_, Rgba8>, out: &mut Vec<u8>, ) -> Result<usize>

Stores the fourth sample as unassociated alpha (ExtraSamples = 2, not premultiplied).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.