Skip to content

Commit 440e671

Browse files
committed
feat: respect the user's image_filter setting for the preset magick previewer (#3286)
1 parent ff5f656 commit 440e671

File tree

8 files changed

+31
-38
lines changed

8 files changed

+31
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
3131
- Port several widespread GUI keys to the input component ([#2849])
3232
- Support invalid UTF-8 paths throughout the codebase ([#2884], [#2889], [#2890], [#2895], [#3023])
3333
- Allow upgrading only specific packages with `ya pkg` ([#2841])
34+
- Respect the user's `image_filter` setting for the preset `magick` previewer ([#3286])
3435
- Allow custom mouse click behavior for individual files ([#2925])
3536
- Display newlines in input as spaces to improve readability ([#2932])
3637
- 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/):
15301531
[#3264]: https://github.com/sxyazi/yazi/pull/3264
15311532
[#3268]: https://github.com/sxyazi/yazi/pull/3268
15321533
[#3271]: https://github.com/sxyazi/yazi/pull/3271
1534+
[#3286]: https://github.com/sxyazi/yazi/pull/3286

Cargo.lock

Lines changed: 2 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ indexmap = { version = "2.12.0", features = [ "serde" ] }
3636
libc = "0.2.177"
3737
lru = "0.16.2"
3838
mlua = { version = "0.11.4", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] }
39-
objc = "0.2.7"
39+
objc2 = "0.6.3"
4040
ordered-float = { version = "5.1.0", features = [ "serde" ] }
4141
parking_lot = "0.12.5"
4242
paste = "1.0.15"

yazi-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ libc = { workspace = true }
1919

2020
[target.'cfg(target_os = "macos")'.dependencies]
2121
core-foundation-sys = { workspace = true }
22-
objc = { workspace = true }
22+
objc2 = { workspace = true }

yazi-ffi/src/cf_dict.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{ffi::{CStr, OsStr, OsString, c_char, c_void}, mem::ManuallyDrop, os::u
22

33
use anyhow::{Result, bail};
44
use core_foundation_sys::{base::{CFRelease, TCFTypeRef}, dictionary::{CFDictionaryGetValueIfPresent, CFDictionaryRef}, string::CFStringRef};
5-
use objc::{msg_send, runtime::Object, sel, sel_impl};
5+
use objc2::{msg_send, runtime::AnyObject};
66

77
use super::cf_string::CFString;
88

@@ -30,24 +30,24 @@ impl CFDict {
3030
pub fn bool(&self, key: &str) -> Result<bool> {
3131
let value = self.value(key)?;
3232
#[allow(unexpected_cfgs)]
33-
Ok(unsafe { msg_send![value as *const Object, boolValue] })
33+
Ok(unsafe { msg_send![value as *const AnyObject, boolValue] })
3434
}
3535

3636
pub fn integer(&self, key: &str) -> Result<i64> {
3737
let value = self.value(key)?;
3838
#[allow(unexpected_cfgs)]
39-
Ok(unsafe { msg_send![value as *const Object, longLongValue] })
39+
Ok(unsafe { msg_send![value as *const AnyObject, longLongValue] })
4040
}
4141

4242
pub fn os_string(&self, key: &str) -> Result<OsString> {
4343
ManuallyDrop::new(CFString(self.value(key)? as CFStringRef)).os_string()
4444
}
4545

4646
pub fn path_buf(&self, key: &str) -> Result<PathBuf> {
47-
let url = self.value(key)? as *const Object;
47+
let url = self.value(key)? as *const AnyObject;
4848
#[allow(unexpected_cfgs)]
4949
let cstr: *const c_char = unsafe {
50-
let nss: *const Object = msg_send![url, path];
50+
let nss: *const AnyObject = msg_send![url, path];
5151
msg_send![nss, UTF8String]
5252
};
5353
Ok(OsStr::from_bytes(unsafe { CStr::from_ptr(cstr) }.to_bytes()).into())

yazi-fs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ windows-sys = { version = "0.61.2", features = [ "Win32_Storage_FileSystem" ] }
3838

3939
[target.'cfg(target_os = "macos")'.dependencies]
4040
core-foundation-sys = { workspace = true }
41-
objc = { workspace = true }
41+
objc2 = { workspace = true }
4242

4343
[target.'cfg(not(target_os = "android"))'.dependencies]
4444
trash = "5.2.5"

yazi-fs/src/mounts/macos.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{ffi::{CStr, CString, OsString, c_void}, mem, os::unix::{ffi::OsStringE
33
use anyhow::{Result, bail};
44
use core_foundation_sys::{array::CFArrayRef, base::{CFRelease, kCFAllocatorDefault}, runloop::{CFRunLoopGetCurrent, CFRunLoopRun, kCFRunLoopDefaultMode}};
55
use libc::{c_char, mach_port_t};
6-
use objc::{msg_send, runtime::Object, sel, sel_impl};
6+
use objc2::{msg_send, runtime::AnyObject};
77
use scopeguard::defer;
88
use tracing::error;
99
use yazi_ffi::{CFDict, CFString, DADiskCopyDescription, DADiskCreateFromBSDName, DARegisterDiskAppearedCallback, DARegisterDiskDescriptionChangedCallback, DARegisterDiskDisappearedCallback, DASessionCreate, DASessionScheduleWithRunLoop, IOIteratorNext, IOObjectRelease, IORegistryEntryCreateCFProperty, IOServiceGetMatchingServices, IOServiceMatching};
@@ -161,7 +161,7 @@ impl Partitions {
161161
defer! { unsafe { CFRelease(property) } };
162162

163163
#[allow(unexpected_cfgs)]
164-
let cstr: *const c_char = unsafe { msg_send![property as *const Object, UTF8String] };
164+
let cstr: *const c_char = unsafe { msg_send![property as *const AnyObject, UTF8String] };
165165
Ok(if cstr.is_null() {
166166
bail!("Invalid value for the name property");
167167
} else {

yazi-plugin/preset/plugins/magick.lua

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,26 @@ function M:preload(job)
2727

2828
local cmd = M.with_limit()
2929
if job.args.flatten then
30-
cmd = cmd:arg("-flatten")
30+
cmd:arg("-flatten")
3131
end
32+
cmd:arg { tostring(job.file.url), "-auto-orient", "-strip" }
3233

33-
-- stylua: ignore
34-
cmd = cmd:arg {
35-
tostring(job.file.url), "-auto-orient", "-strip",
36-
"-sample", string.format("%dx%d>", rt.preview.max_width, rt.preview.max_height),
37-
"-quality", rt.preview.image_quality,
38-
}
34+
local size = string.format("%dx%d>", rt.preview.max_width, rt.preview.max_height)
35+
if rt.preview.image_filter == "nearest" then
36+
cmd:arg { "-sample", size }
37+
elseif rt.preview.image_filter == "catmull-rom" then
38+
cmd:arg { "-filter", "catrom", "-thumbnail", size }
39+
elseif rt.preview.image_filter == "lanczos3" then
40+
cmd:arg { "-filter", "lanczos", "-thumbnail", size }
41+
elseif rt.preview.image_filter == "gaussian" then
42+
cmd:arg { "-filter", "gaussian", "-thumbnail", size }
43+
else
44+
cmd:arg { "-filter", "triangle", "-thumbnail", size }
45+
end
46+
47+
cmd:arg { "-quality", rt.preview.image_quality }
3948
if job.args.bg then
40-
cmd = cmd:arg { "-background", job.args.bg, "-alpha", "remove" }
49+
cmd:arg { "-background", job.args.bg, "-alpha", "remove" }
4150
end
4251

4352
local status, err = cmd:arg(string.format("JPG:%s", cache)):status()

0 commit comments

Comments
 (0)