Skip to content

Commit

Permalink
Version 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shssoichiro committed Oct 8, 2019
1 parent 659717c commit 139d29c
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 111 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,11 @@
### Version 2.3.0
- Allow disabling all alpha optimizations ([#181](https://github.com/shssoichiro/oxipng/pull/181))
- Fix interlacing issues on tiny images ([#182](https://github.com/shssoichiro/oxipng/pull/182))
- Reduce memory usage in filtering ([#191](https://github.com/shssoichiro/oxipng/pull/191))
- Implement palette sorting to improve compression ([#193](https://github.com/shssoichiro/oxipng/pull/193))
- Disable alpha optimizations by default ([#187](https://github.com/shssoichiro/oxipng/pull/187))
- Add support for WASM ([#194](https://github.com/shssoichiro/oxipng/pull/194))

### Version 2.2.2
- Fix grayscale bit-depth reduction ([#171](https://github.com/shssoichiro/oxipng/pull/171))
- Fix typos and incorrect log message ([#172](https://github.com/shssoichiro/oxipng/pull/172))
Expand Down
149 changes: 71 additions & 78 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -15,7 +15,7 @@ homepage = "https://github.com/shssoichiro/oxipng"
license = "MIT"
name = "oxipng"
repository = "https://github.com/shssoichiro/oxipng"
version = "2.2.2"
version = "2.3.0"

[badges]
travis-ci = { repository = "shssoichiro/oxipng", branch = "master" }
Expand Down
22 changes: 11 additions & 11 deletions README.md
Expand Up @@ -94,36 +94,36 @@ Oxipng is open-source software, distributed under the MIT license.

## Benchmarks

Tested oxipng 2.2.2 (compiled on rustc 1.35.0 (3c235d560 2019-05-20)) against OptiPNG version 0.7.7 on Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz with 8 logical cores
Tested oxipng 2.3.0 (compiled on rustc 1.38.0 (625451e37 2019-09-23)) against OptiPNG version 0.7.7 on Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz with 8 logical cores


```
Benchmark #1: ./target/release/oxipng -P ./tests/files/rgb_16_should_be_grayscale_8.png
Time (mean ± σ): 113.5 ms ± 4.9 ms [User: 269.1 ms, System: 18.9 ms]
Range (min … max): 103.0 ms … 125.2 ms 28 runs
Time (mean ± σ): 92.4 ms ± 2.7 ms [User: 249.4 ms, System: 14.5 ms]
Range (min … max): 88.4 ms … 98.5 ms 31 runs
Benchmark #2: optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png
Time (mean ± σ): 281.7 ms ± 3.5 ms [User: 280.3 ms, System: 1.4 ms]
Range (min … max): 275.2 ms … 286.2 ms 10 runs
Time (mean ± σ): 273.5 ms ± 1.7 ms [User: 272.4 ms, System: 1.2 ms]
Range (min … max): 270.3 ms … 275.1 ms 10 runs
Summary
'./target/release/oxipng -P ./tests/files/rgb_16_should_be_grayscale_8.png' ran
2.48 ± 0.11 times faster than 'optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png'
2.96 ± 0.09 times faster than 'optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png'
Benchmark #1: ./target/release/oxipng -o4 -P ./tests/files/rgb_16_should_be_grayscale_8.png
Time (mean ± σ): 141.3 ms ± 6.3 ms [User: 504.8 ms, System: 16.8 ms]
Range (min … max): 130.7 ms … 153.7 ms 21 runs
Time (mean ± σ): 120.7 ms ± 4.1 ms [User: 486.3 ms, System: 14.8 ms]
Range (min … max): 113.7 ms … 130.0 ms 23 runs
Benchmark #2: optipng -o 4 -simulate ./tests/files/rgb_16_should_be_grayscale_8.png
Time (mean ± σ): 956.8 ms ± 15.6 ms [User: 953.1 ms, System: 2.7 ms]
Range (min … max): 941.5 ms … 996.6 ms 10 runs
Time (mean ± σ): 916.8 ms ± 7.4 ms [User: 914.8 ms, System: 1.7 ms]
Range (min … max): 906.8 ms … 929.9 ms 10 runs
Summary
'./target/release/oxipng -o4 -P ./tests/files/rgb_16_should_be_grayscale_8.png' ran
6.77 ± 0.32 times faster than 'optipng -o 4 -simulate ./tests/files/rgb_16_should_be_grayscale_8.png'
7.59 ± 0.26 times faster than 'optipng -o 4 -simulate ./tests/files/rgb_16_should_be_grayscale_8.png'
```

2 changes: 1 addition & 1 deletion README.template.md
Expand Up @@ -26,7 +26,7 @@ cargo build --release
cp target/release/oxipng /usr/local/bin
```

The current minimum supported Rust version is **1.34.0**. Oxipng may compile on earlier versions of Rust,
The current minimum supported Rust version is **1.36.0**. Oxipng may compile on earlier versions of Rust,
but there is no guarantee.

Oxipng follows Semantic Versioning.
Expand Down
13 changes: 9 additions & 4 deletions src/lib.rs
Expand Up @@ -249,7 +249,7 @@ impl Options {
self
}

fn apply_preset_4(mut self) -> Self {
fn apply_preset_4(self) -> Self {
self.apply_preset_3()
}

Expand Down Expand Up @@ -630,8 +630,13 @@ fn optimize_png(
None
}
});
let best: Option<TrialWithData> =
best.reduce_with(|i, j| if i.1.len() < j.1.len() || (i.1.len() == j.1.len() && i.0 < j.0) { i } else { j });
let best: Option<TrialWithData> = best.reduce_with(|i, j| {
if i.1.len() < j.1.len() || (i.1.len() == j.1.len() && i.0 < j.0) {
i
} else {
j
}
});

if let Some(better) = best {
png.idat_data = better.1;
Expand Down Expand Up @@ -797,7 +802,7 @@ impl Deadline {
start: Instant::now(),
timeout,
print_message: AtomicBool::new(verbose),
})
}),
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/png/mod.rs
Expand Up @@ -290,7 +290,13 @@ impl PngImage {
last_pass = pass;
}
}
unfilter_line(line.filter, bpp, &line.data, &last_line, &mut unfiltered_buf);
unfilter_line(
line.filter,
bpp,
&line.data,
&last_line,
&mut unfiltered_buf,
);
unfiltered.push(0);
unfiltered.extend_from_slice(&unfiltered_buf);
std::mem::swap(&mut last_line, &mut unfiltered_buf);
Expand Down Expand Up @@ -332,7 +338,7 @@ impl PngImage {
let mut best_filter = 0;
let mut best_line = Vec::new();
let mut best_size = std::u64::MAX;

// Avoid vertical filtering on first line of each interlacing pass
for filter in if last_pass == line.pass { 0..5 } else { 0..2 } {
filter_line(filter, bpp, &line.data, last_line, &mut f_buf);
Expand All @@ -346,7 +352,6 @@ impl PngImage {
std::mem::swap(&mut best_line, &mut f_buf);
}
f_buf.clear() //discard buffer, and start again

}
filtered.push(best_filter);
filtered.extend_from_slice(&best_line);
Expand Down
7 changes: 1 addition & 6 deletions src/reduction/bit_depth.rs
Expand Up @@ -4,12 +4,7 @@ use crate::png::PngImage;
use bit_vec::BitVec;

const ONE_BIT_PERMUTATIONS: [u8; 2] = [0b0000_0000, 0b1111_1111];
const TWO_BIT_PERMUTATIONS: [u8; 4] = [
0b0000_0000,
0b0101_0101,
0b1010_1010,
0b1111_1111,
];
const TWO_BIT_PERMUTATIONS: [u8; 4] = [0b0000_0000, 0b0101_0101, 0b1010_1010, 0b1111_1111];
const FOUR_BIT_PERMUTATIONS: [u8; 16] = [
0b0000_0000,
0b0001_0001,
Expand Down
13 changes: 6 additions & 7 deletions src/reduction/mod.rs
Expand Up @@ -61,11 +61,13 @@ pub fn reduced_palette(png: &PngImage) -> Option<PngImage> {
}
}

let mut used_enumerated : Vec<(usize, &bool)>= used.iter().enumerate().collect();
let mut used_enumerated: Vec<(usize, &bool)> = used.iter().enumerate().collect();
used_enumerated.sort_by(|a, b| {
//Sort by ascending alpha and descending luma.
let color_val = |i| {
let color = palette.get(i).copied()
let color = palette
.get(i)
.copied()
.unwrap_or_else(|| RGBA8::new(0, 0, 0, 255));
((color.a as i32) << 18)
// These are coefficients for standard sRGB to luma conversion
Expand All @@ -78,8 +80,7 @@ pub fn reduced_palette(png: &PngImage) -> Option<PngImage> {

let mut next_index = 0u16;
let mut seen = HashMap::with_capacity(palette.len());
for (i, used) in used_enumerated.iter().cloned()
{
for (i, used) in used_enumerated.iter().cloned() {
if !used {
continue;
}
Expand All @@ -94,9 +95,7 @@ pub fn reduced_palette(png: &PngImage) -> Option<PngImage> {
new.insert(next_index as u8);
next_index += 1;
}
Occupied(remap_to) => {
palette_map[i] = Some(*remap_to.get())
}
Occupied(remap_to) => palette_map[i] = Some(*remap_to.get()),
}
}
}
Expand Down

0 comments on commit 139d29c

Please sign in to comment.