Remove zlib dependency, which broke with the new version of zlib
This commit is contained in:
parent
705d280f8b
commit
8e02aa8294
7 changed files with 55 additions and 215 deletions
|
|
@ -1,3 +1,6 @@
|
|||
**Version 0.14.1**
|
||||
- Remove zlib dependency and switch entirely to miniz, since zlib 1.2.11 was not working with oxipng. This costs some performance, but is better than having a broken application.
|
||||
|
||||
**Version 0.14.0**
|
||||
- Performance optimizations
|
||||
- [SEMVER_MAJOR] Bump minimum rustc version to 1.13.0
|
||||
|
|
|
|||
84
Cargo.lock
generated
84
Cargo.lock
generated
|
|
@ -1,6 +1,6 @@
|
|||
[root]
|
||||
name = "oxipng"
|
||||
version = "0.14.0"
|
||||
version = "0.14.1"
|
||||
dependencies = [
|
||||
"bit-vec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -10,7 +10,6 @@ dependencies = [
|
|||
"image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libz-sys 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -66,9 +65,9 @@ name = "cargo_metadata"
|
|||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -80,7 +79,7 @@ dependencies = [
|
|||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term_size 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term_size 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -212,16 +211,6 @@ name = "libc"
|
|||
version = "0.2.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.4"
|
||||
|
|
@ -288,11 +277,6 @@ dependencies = [
|
|||
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.6.2"
|
||||
|
|
@ -311,7 +295,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.3.12"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
|
@ -342,7 +326,7 @@ dependencies = [
|
|||
"memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"simd 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
|
@ -366,36 +350,36 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "0.9.7"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde_codegen_internals"
|
||||
version = "0.13.0"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"syn 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.11.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "0.9.7"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quote 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_codegen_internals 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_codegen_internals 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.11.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "0.9.6"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -410,16 +394,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.11.4"
|
||||
version = "0.11.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quote 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"synom 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synom"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quote 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "term_size"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -438,7 +431,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -544,7 +537,6 @@ dependencies = [
|
|||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b"
|
||||
"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5"
|
||||
"checksum libz-sys 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e5ee912a45d686d393d5ac87fac15ba0ba18daae14e8e7543c63ebf7fb7e970c"
|
||||
"checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1"
|
||||
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
|
||||
"checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726"
|
||||
|
|
@ -554,26 +546,26 @@ dependencies = [
|
|||
"checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf"
|
||||
"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c"
|
||||
"checksum num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a225d1e2717567599c24f88e49f00856c6e825a12125181ee42c4257e3688d39"
|
||||
"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
|
||||
"checksum png 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3cb773e9a557edb568ce9935cf783e3cdcabe06a9449d41b3e5506d88e582c82"
|
||||
"checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45"
|
||||
"checksum quote 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e7b44fd83db28b83c1c58187159934906e5e955c812e211df413b76b03c909a5"
|
||||
"checksum quote 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "08de3f12e670f83f61e450443cbae34496a35b665691fd8e99b24ec662f75865"
|
||||
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
|
||||
"checksum rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50c575b58c2b109e2fbc181820cbe177474f35610ff9e357dc75f6bac854ffbf"
|
||||
"checksum regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4278c17d0f6d62dfef0ab00028feb45bd7d2102843f80763474eeb1be8a10c01"
|
||||
"checksum regex-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9191b1f57603095f105d317e375d19b1c9c5c3185ea9633a99a6dcbed04457"
|
||||
"checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b"
|
||||
"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f"
|
||||
"checksum serde 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1e0ed773960f90a78567fcfbe935284adf50c5d7cf119aa2cf43bb0b4afa69bb"
|
||||
"checksum serde_codegen_internals 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c3172bf2940b975c0e4f6ab42a511c0a4407d4f46ccef87a9d3615db5c26fa96"
|
||||
"checksum serde_derive 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6af30425c5161deb200aac4803c62b903eb3be7e889c5823d0e16c4ce0ce989c"
|
||||
"checksum serde_json 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)" = "e095e4e94e7382b76f48e93bd845ffddda62df8dfd4c163b1bfa93d40e22e13a"
|
||||
"checksum serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "204db0f2a5335be7313fd4453132fd56d2085aed081c673140a256772903e116"
|
||||
"checksum serde_codegen_internals 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5113d5bd16471b183803b374f0fe4877ad9658b95e33b11f4a004d73aacc74a"
|
||||
"checksum serde_derive 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "e88ec062a02cbebfd6276044a305d665a9919b497aa6acb2e12c070d1a50d32d"
|
||||
"checksum serde_json 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6501ac6f8b74f9b1033f7ddf79a08edfa0f58d6f8e3190cb8dc97736afa257a8"
|
||||
"checksum simd 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "63b5847c2d766ca7ce7227672850955802fabd779ba616aeabead4c2c3877023"
|
||||
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
|
||||
"checksum syn 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f94368aae82bb29656c98443a7026ca931a659e8d19dcdc41d6e273054e820"
|
||||
"checksum term_size 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "71662702fe5cd2cf95edd4ad655eea42f24a87a0e44059cbaa4e55260b7bc331"
|
||||
"checksum syn 0.11.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0e28da8d02d75d1e58b89258e0741128f0b0d8a8309fb5c627be0fbd37a76c67"
|
||||
"checksum synom 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8fece1853fb872b0acdc3ff88f37c474018e125ef81cd4cb8c0ca515746b62ed"
|
||||
"checksum term_size 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "07b6c1ac5b3fffd75073276bca1ceed01f67a28537097a2a9539e116e50fb21a"
|
||||
"checksum thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4437c97558c70d129e40629a5b385b3fb1ffac301e63941335e4d354081ec14a"
|
||||
"checksum thread_local 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7793b722f0f77ce716e7f1acf416359ca32ff24d04ffbac4269f44a4a83be05d"
|
||||
"checksum thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c85048c6260d17cf486ceae3282d9fb6b90be220bf5b28c400f5485ffc29f0c7"
|
||||
"checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4"
|
||||
"checksum unicode-normalization 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e28fa37426fceeb5cf8f41ee273faa7c82c47dc8fba5853402841e665fcd86ff"
|
||||
"checksum unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18127285758f0e2c6cf325bb3f3d138a12fee27de4f23e146cd6a179f26c2cf3"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ homepage = "https://github.com/shssoichiro/oxipng"
|
|||
license = "MIT"
|
||||
name = "oxipng"
|
||||
repository = "https://github.com/shssoichiro/oxipng"
|
||||
version = "0.14.0"
|
||||
version = "0.14.1"
|
||||
|
||||
[lib]
|
||||
name = "oxipng"
|
||||
|
|
@ -25,7 +25,6 @@ byteorder = "^1.0.0"
|
|||
crc = "^1.2.0"
|
||||
itertools = "^0.5.7"
|
||||
libc = "^0.2.4"
|
||||
libz-sys = "^1.0.0"
|
||||
miniz-sys = "^0.1.7"
|
||||
num_cpus = "^1.0.0"
|
||||
rayon = "^0.6.0"
|
||||
|
|
@ -54,3 +53,6 @@ binary = ["clap", "regex"]
|
|||
nightly = ["rayon/unstable"]
|
||||
nightly-binary = ["binary", "nightly", "regex/simd-accel"]
|
||||
dev = ["nightly-binary", "clippy"]
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 2
|
||||
|
|
@ -27,9 +27,6 @@ cargo build --release
|
|||
cp target/release/oxipng /usr/local/bin
|
||||
```
|
||||
|
||||
Please note that zlib is a required build dependency. Oxipng should work with any 1.x version of zlib,
|
||||
but you are advised to use the latest version (currently 1.2.11) for security and bug fixes.
|
||||
|
||||
The current minimum supported Rust version is **1.13.0**. Oxipng may compile on earlier versions of Rust,
|
||||
but there is no guarantee.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
// Raw un-exported bindings to libz for encoding/decoding
|
||||
// Copyright (c) 2014 Alex Crichton, MIT & Apache licenses
|
||||
// Originally from flate2 crate for miniz
|
||||
// Modified for use in oxipng
|
||||
|
||||
use std::marker;
|
||||
use std::mem;
|
||||
use libc::{c_int, c_uint};
|
||||
use libz_sys;
|
||||
|
||||
pub struct Stream<D: Direction> {
|
||||
raw: libz_sys::z_stream,
|
||||
_marker: marker::PhantomData<D>,
|
||||
}
|
||||
|
||||
pub enum Compress {}
|
||||
pub enum Decompress {}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub trait Direction {
|
||||
unsafe fn destroy(stream: *mut libz_sys::z_stream) -> c_int;
|
||||
}
|
||||
|
||||
impl Stream<Compress> {
|
||||
pub fn new_compress(lvl: c_int,
|
||||
window_bits: c_int,
|
||||
mem_size: c_int,
|
||||
strategy: c_int)
|
||||
-> Stream<Compress> {
|
||||
unsafe {
|
||||
let mut state: libz_sys::z_stream = mem::zeroed();
|
||||
let ret = libz_sys::deflateInit2_(&mut state,
|
||||
lvl,
|
||||
libz_sys::Z_DEFLATED,
|
||||
window_bits,
|
||||
mem_size,
|
||||
strategy,
|
||||
libz_sys::zlibVersion(),
|
||||
mem::size_of::<libz_sys::z_stream>() as i32);
|
||||
debug_assert_eq!(ret, 0);
|
||||
Stream {
|
||||
raw: state,
|
||||
_marker: marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_decompress() -> Stream<Decompress> {
|
||||
unsafe {
|
||||
let mut state: libz_sys::z_stream = mem::zeroed();
|
||||
let ret = libz_sys::inflateInit2_(&mut state,
|
||||
15,
|
||||
libz_sys::zlibVersion(),
|
||||
mem::size_of::<libz_sys::z_stream>() as i32);
|
||||
debug_assert_eq!(ret, 0);
|
||||
Stream {
|
||||
raw: state,
|
||||
_marker: marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Direction> Stream<T> {
|
||||
#[inline]
|
||||
pub fn total_in(&self) -> usize {
|
||||
self.raw.total_in as usize
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn total_out(&self) -> usize {
|
||||
self.raw.total_out as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl Stream<Decompress> {
|
||||
pub fn decompress_vec(&mut self, input: &mut [u8], output: &mut Vec<u8>) -> c_int {
|
||||
self.raw.avail_in = (input.len() - self.total_in()) as c_uint;
|
||||
self.raw.avail_out = (output.capacity() - self.total_out()) as c_uint;
|
||||
|
||||
unsafe {
|
||||
self.raw.next_in = input.as_mut_ptr().offset(self.total_in() as isize);
|
||||
self.raw.next_out = output.as_mut_ptr().offset(self.total_out() as isize);
|
||||
let rc = libz_sys::inflate(&mut self.raw, libz_sys::Z_NO_FLUSH);
|
||||
output.set_len(self.total_out() as usize);
|
||||
rc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Stream<Compress> {
|
||||
pub fn compress_vec(&mut self, input: &mut [u8], output: &mut Vec<u8>) -> c_int {
|
||||
self.raw.avail_in = (input.len() - self.total_in() as usize) as c_uint;
|
||||
self.raw.avail_out = (output.capacity() - self.total_out() as usize) as c_uint;
|
||||
|
||||
unsafe {
|
||||
self.raw.next_in = input.as_mut_ptr().offset(self.total_in() as isize);
|
||||
self.raw.next_out = output.as_mut_ptr().offset(self.total_out() as isize);
|
||||
let rc = libz_sys::deflate(&mut self.raw,
|
||||
if self.raw.avail_in > 0 {
|
||||
libz_sys::Z_NO_FLUSH
|
||||
} else {
|
||||
libz_sys::Z_FINISH
|
||||
});
|
||||
output.set_len(self.total_out() as usize);
|
||||
rc
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn reset(&mut self) -> c_int {
|
||||
unsafe { libz_sys::deflateReset(&mut self.raw) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Direction for Compress {
|
||||
#[inline]
|
||||
unsafe fn destroy(stream: *mut libz_sys::z_stream) -> c_int {
|
||||
libz_sys::deflateEnd(stream)
|
||||
}
|
||||
}
|
||||
impl Direction for Decompress {
|
||||
#[inline]
|
||||
unsafe fn destroy(stream: *mut libz_sys::z_stream) -> c_int {
|
||||
libz_sys::inflateEnd(stream)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Direction> Drop for Stream<D> {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
let _ = <D as Direction>::destroy(&mut self.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +1,21 @@
|
|||
use error::PngError;
|
||||
use libz_sys;
|
||||
use miniz_sys;
|
||||
use libc::c_int;
|
||||
use std::cmp::max;
|
||||
use zopfli;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod libz_stream;
|
||||
#[doc(hidden)]
|
||||
pub mod miniz_stream;
|
||||
|
||||
/// Decompress a data stream using the DEFLATE algorithm
|
||||
pub fn inflate(data: &[u8]) -> Result<Vec<u8>, PngError> {
|
||||
let mut input = data.to_owned();
|
||||
let mut stream = libz_stream::Stream::new_decompress();
|
||||
let mut stream = miniz_stream::Stream::new_decompress();
|
||||
let mut output = Vec::with_capacity(data.len());
|
||||
loop {
|
||||
match stream.decompress_vec(input.as_mut(), output.as_mut()) {
|
||||
libz_sys::Z_OK => output.reserve(data.len()),
|
||||
libz_sys::Z_STREAM_END => break,
|
||||
miniz_sys::MZ_OK => output.reserve(data.len()),
|
||||
miniz_sys::MZ_STREAM_END => break,
|
||||
c => return Err(PngError::new(&format!("Error code on decompress: {}", c))),
|
||||
}
|
||||
}
|
||||
|
|
@ -33,27 +30,13 @@ pub fn deflate(data: &[u8], zc: u8, zm: u8, zs: u8, zw: u8) -> Result<Vec<u8>, P
|
|||
// Compressed input should be smaller than decompressed, so allocate less than data.len()
|
||||
// However, it needs a minimum capacity in order to handle very small images
|
||||
let mut output = Vec::with_capacity(max(1024, data.len() / 20));
|
||||
if zs == 0 || zs == 1 {
|
||||
// Miniz performs 1-2 orders of magnitude better for strategies 0 and 1
|
||||
let mut stream =
|
||||
miniz_stream::Stream::new_compress(zc as c_int, zw as c_int, zm as c_int, zs as c_int);
|
||||
loop {
|
||||
match stream.compress_vec(input.as_mut(), output.as_mut()) {
|
||||
miniz_sys::MZ_OK => output.reserve(max(1024, data.len() / 20)),
|
||||
miniz_sys::MZ_STREAM_END => break,
|
||||
c => return Err(PngError::new(&format!("Error code on compress: {}", c))),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// libz performs an order of magnitude better for strategies 2 and 3
|
||||
let mut stream =
|
||||
libz_stream::Stream::new_compress(zc as c_int, zw as c_int, zm as c_int, zs as c_int);
|
||||
loop {
|
||||
match stream.compress_vec(input.as_mut(), output.as_mut()) {
|
||||
libz_sys::Z_OK => output.reserve(max(1024, data.len() / 20)),
|
||||
libz_sys::Z_STREAM_END => break,
|
||||
c => return Err(PngError::new(&format!("Error code on compress: {}", c))),
|
||||
}
|
||||
let mut stream =
|
||||
miniz_stream::Stream::new_compress(zc as c_int, zw as c_int, zm as c_int, zs as c_int);
|
||||
loop {
|
||||
match stream.compress_vec(input.as_mut(), output.as_mut()) {
|
||||
miniz_sys::MZ_OK => output.reserve(max(1024, data.len() / 20)),
|
||||
miniz_sys::MZ_STREAM_END => break,
|
||||
c => return Err(PngError::new(&format!("Error code on compress: {}", c))),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ extern crate byteorder;
|
|||
extern crate crc;
|
||||
extern crate itertools;
|
||||
extern crate libc;
|
||||
extern crate libz_sys;
|
||||
extern crate miniz_sys;
|
||||
extern crate num_cpus;
|
||||
extern crate rayon;
|
||||
|
|
|
|||
Loading…
Reference in a new issue