From 2bfb29f1bee5dacd060202dcff71df4497eebaf7 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 15 Mar 2023 11:34:47 -0700 Subject: [PATCH] improve handling of animated webp images Use mainline image crate to avoid an otherwise unavoidable panic in the upstream: https://github.com/image-rs/image/issues/1775 Explicitly operate on the frames from the animation. refs: https://github.com/wez/wezterm/issues/3250 --- Cargo.lock | 24 +++++++++++++----------- docs/changelog.md | 2 ++ lua-api-crates/color-funcs/Cargo.toml | 3 ++- term/Cargo.toml | 3 ++- termwiz/Cargo.toml | 3 ++- termwiz/src/image.rs | 10 ++++++++++ wezterm-gui/Cargo.toml | 3 ++- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00095023e..c559fe706 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1761,9 +1761,9 @@ dependencies = [ [[package]] name = "gif" -version = "0.11.4" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" +checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045" dependencies = [ "color_quant", "weezl", @@ -2229,8 +2229,7 @@ dependencies = [ [[package]] name = "image" version = "0.24.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69b7ea949b537b0fd0af141fff8c77690f2ce96f4f41f042ccb6c69c6c965945" +source = "git+https://github.com/image-rs/image.git?rev=fe069785ae245a2c510fd724ef96da283b05a236#fe069785ae245a2c510fd724ef96da283b05a236" dependencies = [ "bytemuck", "byteorder", @@ -2241,7 +2240,7 @@ dependencies = [ "num-rational 0.4.1", "num-traits", "png", - "scoped_threadpool", + "qoi", "tiff", ] @@ -3863,6 +3862,15 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b45c49fc4f91f35bae654f85ebb3a44d60ac64f11b3166ffa609def390c732d8" +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + [[package]] name = "quanta" version = "0.9.3" @@ -4244,12 +4252,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" -[[package]] -name = "scoped_threadpool" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" - [[package]] name = "scopeguard" version = "1.1.0" diff --git a/docs/changelog.md b/docs/changelog.md index 8d989c949..ca966161e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -121,6 +121,8 @@ As features stabilize some brief notes about them will accumulate here. * SSH: Closing an individual pane via `CloseCurrentPane` would kill the remote pane but not detect that it had exited. [#3095](https://github.com/wez/wezterm/issues/3095) +* Panic when decoding animated webp images + [#3250](https://github.com/wez/wezterm/issues/3250) #### Changed * `CTRL-SHIFT-P` now activates the new [command diff --git a/lua-api-crates/color-funcs/Cargo.toml b/lua-api-crates/color-funcs/Cargo.toml index b2da81d3d..14bcec2f5 100644 --- a/lua-api-crates/color-funcs/Cargo.toml +++ b/lua-api-crates/color-funcs/Cargo.toml @@ -10,7 +10,8 @@ anyhow = "1.0" config = { path = "../../config" } csscolorparser = {version="0.6", features=["lab"]} deltae = "0.3" -image = "0.24.2" +# we want image 0.24.6 or later. see https://github.com/wez/wezterm/issues/3250 +image = {version="0.24", git="https://github.com/image-rs/image.git", rev="fe069785ae245a2c510fd724ef96da283b05a236"} lazy_static = "1.4" log = "0.4" lru = "0.7" diff --git a/term/Cargo.toml b/term/Cargo.toml index 75253aee1..57a16f354 100644 --- a/term/Cargo.toml +++ b/term/Cargo.toml @@ -20,7 +20,8 @@ csscolorparser = "0.6" miniz_oxide = "0.4" finl_unicode = "1.2" hex = "0.4" -image = "0.24" +# we want image 0.24.6 or later. see https://github.com/wez/wezterm/issues/3250 +image = {version="0.24", git="https://github.com/image-rs/image.git", rev="fe069785ae245a2c510fd724ef96da283b05a236"} lazy_static = "1.4" log = "0.4" lru = "0.7" diff --git a/termwiz/Cargo.toml b/termwiz/Cargo.toml index 38253fe8d..e3995e923 100644 --- a/termwiz/Cargo.toml +++ b/termwiz/Cargo.toml @@ -21,7 +21,8 @@ finl_unicode = "1.2" fixedbitset = "0.4" fnv = {version="1.0", optional=true} hex = "0.4" -image = {version="0.24", optional=true} +# we want image 0.24.6 or later. see https://github.com/wez/wezterm/issues/3250 +image = {version="0.24", git="https://github.com/image-rs/image.git", rev="fe069785ae245a2c510fd724ef96da283b05a236", optional=true} lazy_static = "1.4" libc = "0.2" log = "0.4" diff --git a/termwiz/src/image.rs b/termwiz/src/image.rs index 3bfc69410..12915f6f7 100644 --- a/termwiz/src/image.rs +++ b/termwiz/src/image.rs @@ -357,6 +357,16 @@ impl ImageDataType { Self::decode_single(data) } } + ImageFormat::WebP => { + let decoder = match image::codecs::webp::WebPDecoder::new(&*data) { + Ok(d) => d, + _ => return Self::EncodedFile(data), + }; + match decoder.into_frames().collect_frames() { + Ok(frames) => Self::decode_frames(frames), + _ => Self::EncodedFile(data), + } + } _ => Self::decode_single(data), } } diff --git a/wezterm-gui/Cargo.toml b/wezterm-gui/Cargo.toml index e8deae031..ed0f56a55 100644 --- a/wezterm-gui/Cargo.toml +++ b/wezterm-gui/Cargo.toml @@ -55,7 +55,8 @@ futures = "0.3" fuzzy-matcher = "0.3" hdrhistogram = "7.1" http_req = "0.9" -image = "0.24" +# we want image 0.24.6 or later. see https://github.com/wez/wezterm/issues/3250 +image = {version="0.24", git="https://github.com/image-rs/image.git", rev="fe069785ae245a2c510fd724ef96da283b05a236"} lazy_static = "1.4" libc = "0.2" lfucache = { path = "../lfucache" } -- 2.51.2