mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: allow to configure image filter (#586)
This commit is contained in:
parent
c02d69590b
commit
f31f78b063
4 changed files with 19 additions and 3 deletions
|
|
@ -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"]}
|
||||
{"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"}
|
||||
|
|
@ -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<u8> {
|
||||
// We don't want to read the orientation of the cached image that has been
|
||||
// rotated in the `Self::precache()` step.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<String>,
|
||||
|
||||
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,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue