Skip to content

Commit

Permalink
Update image_loader.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Nov 6, 2024
1 parent baa823e commit 34f1b3c
Showing 1 changed file with 1 addition and 66 deletions.
67 changes: 1 addition & 66 deletions crates/egui_extras/src/loaders/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,77 +18,12 @@ impl ImageCrateLoader {
pub const ID: &'static str = egui::generate_loader_id!(ImageCrateLoader);
}

fn get_ext_from_image_uri(uri: &str) -> String {
if uri.trim().is_empty() {
return String::new();
}

let image_uri = uri.to_lowercase();

let auto_ext: String = if image_uri.contains(".png") {
"png".to_owned()
} else if image_uri.contains(".jpg") {
"jpg".to_owned()
} else if image_uri.contains(".jpeg") {
"jpeg".to_owned()
} else if image_uri.contains(".gif") {
"gif".to_owned()
} else if image_uri.contains(".ico") {
"ico".to_owned()
} else if image_uri.contains(".svg") {
"svg".to_owned()
} else if image_uri.contains(".webp") {
"webp".to_owned()
} else if image_uri.contains(".apng") {
"apng".to_owned()
} else if image_uri.contains(".avif") {
"avif".to_owned()
} else if image_uri.contains(".bmp") {
"bmp".to_owned()
} else if image_uri.contains(".dds") {
"dds".to_owned()
} else if image_uri.contains(".exr") {
"exr".to_owned()
} else if image_uri.contains(".ff") {
"ff".to_owned()
} else if image_uri.contains(".hdr") {
"hdr".to_owned()
} else if image_uri.contains(".pbm") {
"pbm".to_owned()
} else if image_uri.contains(".pam") {
"pam".to_owned()
} else if image_uri.contains(".ppm") {
"ppm".to_owned()
} else if image_uri.contains(".pgm") {
"pgm".to_owned()
} else if image_uri.contains(".qoi") {
"qoi".to_owned()
} else if image_uri.contains(".tif") {
"tif".to_owned()
} else if image_uri.contains(".tiff") {
"tiff".to_owned()
} else if image_uri.contains(".tga") {
"tga".to_owned()
} else {
// If the image format is unknown, it is assumed to be `png`.
"png".to_owned()
};

auto_ext
}

fn is_supported_uri(uri: &str) -> bool {
let ext = get_ext_from_image_uri(uri);
if ext.is_empty() {
// `true` because if there's no extension, assume that we support it
return true;
}

// Uses only the enabled image crate features
ImageFormat::all()
.filter(ImageFormat::reading_enabled)
.flat_map(ImageFormat::extensions_str)
.any(|format_ext| ext == *format_ext)
.any(|format_ext| uri.contains(*format_ext))
}

fn is_unsupported_mime(mime: &str) -> bool {
Expand Down

0 comments on commit 34f1b3c

Please sign in to comment.