Use multiple threads to filter
This commit is contained in:
parent
7f9ad263ec
commit
7734a9ffff
2 changed files with 21 additions and 9 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
**Version 0.9.0 (unreleased)**
|
**Version 0.9.0 (unreleased)**
|
||||||
- [SEMVER_MAJOR] Significant refactoring of modules
|
- [SEMVER_MAJOR] Significant refactoring of modules
|
||||||
- Use `itertools` to cleanup areas of code
|
- Use `itertools` to cleanup areas of code
|
||||||
|
- Use multiple threads for filtering trials
|
||||||
|
|
||||||
**Version 0.8.2**
|
**Version 0.8.2**
|
||||||
- Fix issue where images smaller than 4px width would crash on interlacing ([#42](https://github.com/shssoichiro/oxipng/issues/42))
|
- Fix issue where images smaller than 4px width would crash on interlacing ([#42](https://github.com/shssoichiro/oxipng/issues/42))
|
||||||
|
|
|
||||||
29
src/lib.rs
29
src/lib.rs
|
|
@ -371,22 +371,33 @@ fn optimize_png(mut png: &mut png::PngData, file_original_size: usize, opts: &Op
|
||||||
let best: Arc<Mutex<Option<TrialWithData>>> = Arc::new(Mutex::new(None));
|
let best: Arc<Mutex<Option<TrialWithData>>> = Arc::new(Mutex::new(None));
|
||||||
let combinations = filter.len() * compression.len() * memory.len() * strategies.len();
|
let combinations = filter.len() * compression.len() * memory.len() * strategies.len();
|
||||||
let mut results: Vec<(u8, u8, u8, u8)> = Vec::with_capacity(combinations);
|
let mut results: Vec<(u8, u8, u8, u8)> = Vec::with_capacity(combinations);
|
||||||
let mut filters: HashMap<u8, Vec<u8>> = HashMap::with_capacity(filter.len());
|
let filters: Arc<Mutex<HashMap<u8, Vec<u8>>>> =
|
||||||
|
Arc::new(Mutex::new(HashMap::with_capacity(filter.len())));
|
||||||
if opts.verbosity.is_some() {
|
if opts.verbosity.is_some() {
|
||||||
writeln!(&mut stderr(), "Trying: {} combinations", combinations).ok();
|
writeln!(&mut stderr(), "Trying: {} combinations", combinations).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
for f in &filter {
|
pool.scoped(|scope| {
|
||||||
let filtered = png.filter_image(*f);
|
for f in &filter {
|
||||||
filters.insert(*f, filtered.clone());
|
let png = png.clone();
|
||||||
for zc in &compression {
|
let filters = filters.clone();
|
||||||
for zm in &memory {
|
for zc in &compression {
|
||||||
for zs in &strategies {
|
for zm in &memory {
|
||||||
results.push((*f, *zc, *zm, *zs));
|
for zs in &strategies {
|
||||||
|
results.push((*f, *zc, *zm, *zs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scope.execute(move || {
|
||||||
|
let filtered = png.filter_image(*f);
|
||||||
|
let mut filters = filters.lock().unwrap();
|
||||||
|
filters.insert(*f, filtered);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
let filters = filters.lock().unwrap();
|
||||||
|
|
||||||
pool.scoped(|scope| {
|
pool.scoped(|scope| {
|
||||||
let original_len = png.idat_data.len();
|
let original_len = png.idat_data.len();
|
||||||
let interlacing_changed = opts.interlace.is_some() &&
|
let interlacing_changed = opts.interlace.is_some() &&
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue