diff --git a/CHANGELOG.md b/CHANGELOG.md index 33782625..8a6ab86f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): - Port several widespread GUI keys to the input component ([#2849]) - Support invalid UTF-8 paths throughout the codebase ([#2884], [#2889], [#2890], [#2895], [#3023]) - Allow upgrading only specific packages with `ya pkg` ([#2841]) +- Respect the user's `image_filter` setting for the preset `magick` previewer ([#3286]) - Allow custom mouse click behavior for individual files ([#2925]) - Display newlines in input as spaces to improve readability ([#2932]) - Fill in error messages if preview fails ([#2917]) @@ -1530,3 +1531,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): [#3264]: https://github.com/sxyazi/yazi/pull/3264 [#3268]: https://github.com/sxyazi/yazi/pull/3268 [#3271]: https://github.com/sxyazi/yazi/pull/3271 +[#3286]: https://github.com/sxyazi/yazi/pull/3286 diff --git a/Cargo.lock b/Cargo.lock index 1d8272ba..2bec99ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2027,15 +2027,6 @@ dependencies = [ "which", ] -[[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", -] - [[package]] name = "matchers" version = "0.2.0" @@ -2334,15 +2325,6 @@ dependencies = [ "libc", ] -[[package]] -name = "objc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" -dependencies = [ - "malloc_buf", -] - [[package]] name = "objc2" version = "0.6.3" @@ -4891,7 +4873,7 @@ dependencies = [ "anyhow", "core-foundation-sys", "libc", - "objc", + "objc2", "yazi-macro", ] @@ -4947,7 +4929,7 @@ dependencies = [ "foldhash 0.2.0", "hashbrown 0.16.0", "libc", - "objc", + "objc2", "parking_lot", "percent-encoding", "regex", diff --git a/Cargo.toml b/Cargo.toml index 8361a1ca..89ac9f85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ indexmap = { version = "2.12.0", features = [ "serde" ] } libc = "0.2.177" lru = "0.16.2" mlua = { version = "0.11.4", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] } -objc = "0.2.7" +objc2 = "0.6.3" ordered-float = { version = "5.1.0", features = [ "serde" ] } parking_lot = "0.12.5" paste = "1.0.15" diff --git a/yazi-ffi/Cargo.toml b/yazi-ffi/Cargo.toml index 8a911dde..32fe61b3 100644 --- a/yazi-ffi/Cargo.toml +++ b/yazi-ffi/Cargo.toml @@ -19,4 +19,4 @@ libc = { workspace = true } [target.'cfg(target_os = "macos")'.dependencies] core-foundation-sys = { workspace = true } -objc = { workspace = true } +objc2 = { workspace = true } diff --git a/yazi-ffi/src/cf_dict.rs b/yazi-ffi/src/cf_dict.rs index d99abb9d..9bf78f7e 100644 --- a/yazi-ffi/src/cf_dict.rs +++ b/yazi-ffi/src/cf_dict.rs @@ -2,7 +2,7 @@ use std::{ffi::{CStr, OsStr, OsString, c_char, c_void}, mem::ManuallyDrop, os::u use anyhow::{Result, bail}; use core_foundation_sys::{base::{CFRelease, TCFTypeRef}, dictionary::{CFDictionaryGetValueIfPresent, CFDictionaryRef}, string::CFStringRef}; -use objc::{msg_send, runtime::Object, sel, sel_impl}; +use objc2::{msg_send, runtime::AnyObject}; use super::cf_string::CFString; @@ -30,13 +30,13 @@ impl CFDict { pub fn bool(&self, key: &str) -> Result { let value = self.value(key)?; #[allow(unexpected_cfgs)] - Ok(unsafe { msg_send![value as *const Object, boolValue] }) + Ok(unsafe { msg_send![value as *const AnyObject, boolValue] }) } pub fn integer(&self, key: &str) -> Result { let value = self.value(key)?; #[allow(unexpected_cfgs)] - Ok(unsafe { msg_send![value as *const Object, longLongValue] }) + Ok(unsafe { msg_send![value as *const AnyObject, longLongValue] }) } pub fn os_string(&self, key: &str) -> Result { @@ -44,10 +44,10 @@ impl CFDict { } pub fn path_buf(&self, key: &str) -> Result { - let url = self.value(key)? as *const Object; + let url = self.value(key)? as *const AnyObject; #[allow(unexpected_cfgs)] let cstr: *const c_char = unsafe { - let nss: *const Object = msg_send![url, path]; + let nss: *const AnyObject = msg_send![url, path]; msg_send![nss, UTF8String] }; Ok(OsStr::from_bytes(unsafe { CStr::from_ptr(cstr) }.to_bytes()).into()) diff --git a/yazi-fs/Cargo.toml b/yazi-fs/Cargo.toml index 72a0812a..edd1e4d7 100644 --- a/yazi-fs/Cargo.toml +++ b/yazi-fs/Cargo.toml @@ -38,7 +38,7 @@ windows-sys = { version = "0.61.2", features = [ "Win32_Storage_FileSystem" ] } [target.'cfg(target_os = "macos")'.dependencies] core-foundation-sys = { workspace = true } -objc = { workspace = true } +objc2 = { workspace = true } [target.'cfg(not(target_os = "android"))'.dependencies] trash = "5.2.5" diff --git a/yazi-fs/src/mounts/macos.rs b/yazi-fs/src/mounts/macos.rs index 6d8367d2..f4bcc5d4 100644 --- a/yazi-fs/src/mounts/macos.rs +++ b/yazi-fs/src/mounts/macos.rs @@ -3,7 +3,7 @@ use std::{ffi::{CStr, CString, OsString, c_void}, mem, os::unix::{ffi::OsStringE use anyhow::{Result, bail}; use core_foundation_sys::{array::CFArrayRef, base::{CFRelease, kCFAllocatorDefault}, runloop::{CFRunLoopGetCurrent, CFRunLoopRun, kCFRunLoopDefaultMode}}; use libc::{c_char, mach_port_t}; -use objc::{msg_send, runtime::Object, sel, sel_impl}; +use objc2::{msg_send, runtime::AnyObject}; use scopeguard::defer; use tracing::error; use yazi_ffi::{CFDict, CFString, DADiskCopyDescription, DADiskCreateFromBSDName, DARegisterDiskAppearedCallback, DARegisterDiskDescriptionChangedCallback, DARegisterDiskDisappearedCallback, DASessionCreate, DASessionScheduleWithRunLoop, IOIteratorNext, IOObjectRelease, IORegistryEntryCreateCFProperty, IOServiceGetMatchingServices, IOServiceMatching}; @@ -161,7 +161,7 @@ impl Partitions { defer! { unsafe { CFRelease(property) } }; #[allow(unexpected_cfgs)] - let cstr: *const c_char = unsafe { msg_send![property as *const Object, UTF8String] }; + let cstr: *const c_char = unsafe { msg_send![property as *const AnyObject, UTF8String] }; Ok(if cstr.is_null() { bail!("Invalid value for the name property"); } else { diff --git a/yazi-plugin/preset/plugins/magick.lua b/yazi-plugin/preset/plugins/magick.lua index ff512a72..df9b6375 100644 --- a/yazi-plugin/preset/plugins/magick.lua +++ b/yazi-plugin/preset/plugins/magick.lua @@ -27,17 +27,26 @@ function M:preload(job) local cmd = M.with_limit() if job.args.flatten then - cmd = cmd:arg("-flatten") + cmd:arg("-flatten") + end + cmd:arg { tostring(job.file.url), "-auto-orient", "-strip" } + + local size = string.format("%dx%d>", rt.preview.max_width, rt.preview.max_height) + if rt.preview.image_filter == "nearest" then + cmd:arg { "-sample", size } + elseif rt.preview.image_filter == "catmull-rom" then + cmd:arg { "-filter", "catrom", "-thumbnail", size } + elseif rt.preview.image_filter == "lanczos3" then + cmd:arg { "-filter", "lanczos", "-thumbnail", size } + elseif rt.preview.image_filter == "gaussian" then + cmd:arg { "-filter", "gaussian", "-thumbnail", size } + else + cmd:arg { "-filter", "triangle", "-thumbnail", size } end - -- stylua: ignore - cmd = cmd:arg { - tostring(job.file.url), "-auto-orient", "-strip", - "-sample", string.format("%dx%d>", rt.preview.max_width, rt.preview.max_height), - "-quality", rt.preview.image_quality, - } + cmd:arg { "-quality", rt.preview.image_quality } if job.args.bg then - cmd = cmd:arg { "-background", job.args.bg, "-alpha", "remove" } + cmd:arg { "-background", job.args.bg, "-alpha", "remove" } end local status, err = cmd:arg(string.format("JPG:%s", cache)):status()