Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor mime type support detection in image loader to allow for deferred handling and appended encoding info #5686

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 14 additions & 4 deletions crates/egui_extras/src/loaders/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ fn is_supported_uri(uri: &str) -> bool {
}

fn is_supported_mime(mime: &str) -> bool {
// This is the default mime type for binary files, so this might actually be a valid image,
// let's relay on image's format guessing
if mime == "application/octet-stream" {
return true;
// some mime types e.g. reflect binary files or mark the content as a download, which
// may be a valid image or not, in this case, defer the decision on the format guessing
// or the image crate and return true here
let mimes_to_defer = [
"application/octet-stream",
"application/x-msdownload",
"application/force-download",
];
for m in &mimes_to_defer {
// use contains instead of direct equality, as e.g. encoding info might be appended
if mime.contains(m) {
return true;
}
}

// Uses only the enabled image crate features
ImageFormat::all()
.filter(ImageFormat::reading_enabled)
Expand Down