From 028854492e1c4257032727fb8a83bada95362adc Mon Sep 17 00:00:00 2001 From: gigas002 Date: Mon, 4 Mar 2024 20:48:52 +0900 Subject: [PATCH] Add support for webp --- Cargo.lock | 36 ++++++++++++++++++++++++++++++++++++ wayshot/Cargo.toml | 1 + wayshot/src/utils.rs | 4 ++++ wayshot/src/wayshot.rs | 3 ++- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 2d5bff5d..9e94c711 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,7 @@ version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ + "jobserver", "libc", ] @@ -241,6 +242,12 @@ dependencies = [ "thread_local", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "image" version = "0.24.7" @@ -255,6 +262,16 @@ dependencies = [ "num-traits", "png", "qoi", + "webp", +] + +[[package]] +name = "jobserver" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +dependencies = [ + "libc", ] [[package]] @@ -299,6 +316,16 @@ dependencies = [ "wayland-protocols-wlr", ] +[[package]] +name = "libwebp-sys" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829b6b604f31ed6d2bccbac841fe0788de93dbd87e4eb1ba2c4adfe8c012a838" +dependencies = [ + "cc", + "glob", +] + [[package]] name = "linux-raw-sys" version = "0.4.12" @@ -763,6 +790,15 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "webp" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bb5d8e7814e92297b0e1c773ce43d290bef6c17452dafd9fc49e5edb5beba71" +dependencies = [ + "libwebp-sys", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/wayshot/Cargo.toml b/wayshot/Cargo.toml index 8d4aa528..507aaf1a 100644 --- a/wayshot/Cargo.toml +++ b/wayshot/Cargo.toml @@ -26,6 +26,7 @@ image = { version = "0.24", default-features = false, features = [ "png", "pnm", "qoi", + "webp-encoder", ] } dialoguer = { version = "0.11.0", features = ["fuzzy-select"] } diff --git a/wayshot/src/utils.rs b/wayshot/src/utils.rs index e24caf74..1c961e4e 100644 --- a/wayshot/src/utils.rs +++ b/wayshot/src/utils.rs @@ -51,6 +51,8 @@ pub enum EncodingFormat { Ppm, /// Qoi encoder. Qoi, + /// WebP encoder, + WebP, } impl From for image::ImageOutputFormat { @@ -60,6 +62,7 @@ impl From for image::ImageOutputFormat { EncodingFormat::Png => image::ImageFormat::Png.into(), EncodingFormat::Ppm => image::ImageFormat::Pnm.into(), EncodingFormat::Qoi => image::ImageFormat::Qoi.into(), + EncodingFormat::WebP => image::ImageFormat::WebP.into(), } } } @@ -71,6 +74,7 @@ impl From for &str { EncodingFormat::Png => "png", EncodingFormat::Ppm => "ppm", EncodingFormat::Qoi => "qoi", + EncodingFormat::WebP => "webp", } } } diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index b4b3c01f..6371d1f7 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -50,8 +50,9 @@ fn main() -> Result<(), Box> { "png" => EncodingFormat::Png, "ppm" => EncodingFormat::Ppm, "qoi" => EncodingFormat::Qoi, + "webp" => EncodingFormat::WebP, _ => { - tracing::error!("Invalid extension provided.\nValid extensions:\n1) jpeg\n2) jpg\n3) png\n4) ppm\n5) qoi"); + tracing::error!("Invalid extension provided.\nValid extensions:\n1) jpeg\n2) jpg\n3) png\n4) ppm\n5) qoi\n6) webp"); exit(1); } }