Compare commits

...

3 Commits

Author SHA1 Message Date
Diego Dorado
73df0d8418
Merge 3a58847f37 into 6e0065e3df 2024-09-06 14:43:37 -06:00
sxyazi
6e0065e3df
chore: update dependencies 2024-09-07 01:10:06 +08:00
Diego Dorado
3a58847f37
encode images with alpha channel if present for preview 2024-08-26 14:41:40 -03:00
8 changed files with 91 additions and 71 deletions

78
Cargo.lock generated
View File

@ -153,7 +153,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -345,9 +345,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.15"
version = "1.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6"
checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b"
dependencies = [
"jobserver",
"libc",
@ -384,9 +384,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.16"
version = "4.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019"
checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac"
dependencies = [
"clap_builder",
"clap_derive",
@ -394,9 +394,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.15"
version = "4.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6"
checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73"
dependencies = [
"anstream",
"anstyle",
@ -406,9 +406,9 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "4.5.24"
version = "4.5.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d7db6eca8c205649e8d3ccd05aa5042b1800a784e56bc7c43524fde8abbfa9b"
checksum = "205d5ef6d485fa47606b98b0ddc4ead26eb850aaa86abfb562a94fb3280ecba0"
dependencies = [
"clap",
]
@ -442,7 +442,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -621,7 +621,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -632,7 +632,7 @@ checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178"
dependencies = [
"darling_core",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -662,7 +662,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -672,7 +672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b"
dependencies = [
"derive_builder_core",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -918,7 +918,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1176,7 +1176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b23a0c8dfe501baac4adf6ebbfa6eddf8f0c07f56b058cc1288017e32397846c"
dependencies = [
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1196,7 +1196,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1495,7 +1495,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1588,7 +1588,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1868,7 +1868,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd"
dependencies = [
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2170,14 +2170,14 @@ checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
name = "serde_json"
version = "1.0.127"
version = "1.0.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad"
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
dependencies = [
"itoa",
"memchr",
@ -2343,7 +2343,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2359,9 +2359,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.76"
version = "2.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525"
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
dependencies = [
"proc-macro2",
"quote",
@ -2425,7 +2425,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2543,14 +2543,14 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
name = "tokio-stream"
version = "0.1.15"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af"
checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1"
dependencies = [
"futures-core",
"pin-project-lite",
@ -2559,9 +2559,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.7.11"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1"
checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a"
dependencies = [
"bytes",
"futures-core",
@ -2636,7 +2636,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2818,7 +2818,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2916,7 +2916,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
"wasm-bindgen-shared",
]
@ -2938,7 +2938,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -3037,7 +3037,7 @@ checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -3048,7 +3048,7 @@ checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -3503,7 +3503,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]

View File

@ -15,7 +15,7 @@ anyhow = "1.0.86"
arc-swap = "1.7.1"
base64 = "0.22.1"
bitflags = "2.6.0"
clap = { version = "4.5.16", features = [ "derive" ] }
clap = { version = "4.5.17", features = [ "derive" ] }
crossterm = { version = "0.28.1", features = [ "event-stream" ] }
dirs = "5.0.1"
futures = "0.3.30"
@ -28,11 +28,11 @@ ratatui = { version = "0.28.1", features = [ "unstable-rendered-line-info"
regex = "1.10.6"
scopeguard = "1.2.0"
serde = { version = "1.0.209", features = [ "derive" ] }
serde_json = "1.0.127"
serde_json = "1.0.128"
shell-words = "1.1.0"
tokio = { version = "1.40.0", features = [ "full" ] }
tokio-stream = "0.1.15"
tokio-util = "0.7.11"
tokio-stream = "0.1.16"
tokio-util = "0.7.12"
tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_level_warn" ] }
unicode-width = "0.1.13"
uzers = "0.12.1"

View File

@ -2,7 +2,7 @@ use std::{fs::File, io::BufReader, path::{Path, PathBuf}};
use anyhow::Result;
use exif::{In, Tag};
use image::{codecs::jpeg::JpegEncoder, imageops::{self, FilterType}, DynamicImage, Limits};
use image::{codecs::{jpeg::JpegEncoder, png::PngEncoder}, imageops::{self, FilterType}, DynamicImage, ImageEncoder, Limits};
use ratatui::layout::Rect;
use yazi_config::{PREVIEW, TASKS};
@ -30,18 +30,25 @@ impl Image {
img = img.resize(w, h, Self::filter());
}
let mut buf = Vec::new();
img = Self::rotate(img, orientation);
if !matches!(img, DynamicImage::ImageRgb8(_)) {
img = DynamicImage::ImageRgb8(img.into_rgb8());
match img {
DynamicImage::ImageRgb8(_) => {
JpegEncoder::new_with_quality(&mut buf, PREVIEW.image_quality).encode_image(&img)?;
}
_ => {
let (width, height) = (img.width(), img.height());
let img_rgba8 = img.into_rgba8(); // Consume `img` here
PngEncoder::new(&mut buf).write_image(
&img_rgba8,
width,
height,
image::ExtendedColorType::Rgba8,
)?;
}
}
let mut buf = Vec::new();
JpegEncoder::new_with_quality(&mut buf, PREVIEW.image_quality).encode(
img.as_bytes(),
img.width(),
img.height(),
img.color().into(),
)?;
Ok::<_, anyhow::Error>(buf)
})
.await??;

View File

@ -1,10 +1,11 @@
use std::{io::Write, path::Path};
use anyhow::Result;
use base64::{engine::{general_purpose::STANDARD, Config}, Engine};
use base64::{engine::general_purpose::STANDARD, Engine};
use crossterm::{cursor::MoveTo, queue};
use image::{codecs::jpeg::JpegEncoder, DynamicImage};
use image::{codecs::{jpeg::JpegEncoder, png::PngEncoder}, DynamicImage, ImageEncoder};
use ratatui::layout::Rect;
use yazi_config::PREVIEW;
use super::image::Image;
use crate::{adapter::Adapter, Emulator, CLOSE, START};
@ -38,22 +39,34 @@ impl Iterm2 {
async fn encode(img: DynamicImage) -> Result<Vec<u8>> {
tokio::task::spawn_blocking(move || {
let mut jpg = vec![];
JpegEncoder::new_with_quality(&mut jpg, 75).encode_image(&img)?;
let width = img.width();
let height = img.height();
let len = base64::encoded_len(jpg.len(), STANDARD.config().encode_padding());
let mut buf = Vec::with_capacity(200 + len.unwrap_or(1 << 16));
let mut img_buf = vec![];
if img.color().has_alpha() {
PngEncoder::new(&mut img_buf).write_image(
&img.into_rgba8(),
width,
height,
image::ExtendedColorType::Rgba8,
)?;
} else {
JpegEncoder::new_with_quality(&mut img_buf, PREVIEW.image_quality).encode_image(&img)?;
}
let mut buf = vec![];
write!(
buf,
"{}]1337;File=inline=1;size={};width={}px;height={}px;doNotMoveCursor=1:{}\x07{}",
START,
jpg.len(),
img.width(),
img.height(),
STANDARD.encode(&jpg),
img_buf.len(),
width,
height,
STANDARD.encode(&img_buf),
CLOSE
)?;
Ok(buf)
})
.await?

View File

@ -20,7 +20,7 @@ serde = { workspace = true }
[build-dependencies]
clap = { workspace = true }
clap_complete = "4.5.24"
clap_complete = "4.5.26"
clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.3"
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }

View File

@ -28,7 +28,7 @@ yazi-shared = { path = "../yazi-shared", version = "0.3.3" }
# External build dependencies
anyhow = { workspace = true }
clap = { workspace = true }
clap_complete = "4.5.24"
clap_complete = "4.5.26"
clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.3"
serde_json = { workspace = true }

View File

@ -25,7 +25,7 @@ bitflags = { workspace = true }
crossterm = { workspace = true }
dirs = { workspace = true }
futures = { workspace = true }
notify-fork = { version = "6.1.1", default-features = false, features = [ "macos_fsevent" ] }
notify = { package = "notify-fork", version = "6.1.1", default-features = false, features = [ "macos_fsevent" ] }
parking_lot = { workspace = true }
ratatui = { workspace = true }
scopeguard = { workspace = true }

View File

@ -1,7 +1,7 @@
use std::{collections::{HashMap, HashSet}, time::Duration};
use anyhow::Result;
use notify_fork::{PollWatcher, RecommendedWatcher, RecursiveMode, Watcher as _Watcher};
use notify::{PollWatcher, RecommendedWatcher, RecursiveMode, Watcher as _Watcher};
use parking_lot::RwLock;
use tokio::{fs, pin, sync::{mpsc::{self, UnboundedReceiver}, watch}};
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
@ -27,7 +27,7 @@ impl Watcher {
let (out_tx, out_rx) = mpsc::unbounded_channel();
let out_tx_ = out_tx.clone();
let handler = move |res: Result<notify_fork::Event, notify_fork::Error>| {
let handler = move |res: Result<notify::Event, notify::Error>| {
let Ok(event) = res else { return };
if event.kind.is_access() {
return;
@ -37,7 +37,7 @@ impl Watcher {
}
};
let config = notify_fork::Config::default().with_poll_interval(Duration::from_millis(500));
let config = notify::Config::default().with_poll_interval(Duration::from_millis(500));
if *yazi_adapter::WSL {
tokio::spawn(Self::fan_in(in_rx, PollWatcher::new(handler, config).unwrap()));
} else {
@ -79,7 +79,7 @@ impl Watcher {
});
}
async fn fan_in(mut rx: watch::Receiver<HashSet<Url>>, mut watcher: impl notify_fork::Watcher) {
async fn fan_in(mut rx: watch::Receiver<HashSet<Url>>, mut watcher: impl notify::Watcher) {
loop {
let (mut to_unwatch, mut to_watch): (HashSet<_>, HashSet<_>) = {
let (new, old) = (&*rx.borrow_and_update(), &*WATCHED.read());
@ -88,7 +88,7 @@ impl Watcher {
to_unwatch.retain(|u| match watcher.unwatch(u) {
Ok(_) => true,
Err(e) if matches!(e.kind, notify_fork::ErrorKind::WatchNotFound) => true,
Err(e) if matches!(e.kind, notify::ErrorKind::WatchNotFound) => true,
Err(e) => {
error!("Unwatch failed: {e:?}");
false