feat: compressing images in a separate blocking thread

This commit is contained in:
sxyazi 2023-07-19 19:42:59 +08:00
parent f80a13a33b
commit 54f289018e
No known key found for this signature in database
3 changed files with 18 additions and 13 deletions

View file

@ -42,11 +42,14 @@ cargo build --release
./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
- [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 fd, rg for fuzzy file searching
- [ ] Documentation of commands and options
- [ ] Support for Überzug++ for image previews with X11/wayland environment
- [ ] Batch renaming support

View file

@ -91,9 +91,9 @@ impl Preview {
(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>> {
let img = image::load_from_memory(&file)?;
let img = image::load_from_memory(&img)?;
Kitty::image_show(if img.width() > w || img.height() > h {
img.resize(w, h, FilterType::Triangle)
} else {

View file

@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};
use anyhow::Result;
use anyhow::{Error, Result};
use image::{imageops::FilterType, ImageFormat};
use tokio::{fs, sync::mpsc};
@ -60,17 +60,19 @@ impl Precache {
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 = if let Ok(Ok(img)) = img {
img
} else {
return Ok(self.sch.send(TaskOp::Adv(task.id, 1, 0))?);
};
let img = fs::read(&task.target).await;
tokio::task::spawn_blocking(move || {
let img = image::load_from_memory(&img?)?;
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();
}
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))?;
}
PrecacheOp::Video(task) => {