fix(wallpapers): filter images by extension
This commit is contained in:
parent
3ee46f3d58
commit
92085b60ab
1 changed files with 21 additions and 2 deletions
|
|
@ -5,6 +5,7 @@ use futures_lite::Stream;
|
||||||
use image::imageops::FilterType;
|
use image::imageops::FilterType;
|
||||||
use image::{DynamicImage, ImageBuffer, Rgba, RgbaImage};
|
use image::{DynamicImage, ImageBuffer, Rgba, RgbaImage};
|
||||||
use jxl_oxide::{EnumColourEncoding, JxlImage, PixelFormat};
|
use jxl_oxide::{EnumColourEncoding, JxlImage, PixelFormat};
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
collections::{hash_map::DefaultHasher, BTreeSet, HashMap},
|
collections::{hash_map::DefaultHasher, BTreeSet, HashMap},
|
||||||
|
|
@ -111,7 +112,7 @@ pub async fn load_each_from_path(
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
||||||
if file_type.is_file() {
|
if file_type.is_file() {
|
||||||
let path = if path.extension().map_or(false, |ext| ext == "jxl") {
|
let path = if path.extension().map(|ext| ext == "jxl").unwrap_or_default() {
|
||||||
path
|
path
|
||||||
} else if let Ok(Some(kind)) = infer::get_from_path(&path) {
|
} else if let Ok(Some(kind)) = infer::get_from_path(&path) {
|
||||||
if infer::MatcherType::Image == kind.matcher_type() {
|
if infer::MatcherType::Image == kind.matcher_type() {
|
||||||
|
|
@ -252,7 +253,7 @@ fn load_thumbnail(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_image(input_buffer: &mut Vec<u8>, path: &Path) -> Option<DynamicImage> {
|
fn open_image(input_buffer: &mut Vec<u8>, path: &Path) -> Option<DynamicImage> {
|
||||||
if path.extension().map_or(false, |ext| ext == "jxl") {
|
if path.extension().map(|ext| ext == "jxl").unwrap_or_default() {
|
||||||
return match decode_jpegxl(path) {
|
return match decode_jpegxl(path) {
|
||||||
Ok(image) => Some(image),
|
Ok(image) => Some(image),
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
|
|
@ -262,6 +263,24 @@ fn open_image(input_buffer: &mut Vec<u8>, path: &Path) -> Option<DynamicImage> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SUPPORTED_FORMATS: &[&[u8]] = &[
|
||||||
|
"jpg".as_bytes(),
|
||||||
|
"jpeg".as_bytes(),
|
||||||
|
"png".as_bytes(),
|
||||||
|
"avif".as_bytes(),
|
||||||
|
"webp".as_bytes(),
|
||||||
|
"heif".as_bytes(),
|
||||||
|
];
|
||||||
|
|
||||||
|
let format_is_supported = path
|
||||||
|
.extension()
|
||||||
|
.map(|ext| SUPPORTED_FORMATS.contains(&ext.to_ascii_lowercase().as_bytes()))
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if !format_is_supported {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let capacity = match path.metadata() {
|
let capacity = match path.metadata() {
|
||||||
Ok(metadata) => metadata.len() as usize,
|
Ok(metadata) => metadata.len() as usize,
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue