Merge pull request #351 from Shnatsel/semver-breaking-deflate-level

Implement DEFLATE compression level control properly, with a semver break
This commit is contained in:
Aurelia Molzer authored and GitHub committed 2026-03-05 20:12:27 +00:00
commit 31c49ea6ef
5 files changed
+15 -27

No files matched your search

+8 -17
View File
@@ -7,24 +7,15 @@ pub struct Deflate {
level: FlateCompression,
}
/// The level of compression used by the Deflate algorithm.
/// It allows trading compression ratio for compression speed.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
#[derive(Default)]
pub enum DeflateLevel {
/// The fastest possible compression mode.
Fast = 1,
/// The conserative choice between speed and ratio.
#[default]
Balanced = 6,
/// The best compression available with Deflate.
Best = 9,
}
impl Deflate {
/// Create a new deflate compressor with a specific level of compression.
pub fn with_level(level: DeflateLevel) -> Self {
///
/// The valid levels are 1 through 9 inclusive. The default level is 6.
///
/// - `1` stands for light but fast compression
/// - `6` is the recommended balanced default
/// - `9` is maximum compression ratio at the cost of slow encoding
pub fn with_level(level: u8) -> Self {
Self {
level: FlateCompression::new(level as u32),
}
@@ -45,7 +36,7 @@ impl Deflate {
impl Default for Deflate {
fn default() -> Self {
Self::with_level(DeflateLevel::default())
Self::with_level(6)
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ mod packbits;
mod uncompressed;
#[cfg(feature = "deflate")]
pub use self::deflate::{Deflate, DeflateLevel};
pub use self::deflate::Deflate;
#[cfg(feature = "lzw")]
pub use self::lzw::Lzw;
+1 -3
View File
@@ -38,8 +38,6 @@ use self::writer::*;
/// [Predictor::Horizontal] is for integer sample types.
/// [Predictor::FloatingPoint] is for floating-point sample types (f32, f64).
pub type Predictor = crate::tags::Predictor;
#[cfg(feature = "deflate")]
pub type DeflateLevel = compression::DeflateLevel;
#[derive(Clone, Copy, PartialEq, Default)]
pub enum Compression {
@@ -48,7 +46,7 @@ pub enum Compression {
#[cfg(feature = "lzw")]
Lzw,
#[cfg(feature = "deflate")]
Deflate(DeflateLevel),
Deflate(u8),
Packbits,
}