diff --git a/cspell.json b/cspell.json index 4ac57c87..847adae7 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"flagWords":[],"version":"0.2","language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty"]} \ No newline at end of file +{"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos"],"flagWords":[],"version":"0.2"} \ No newline at end of file diff --git a/yazi-adaptor/src/image.rs b/yazi-adaptor/src/image.rs index e639c47f..2595b9e8 100644 --- a/yazi-adaptor/src/image.rs +++ b/yazi-adaptor/src/image.rs @@ -26,7 +26,7 @@ impl Image { let buf = tokio::task::spawn_blocking(move || { if img.width() > w || img.height() > h { - img = img.resize(w, h, FilterType::Triangle); + img = img.resize(w, h, Self::filter()); } img = Self::rotate(img, orientation); @@ -69,7 +69,7 @@ impl Image { tokio::task::spawn_blocking(move || { if img.width() > w || img.height() > h { - img = img.resize(w, h, FilterType::Triangle) + img = img.resize(w, h, Self::filter()) } Ok(Self::rotate(img, orientation)) }) @@ -85,6 +85,18 @@ impl Image { .unwrap_or((PREVIEW.max_width, PREVIEW.max_height)) } + #[inline] + fn filter() -> FilterType { + match PREVIEW.image_filter.as_str() { + "nearest" => FilterType::Nearest, + "triangle" => FilterType::Triangle, + "catmull-rom" => FilterType::CatmullRom, + "gaussian" => FilterType::Gaussian, + "lanczos3" => FilterType::Lanczos3, + _ => FilterType::Triangle, + } + } + async fn orientation(path: &Path) -> Result { // We don't want to read the orientation of the cached image that has been // rotated in the `Self::precache()` step. diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 64f631fc..5ff959be 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -17,6 +17,7 @@ tab_size = 2 max_width = 600 max_height = 900 cache_dir = "" +image_filter = "triangle" image_quality = 75 sixel_fraction = 15 ueberzug_scale = 1 diff --git a/yazi-config/src/preview/preview.rs b/yazi-config/src/preview/preview.rs index f4c3d4cb..a6f7e9af 100644 --- a/yazi-config/src/preview/preview.rs +++ b/yazi-config/src/preview/preview.rs @@ -14,6 +14,7 @@ pub struct Preview { pub cache_dir: PathBuf, + pub image_filter: String, pub image_quality: u8, pub sixel_fraction: u8, @@ -35,6 +36,7 @@ impl Default for Preview { cache_dir: Option, + image_filter: String, #[validate(range(min = 50, max = 90))] image_quality: u8, #[validate(range(min = 10, max = 20))] @@ -74,6 +76,7 @@ impl Default for Preview { cache_dir, + image_filter: preview.image_filter, image_quality: preview.image_quality, sixel_fraction: preview.sixel_fraction,