-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable zopfli on oxipng #1413
base: dev
Are you sure you want to change the base?
Enable zopfli on oxipng #1413
Changes from 6 commits
a9122ff
ca9c710
931e32a
58859d5
c8bf961
b62d9ff
e3bb3a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,8 @@ | ||||||
#[cfg(feature = "parallel")] | ||||||
pub use wasm_bindgen_rayon::init_thread_pool; | ||||||
|
||||||
use oxipng::{BitDepth, ColorType, Interlacing}; | ||||||
use oxipng::{BitDepth, ColorType, Deflaters, Interlacing}; | ||||||
use std::num::NonZeroU8; | ||||||
use wasm_bindgen::prelude::*; | ||||||
use wasm_bindgen::Clamped; | ||||||
|
||||||
|
@@ -12,6 +13,9 @@ pub fn optimise( | |||||
height: u32, | ||||||
level: u8, | ||||||
interlace: bool, | ||||||
deflater: u8, | ||||||
iterations: u8, | ||||||
compression_level: u8, | ||||||
) -> Vec<u8> { | ||||||
let mut options = oxipng::Options::from_preset(level); | ||||||
options.optimize_alpha = true; | ||||||
|
@@ -20,6 +24,23 @@ pub fn optimise( | |||||
} else { | ||||||
Interlacing::None | ||||||
}); | ||||||
match deflater { | ||||||
0 => { | ||||||
options.deflate = Deflaters::Libdeflater { | ||||||
compression: compression_level, | ||||||
} | ||||||
} | ||||||
1 => { | ||||||
options.deflate = Deflaters::Zopfli { | ||||||
iterations: Option::unwrap(NonZeroU8::new(iterations)), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
_ => { | ||||||
options.deflate = Deflaters::Libdeflater { | ||||||
compression: compression_level, | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
let raw = oxipng::RawImage::new(width, height, ColorType::RGBA, BitDepth::Eight, data.0) | ||||||
.unwrap_throw(); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to introduce a type here first, like we have in the
resize
module, so we can match on semantically meaningful words rather than numbers.Also, invalid numbers should be
panic()
’d, not just use a default value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @surma !
Is this what you were thinking of e3bb3a9 ?