Skip to content

Commit

Permalink
feat: use ril with image-webp feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nekowinston committed Apr 10, 2024
1 parent 25acb34 commit 0bcddb5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 49 deletions.
40 changes: 12 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions catwalk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
thiserror = "1"

[dependencies.ril]
git = "https://github.com/nekowinston/ril"
branch = "feat/image_webp"
default-features = false
features = ["png", "resize", "webp-pure"]

[target.'cfg(not(target_family = "wasm"))'.dependencies]
clap = { version = "4", features = ["derive"] }
clap_complete = { version = "4" }
color-eyre = { version = "0.6", default-features = false }
ril = { version = "0.10", default-features = false, features = [
"png",
"resize",
"webp",
] }

[target.'cfg(target_family = "wasm")'.dependencies]
js-sys = "0.3"
ril = { version = "0.10", default-features = false }
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["ImageData"] }
getrandom = { version = "0.2", features = ["js"] }
Expand Down
21 changes: 6 additions & 15 deletions catwalk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,11 @@ fn main() -> Result<()> {
match args.output.extension() {
None => return Err(eyre!("Output file type could not be determined")),
Some(os_str) => match os_str.to_str() {
Some("png") => {
use ril::encodings::png::PngEncoder;

PngEncoder::encode_static(&catwalk, &mut writebuf)?;
}
Some("webp") => {
use ril::encodings::webp::{WebPEncoderOptions, WebPStaticEncoder};

let opt = WebPEncoderOptions::new().with_lossless(true);
let meta = EncoderMetadata::<Rgba>::from(&catwalk).with_config(opt);
let mut encoder = WebPStaticEncoder::new(&mut writebuf, meta)?;
encoder.add_frame(&catwalk)?;
}
Some("png") => catwalk.encode(ImageFormat::Png, &mut writebuf)?,
Some("webp") => catwalk.encode(ImageFormat::WebP, &mut writebuf)?,
_ => return Err(eyre!("Output file type not supported")),
},
}
};

let output = if args.directory.is_some() {
let mut path = args.directory.clone().unwrap_or_default();
Expand All @@ -95,5 +84,7 @@ fn main() -> Result<()> {
args.output
};

std::fs::write(output, writebuf.get_ref()).map_err(|e| eyre!("Failed to write image: {}", e))
// std::fs::write(output, writebuf.get_ref()).map_err(|e| eyre!("Failed to write image: {}", e))
catwalk.save_inferred(output)?;
Ok(())
}

0 comments on commit 0bcddb5

Please sign in to comment.