mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: compressing images in a separate blocking thread
This commit is contained in:
parent
f80a13a33b
commit
54f289018e
3 changed files with 18 additions and 13 deletions
|
|
@ -42,11 +42,14 @@ cargo build --release
|
||||||
./target/release/yazi
|
./target/release/yazi
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to use your own config, copy the [config folder](https://github.com/sxyazi/yazi/tree/main/config) to `~/.config/yazi`, and modify it as you like.
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [x] Add example config for general usage, currently please see my [another repo](https://github.com/sxyazi/dotfiles/tree/main/yazi) instead
|
- [x] Add example config for general usage, currently please see my [another repo](https://github.com/sxyazi/dotfiles/tree/main/yazi) instead
|
||||||
- [x] Integration with fzf, zoxide for fast directory navigation
|
- [x] Integration with fzf, zoxide for fast directory navigation
|
||||||
- [x] Integration with fd, rg for fuzzy file searching
|
- [x] Integration with fd, rg for fuzzy file searching
|
||||||
|
- [ ] Documentation of commands and options
|
||||||
- [ ] Support for Überzug++ for image previews with X11/wayland environment
|
- [ ] Support for Überzug++ for image previews with X11/wayland environment
|
||||||
- [ ] Batch renaming support
|
- [ ] Batch renaming support
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,9 @@ impl Preview {
|
||||||
(w.min(PREVIEW.max_width), h.min(PREVIEW.max_height))
|
(w.min(PREVIEW.max_width), h.min(PREVIEW.max_height))
|
||||||
};
|
};
|
||||||
|
|
||||||
let file = fs::read(path).await?;
|
let img = fs::read(path).await?;
|
||||||
tokio::task::spawn_blocking(move || -> Result<Vec<u8>> {
|
tokio::task::spawn_blocking(move || -> Result<Vec<u8>> {
|
||||||
let img = image::load_from_memory(&file)?;
|
let img = image::load_from_memory(&img)?;
|
||||||
Kitty::image_show(if img.width() > w || img.height() > h {
|
Kitty::image_show(if img.width() > w || img.height() > h {
|
||||||
img.resize(w, h, FilterType::Triangle)
|
img.resize(w, h, FilterType::Triangle)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{Error, Result};
|
||||||
use image::{imageops::FilterType, ImageFormat};
|
use image::{imageops::FilterType, ImageFormat};
|
||||||
use tokio::{fs, sync::mpsc};
|
use tokio::{fs, sync::mpsc};
|
||||||
|
|
||||||
|
|
@ -60,17 +60,19 @@ impl Precache {
|
||||||
return Ok(self.sch.send(TaskOp::Adv(task.id, 1, 0))?);
|
return Ok(self.sch.send(TaskOp::Adv(task.id, 1, 0))?);
|
||||||
}
|
}
|
||||||
|
|
||||||
let img = fs::read(&task.target).await.map(|b| image::load_from_memory(&b));
|
let img = fs::read(&task.target).await;
|
||||||
let img = if let Ok(Ok(img)) = img {
|
tokio::task::spawn_blocking(move || {
|
||||||
img
|
let img = image::load_from_memory(&img?)?;
|
||||||
} else {
|
let (w, h) = (PREVIEW.max_width, PREVIEW.max_height);
|
||||||
return Ok(self.sch.send(TaskOp::Adv(task.id, 1, 0))?);
|
|
||||||
};
|
if img.width() > w || img.height() > h {
|
||||||
|
img.resize(w, h, FilterType::Triangle).save_with_format(&cache, ImageFormat::Jpeg).ok();
|
||||||
|
}
|
||||||
|
Ok::<(), Error>(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
|
||||||
let (w, h) = (PREVIEW.max_width, PREVIEW.max_height);
|
|
||||||
if img.width() > w || img.height() > h {
|
|
||||||
img.resize(w, h, FilterType::Triangle).save_with_format(&cache, ImageFormat::Jpeg).ok();
|
|
||||||
}
|
|
||||||
self.sch.send(TaskOp::Adv(task.id, 1, 0))?;
|
self.sch.send(TaskOp::Adv(task.id, 1, 0))?;
|
||||||
}
|
}
|
||||||
PrecacheOp::Video(task) => {
|
PrecacheOp::Video(task) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue