fixed deflate and packbits

This commit is contained in:
Pretorer committed 2022-01-11 15:43:00 +01:00
1 parent 1d8cbbc6a1
commit 9df18a1674
3 files changed
+8 -2

No files matched your search

+1 -1
View File
@@ -53,7 +53,7 @@ impl Compression for Deflate {
impl CompressionAlgorithm for Deflate { impl CompressionAlgorithm for Deflate {
fn write_to<W: Write>(&mut self, writer: &mut W, bytes: &[u8]) -> Result<u64, io::Error> { fn write_to<W: Write>(&mut self, writer: &mut W, bytes: &[u8]) -> Result<u64, io::Error> {
let mut encoder = ZlibEncoder::new(writer, self.level); let mut encoder = ZlibEncoder::new(writer, self.level);
encoder.write(&bytes)?; encoder.write_all(&bytes)?;
encoder.try_finish()?; encoder.try_finish()?;
Ok(encoder.total_out()) Ok(encoder.total_out())
} }
+1
View File
@@ -122,6 +122,7 @@ impl CompressionAlgorithm for Packbits {
bufwriter.write(&bytes[pending_index..pending_index + bytes_pending as usize])?; bufwriter.write(&bytes[pending_index..pending_index + bytes_pending as usize])?;
} }
bufwriter.flush()?;
Ok(bytes_written) Ok(bytes_written)
} }
} }
+6 -1
View File
@@ -354,7 +354,12 @@ impl<'a, W: 'a + Write + Seek, T: ColorType, K: TiffKind, D: Compression>
// Limit the strip size to prevent potential memory and security issues. // Limit the strip size to prevent potential memory and security issues.
// Also keep the multiple strip handling 'oiled' // Also keep the multiple strip handling 'oiled'
let rows_per_strip = (1_000_000 + row_bytes - 1) / row_bytes; let rows_per_strip = {
match D::COMPRESSION_METHOD {
crate::tags::CompressionMethod::PackBits => 1, // Each row must be packed separately. Do not compress across row boundaries
_ => (1_000_000 + row_bytes - 1) / row_bytes,
}
};
let strip_count = (u64::from(height) + rows_per_strip - 1) / rows_per_strip; let strip_count = (u64::from(height) + rows_per_strip - 1) / rows_per_strip;