Switch to using zopfli::Options in prep for https://github.com/zopfli-rs/zopfli/pull/21
This commit is contained in:
parent
cd57847c15
commit
98a34c0722
3 changed files with 7 additions and 19 deletions
|
|
@ -7,8 +7,6 @@ pub use deflater::inflate;
|
|||
use std::io::{BufWriter, copy, Cursor, Write};
|
||||
use std::{fmt, fmt::Display, io};
|
||||
|
||||
#[cfg(feature = "zopfli")]
|
||||
use std::num::NonZeroU8;
|
||||
#[cfg(feature = "zopfli")]
|
||||
use zopfli::{DeflateEncoder, Options};
|
||||
#[cfg(feature = "zopfli")]
|
||||
|
|
@ -29,10 +27,8 @@ pub enum Deflaters {
|
|||
#[cfg(feature = "zopfli")]
|
||||
/// Use the better but slower Zopfli implementation
|
||||
Zopfli {
|
||||
/// The number of compression iterations to do. 15 iterations are fine
|
||||
/// for small files, but bigger files will need to be compressed with
|
||||
/// less iterations, or else they will be too slow.
|
||||
iterations: NonZeroU8,
|
||||
/// Zopfli compression options
|
||||
options: Options,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +41,7 @@ impl Deflater for Deflaters {
|
|||
let compressed = match self {
|
||||
Self::Libdeflater { compression } => deflate(data, *compression, max_size)?,
|
||||
#[cfg(feature = "zopfli")]
|
||||
Self::Zopfli { iterations } => zopfli_deflate(data, *iterations)?,
|
||||
Self::Zopfli { options } => zopfli_deflate(data, options)?,
|
||||
};
|
||||
if let Some(max) = max_size.get() {
|
||||
if compressed.len() > max {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,12 @@
|
|||
use std::io::{Error, ErrorKind, Read};
|
||||
use crate::{PngError, PngResult};
|
||||
use std::num::NonZeroU8;
|
||||
use simd_adler32::Adler32;
|
||||
|
||||
pub fn deflate(data: &[u8], iterations: NonZeroU8) -> PngResult<Vec<u8>> {
|
||||
pub fn deflate(data: &[u8], options: &zopfli::Options) -> PngResult<Vec<u8>> {
|
||||
use std::cmp::max;
|
||||
|
||||
let mut output = Vec::with_capacity(max(1024, data.len() / 20));
|
||||
let options = zopfli::Options {
|
||||
iteration_count: iterations,
|
||||
..Default::default()
|
||||
};
|
||||
match zopfli::compress(&options, &zopfli::Format::Zlib, data, &mut output) {
|
||||
match zopfli::compress(options, &zopfli::Format::Zlib, data, &mut output) {
|
||||
Ok(_) => (),
|
||||
Err(_) => return Err(PngError::new("Failed to compress in zopfli")),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ use oxipng::RowFilter;
|
|||
use oxipng::StripChunks;
|
||||
use oxipng::{InFile, OutFile};
|
||||
use std::fs::DirBuilder;
|
||||
#[cfg(feature = "zopfli")]
|
||||
use std::num::NonZeroU8;
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
use std::time::Duration;
|
||||
|
|
@ -552,9 +550,8 @@ fn parse_opts_into_struct(
|
|||
|
||||
if matches.is_present("zopfli") {
|
||||
#[cfg(feature = "zopfli")]
|
||||
if let Some(iterations) = NonZeroU8::new(15) {
|
||||
opts.deflate = Deflaters::Zopfli { iterations };
|
||||
}
|
||||
let zopfli_opts = zopfli::Options::default();
|
||||
opts.deflate = Deflaters::Zopfli { options: zopfli_opts };
|
||||
} else if let Deflaters::Libdeflater { compression } = &mut opts.deflate {
|
||||
if let Some(x) = matches.get_one::<i64>("compression") {
|
||||
*compression = *x as u8;
|
||||
|
|
|
|||
Loading…
Reference in a new issue