Compare commits

...
Author SHA1 Message Date
A. Molzer 3340fc04e0 Publicly export TiffWriter 2026-03-31 18:29:48 +02:00
2 changed files with 26 additions and 0 deletions

No files matched your search

+10
View File
@@ -28,6 +28,8 @@ use self::compression::Compression as Comp;
use self::compression::*; use self::compression::*;
use self::writer::*; use self::writer::*;
pub use self::writer::TiffWriter;
/// Type of prediction to prepare the image with. /// Type of prediction to prepare the image with.
/// ///
/// Image data can be very unpredictable, and thus very hard to compress. Predictors are simple /// Image data can be very unpredictable, and thus very hard to compress. Predictors are simple
@@ -185,6 +187,14 @@ impl<W: Write + Seek, K: TiffKind> TiffEncoder<W, K> {
self self
} }
/// Get a mutable reference to a writer for raw values.
///
/// This can be used to write custom data sections to the underlying writer that may or may not
/// be referenced in the IFDs of the tiff structure.
pub fn get_mut(&mut self) -> &mut TiffWriter<W> {
&mut self.writer
}
/// Create a [`DirectoryEncoder`] to encode an ifd directory. /// Create a [`DirectoryEncoder`] to encode an ifd directory.
#[deprecated = "`image_directory` replaced the old behavior and clarifies the intent"] #[deprecated = "`image_directory` replaced the old behavior and clarifies the intent"]
#[doc(hidden)] #[doc(hidden)]
+16
View File
@@ -40,6 +40,7 @@ pub fn write_bigtiff_header<W: Write>(writer: &mut TiffWriter<W>) -> TiffResult<
Ok(()) Ok(())
} }
/// A writer that tracks offset and can compress.
pub struct TiffWriter<W> { pub struct TiffWriter<W> {
writer: W, writer: W,
offset: u64, offset: u64,
@@ -61,6 +62,7 @@ impl<W: Write> TiffWriter<W> {
self.compressor = compressor; self.compressor = compressor;
} }
/// Unset the compression.
pub fn reset_compression(&mut self) { pub fn reset_compression(&mut self) {
self.compressor = Compressor::default(); self.compressor = Compressor::default();
} }
@@ -73,6 +75,7 @@ impl<W: Write> TiffWriter<W> {
self.offset() - core::mem::size_of::<K::OffsetType>() as u64 self.offset() - core::mem::size_of::<K::OffsetType>() as u64
} }
/// Get the number of bytes written by the last write operation.
pub fn last_written(&self) -> u64 { pub fn last_written(&self) -> u64 {
self.byte_count self.byte_count
} }
@@ -183,6 +186,19 @@ impl<W: Write> TiffWriter<W> {
} }
} }
/// Write uncompressed bytes to the raw underlying file.
impl<W: Write> std::io::Write for TiffWriter<W> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
let n = self.writer.write(buf)?;
self.offset += n as u64;
Ok(n)
}
fn flush(&mut self) -> io::Result<()> {
self.writer.flush()
}
}
impl<W: Seek> TiffWriter<W> { impl<W: Seek> TiffWriter<W> {
pub fn goto_offset(&mut self, offset: u64) -> Result<(), io::Error> { pub fn goto_offset(&mut self, offset: u64) -> Result<(), io::Error> {
self.offset = offset; self.offset = offset;