mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 01:59:57 +00:00
Use oxipng raw api
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
#[cfg(feature = "parallel")]
|
||||
pub use wasm_bindgen_rayon::init_thread_pool;
|
||||
|
||||
use oxipng::Interlacing;
|
||||
use oxipng::{BitDepth, ColorType, Interlacing};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::Clamped;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn optimise(data: &[u8], level: u8, interlace: bool) -> Vec<u8> {
|
||||
pub fn optimise(
|
||||
data: Clamped<Vec<u8>>,
|
||||
width: u32,
|
||||
height: u32,
|
||||
level: u8,
|
||||
interlace: bool,
|
||||
) -> Vec<u8> {
|
||||
let mut options = oxipng::Options::from_preset(level);
|
||||
options.optimize_alpha = true;
|
||||
options.interlace = Some(if interlace {
|
||||
@@ -14,5 +21,7 @@ pub fn optimise(data: &[u8], level: u8, interlace: bool) -> Vec<u8> {
|
||||
Interlacing::None
|
||||
});
|
||||
|
||||
oxipng::optimize_from_memory(data, &options).unwrap_throw()
|
||||
let raw = oxipng::RawImage::new(width, height, ColorType::RGBA, BitDepth::Eight, data.0)
|
||||
.unwrap_throw();
|
||||
raw.create_optimized_png(&options).unwrap_throw()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user