Skip to content
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

feat(catwalk): use ril with pure rust webp feature #147

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 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"
rev = "88d559706bd084468a95723d42910140803cb090"
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))
catwalk
.save_inferred(output)
.map_err(|e| eyre!("Failed to write image: {}", e))
}
9 changes: 8 additions & 1 deletion nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
inherit (memberCargoToml.package) version;
src = pkgs.nix-gitignore.gitignoreSource [] ../.;

cargoLock.lockFile = ../Cargo.lock;
cargoLock = {
lockFile = ../Cargo.lock;
outputHashes = {
"image-webp-0.1.1" = "sha256-WlGXjvkw6JL8OsS9IoM5Fpd4au8zp9jO/Z2iTXQE2Ko=";
"ril-0.10.1" = "sha256-xVkuR8m6Q91Ii+bbCD9+foyka5a0vpJwTHBM8Hjjt4I=";
};
};

buildAndTestSubdir = pname;

meta = {
Expand Down