Skip to content
Merged
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
2 changes: 1 addition & 1 deletion crates/ui-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ unicode-normalization = "0.1"
sys-locale = { version = "0.3", features = ["js"] }

# Pictures kept with features (photo thumbnails), shown in the identify popup.
image = { workspace = true, features = ["jpeg", "webp"] }
image = { workspace = true, features = ["gif", "jpeg", "webp"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
rfd = { workspace = true }
Expand Down
31 changes: 20 additions & 11 deletions crates/ui-egui/src/popupmedia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,24 @@ fn header(bytes: &[u8]) -> Result<image::ImageReader<std::io::Cursor<&[u8]>>, Fa
Ok(reader)
}

/// Decodes a fetched picture for the pop-up: refused when it isn't one, or when its header says
/// it is larger than [`crate::mapview::decode_picture`] takes (before anything is decoded, so a
/// small file can't unpack into a huge picture), and kept at most [`MAX_SIDE`] pixels a side.
/// The picture formats the pop-up shows. A fixed list, not whatever decoders `image` happens to be
/// built with: another crate in the build can add one (`arboard`, through the clipboard, adds BMP
/// on Windows and TIFF on macOS), and the same file must give the same answer on every platform.
const SHOWN: [image::ImageFormat; 4] =
[image::ImageFormat::Png, image::ImageFormat::Jpeg, image::ImageFormat::WebP, image::ImageFormat::Gif];
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/// Decodes a fetched picture for the pop-up: refused when it isn't one, or is in a format outside
/// [`SHOWN`], or when its header says it is larger than [`crate::mapview::decode_picture`] takes
/// (before anything is decoded, so a small file can't unpack into a huge picture), and kept at
/// most [`MAX_SIDE`] pixels a side.
pub(crate) fn decode(bytes: &[u8]) -> Result<image::RgbaImage, Failure> {
let header = header(bytes)?;
let Some(format) = header.format() else { return Err(Failure::NotPicture) };
// A picture whose format has no decoder here says so, rather than that it isn't one.
let (w, h) = header.into_dimensions().map_err(|e| match e {
image::ImageError::Unsupported(u) if matches!(u.kind(), image::error::UnsupportedErrorKind::Format(_)) => {
Failure::Unsupported(format!("{format:?}").to_uppercase())
}
_ => Failure::NotPicture,
})?;
// A picture in another format says so, rather than that it isn't one.
if !SHOWN.contains(&format) {
return Err(Failure::Unsupported(format!("{format:?}").to_uppercase()));
}
let (w, h) = header.into_dimensions().map_err(|_| Failure::NotPicture)?;
Comment thread
deniial00 marked this conversation as resolved.
Resolved
if w > MAX_DECODED_SIDE || h > MAX_DECODED_SIDE {
return Err(Failure::TooLarge(w, h));
}
Expand Down Expand Up @@ -548,13 +553,17 @@ mod tests {
assert_eq!(Failure::TooLarge(4000, 3000).line(), "Picture unavailable: 4000 × 3000 pixels is larger than 2048 × 2048");
assert_eq!(decode(b"<html>Not found</html>"), Err(Failure::NotPicture));
assert_eq!(decode(&[]), Err(Failure::NotPicture));
// A picture whose format isn't read here says so, not that it isn't a picture.
// A picture in a format the pop-up doesn't show says so, not that it isn't a picture, whatever
// decoders the build has (the clipboard adds BMP on Windows and TIFF on macOS).
let mut bmp = b"BM".to_vec();
bmp.resize(64, 0);
assert_eq!(decode(&bmp), Err(Failure::Unsupported("BMP".into())));
let mut tiff = b"II*\0".to_vec();
tiff.resize(64, 0);
assert_eq!(decode(&tiff), Err(Failure::Unsupported("TIFF".into())));
// A GIF is shown (a 1 × 1 one).
let gif = b"GIF89a\x01\0\x01\0\x80\0\0\0\0\0\xff\xff\xff!\xf9\x04\x01\0\0\0\0,\0\0\0\0\x01\0\x01\0\0\x02\x02D\x01\0;";
assert_eq!(decode(gif).unwrap().dimensions(), (1, 1));
assert_eq!(Failure::Unsupported("BMP".into()).line(), "Picture unavailable: BMP pictures aren't supported");
// A picture cut short doesn't decode.
let whole = png(64, 64);
Expand Down
5 changes: 3 additions & 2 deletions docs/user-guide/editing.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ such as `image_page_url` or `image_credit` stay links or text in the list.
A picture from RustGIS's own asset server (`https://assets.rustgis.app/…`) is fetched as the pop-up
opens. A picture from any other server isn't: the pop-up shows **Show Picture** and the server's
name, and fetches nothing until you click it, because the request tells that server that someone
opened the data (see [Privacy](../privacy.md)). A spinner shows while a picture is fetched. Pictures
of up to 4 MB and 2048 × 2048 pixels are shown; the last 16 addresses' pictures are kept for the
opened the data (see [Privacy](../privacy.md)). A spinner shows while a picture is fetched. PNG, JPEG,
WebP and GIF pictures of up to 4 MB and 2048 × 2048 pixels are shown (on every platform; any other
format, such as BMP or TIFF, is "not supported"); the last 16 addresses' pictures are kept for the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the text quotes "not supported", but the message the code produces is "Picture unavailable: BMP pictures aren't supported". Quoting the real wording would let a user match the doc to what they see. Left for the release quality pass.

session, so opening the pop-up again shows the picture without asking again; they are forgotten with
the web layers' cached tiles (signing out of ArcGIS, a login that ends, **Reload Web Layers**). When
one can't be shown, the pop-up says why ("Picture unavailable: …": the server's answer, a network
Expand Down
Loading