Skip to content

Commit a872446

Browse files
Fix image_loader for animated image types (#5688)
Hi, after upgrading to 0.31.0 all of my beautiful static webp images started failing to load. I use the image_loader to load those via the `image` crate. I noticed that with 0.31.0 there are additions to how animated image types are handled with frames and such. And with those changes the frame index is attached to the uri at the end. This was problematic for the image_loader, because it wasn't updated to handle that frame tag at the end of the uri, so when looking up the bytes, it would fail to match the uri in the bytes cache (the bytes were being saved without the frame index, but attempting to be fetched _with_ the frame index). This fixes the image_loader for me with webp & gif. They don't load the animations, but I think that is because I don't have the custom image_loader set up so I'm not worried about that for myself. I'm not sure if that part is problematic in general, or if its just the way I have my features set up. You can recreate the issue on master by swapping out the dependency features in the `images` example like this: ``` # egui_extras = { workspace = true, features = ["default", "all_loaders"] } # env_logger = { version = "0.10", default-features = false, features = [ # "auto-color", # "humantime", # ] } # image = { workspace = true, features = ["jpeg", "png"] } egui_extras = { workspace = true, features = ["image", "svg"] } env_logger = { version = "0.10", default-features = false, features = [ "auto-color", "humantime", ] } image = { workspace = true, features = ["jpeg", "png", "webp", "gif"] } ``` * [x] I have followed the instructions in the PR template --------- Co-authored-by: lucasmerlin <lucasmeurer96@gmail.com> (cherry picked from commit 770c976)
1 parent 5b47b80 commit a872446

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crates/egui_extras/src/loaders/image_loader.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use ahash::HashMap;
22
use egui::{
3+
decode_animated_image_uri,
34
load::{BytesPoll, ImageLoadResult, ImageLoader, ImagePoll, LoadError, SizeHint},
45
mutex::Mutex,
56
ColorImage,
@@ -58,6 +59,11 @@ impl ImageLoader for ImageCrateLoader {
5859
// 2. Mime from `BytesPoll::Ready`
5960
// 3. image::guess_format (used internally by image::load_from_memory)
6061

62+
// TODO(lucasmerlin): Egui currently changes all URIs for webp and gif files to include
63+
// the frame index (#0), which breaks if the animated image loader is disabled.
64+
// We work around this by removing the frame index from the URI here
65+
let uri = decode_animated_image_uri(uri).map_or(uri, |(uri, _frame_index)| uri);
66+
6167
// (1)
6268
if uri.starts_with("file://") && !is_supported_uri(uri) {
6369
return Err(LoadError::NotSupported);

0 commit comments

Comments
 (0)