diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index ebe66f5..aa31d4f 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -20,10 +20,10 @@ use self::colortype::*; use self::writer::*; -/// Tiff encoder. +/// Encoder for Tiff and BigTiff files. /// /// With this type you can get a `DirectoryEncoder` or a `ImageEncoder` -/// to encode tiff ifd directories with images. +/// to encode Tiff/BigTiff ifd directories with images. /// /// See `DirectoryEncoder` and `ImageEncoder`. /// @@ -35,9 +35,14 @@ use self::writer::*; /// # let image_data = vec![0; 100*100*3]; /// use tiff::encoder::*; /// +/// // create a standard Tiff file /// let mut tiff = TiffEncoder::new(&mut file).unwrap(); -/// /// tiff.write_image::(100, 100, &image_data).unwrap(); +/// +/// // create a BigTiff file +/// let mut bigtiff = TiffEncoder::new_big(&mut file).unwrap(); +/// bigtiff.write_image::(100, 100, &image_data).unwrap(); +/// /// # } /// ``` pub struct TiffEncoder { @@ -45,19 +50,31 @@ pub struct TiffEncoder { kind: PhantomData, } +/// Constructor functions to create standard Tiff files. impl TiffEncoder { - pub fn new(writer: W) -> TiffResult { + /// Creates a new encoder for standard Tiff files. + /// + /// To create BigTiff files, use [`new_big`][TiffEncoder::new_big] or + /// [`new_generic`][TiffEncoder::new_generic]. + pub fn new(writer: W) -> TiffResult> { TiffEncoder::new_generic(writer) } } +/// Constructor functions to create BigTiff files. impl TiffEncoder { + /// Creates a new encoder for BigTiff files. + /// + /// To create standard Tiff files, use [`new`][TiffEncoder::new] or + /// [`new_generic`][TiffEncoder::new_generic]. pub fn new_big(writer: W) -> TiffResult { TiffEncoder::new_generic(writer) } } +/// Generic functions that are available for both Tiff and BigTiff encoders. impl TiffEncoder { + /// Creates a new Tiff or BigTiff encoder, inferred from the return type. pub fn new_generic(writer: W) -> TiffResult { let mut encoder = TiffEncoder { writer: TiffWriter::new(writer), @@ -69,12 +86,12 @@ impl TiffEncoder { Ok(encoder) } - /// Create a `DirectoryEncoder` to encode an ifd directory. + /// Create a [`DirectoryEncoder`] to encode an ifd directory. pub fn new_directory(&mut self) -> TiffResult> { DirectoryEncoder::new(&mut self.writer) } - /// Create an 'ImageEncoder' to encode an image one slice at a time. + /// Create an [`ImageEncoder`] to encode an image one slice at a time. pub fn new_image( &mut self, width: u32, @@ -470,7 +487,9 @@ struct DirectoryEntry { data: Vec, } -/// Helper trait to abstract over Tiff/BigTiff differences. +/// Trait to abstract over Tiff/BigTiff differences. +/// +/// Implemented for [`TiffKindStandard`] and [`TiffKindBig`]. pub trait TiffKind { /// The type of offset fields, `u32` for normal Tiff, `u64` for BigTiff. type OffsetType: TryFrom + Into + TiffValue; @@ -510,6 +529,7 @@ pub trait TiffKind { fn convert_slice(slice: &[Self::OffsetType]) -> &Self::OffsetArrayType; } +/// Create a standard Tiff file. pub struct TiffKindStandard; impl TiffKind for TiffKindStandard { @@ -544,6 +564,7 @@ impl TiffKind for TiffKindStandard { } } +/// Create a BigTiff file. pub struct TiffKindBig; impl TiffKind for TiffKindBig {