1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Image decoding for the `Image` component — decode raster bytes into an
//! `egui::ColorImage`, cached as a `TextureHandle` on [`crate::EguiApp`] (the
//! handle itself is created in `EguiApp::load_images`, which holds the
//! `egui::Context`).
//!
//! This is the egui counterpart of the Bevy backend's `images.rs`, the Iced
//! backend's `fetch_sample_images` / `fetch_handle`, and the Slint backend's
//! inline image decode. Like Bevy and Slint, egui's gallery has no convenient
//! async hook, so decoding runs **synchronously on the UI thread** in
//! [`EguiApp::load_images`] (a read-pass that collects uncached URLs, then a
//! write-pass that decodes + caches them). The gallery samples carry only a
//! handful of small images, so the one-time per-URL cost (a few ms for local
//! files; one blocking HTTP round-trip per remote URL with a 5 s cap) is
//! acceptable. Results are cached by resolved URL and cleared on sample switch.
//!
//! - **local file** (`path`, `file://path`): read + decode via the `image` crate.
//! - **`http(s)` URL**: blocking `ureq` GET → decode.
//! - **`data:` URL / decode failure / missing file**: `None` (placeholder stays,
//! not retried), matching the Slint/Bevy backends.
use Read;
use Duration;
use ColorImage;
/// Fetch + decode one image URL to an `egui::ColorImage` (or `None` on any
/// failure / unsupported scheme). Blocking — see the module docs.
/// Fetch the raw bytes for `url`: blocking `ureq` GET for `http(s)`, a local
/// file read for a path / `file://` URL, and `None` for `data:` URLs (matching
/// the Slint/Bevy backends).
/// Decode encoded image bytes (PNG / JPEG / …) into an `egui::ColorImage` via
/// the standalone `image` crate (same 0.25 line Bevy/Iced use). Returns `None`
/// for an undecodable payload (the placeholder stays). The `image` crate yields
/// non-premultiplied straight RGBA, so `from_rgba_unmultiplied` is correct here.