Merge pull request #153 from mindQ-GmbH-Co-KG/compression-release

fixed deflate and packbits
This commit is contained in:
HeroicKatora authored and GitHub committed 2022-01-11 18:53:12 +01:00
commit 77f15b5c0a
3 files changed
+9 -3

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)
} }
} }
+7 -2
View File
@@ -12,7 +12,7 @@ use std::{
use crate::{ use crate::{
error::TiffResult, error::TiffResult,
tags::{ResolutionUnit, Tag}, tags::{CompressionMethod, ResolutionUnit, Tag},
}; };
pub mod colortype; pub mod colortype;
@@ -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 {
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;