Update oxipng to v9

This commit is contained in:
Andrew
2024-01-07 11:03:56 +13:00
committed by andrews05
parent e217740e53
commit e4322bcbc3
5 changed files with 98 additions and 332 deletions

View File

@@ -1,20 +1,18 @@
#[cfg(feature = "parallel")]
pub use wasm_bindgen_rayon::init_thread_pool;
use oxipng::AlphaOptim;
use oxipng::Interlacing;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn optimise(data: &[u8], level: u8, interlace: bool) -> Vec<u8> {
let mut options = oxipng::Options::from_preset(level);
options.alphas.insert(AlphaOptim::Black);
options.alphas.insert(AlphaOptim::White);
options.alphas.insert(AlphaOptim::Up);
options.alphas.insert(AlphaOptim::Down);
options.alphas.insert(AlphaOptim::Left);
options.alphas.insert(AlphaOptim::Right);
options.interlace = Some(if interlace { 1 } else { 0 });
options.optimize_alpha = true;
options.interlace = Some(if interlace {
Interlacing::Adam7
} else {
Interlacing::None
});
options.deflate = oxipng::Deflaters::Libdeflater;
oxipng::optimize_from_memory(data, &options).unwrap_throw()
}