Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions apps/lightcraft-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,16 @@ fn mcp(args: &[String]) -> Result<(), String> {
while i < args.len() {
match args[i].as_str() {
"--connect" => {
// Optional address argument.
match args.get(i + 1).filter(|a| !a.starts_with("--") && a.contains(':')) {
Some(a) => {
connect = Some(a.clone());
i += 1;
}
None => connect = Some(DEFAULT_ADDR.to_string()),
let (addr, took) = connect_value(args.get(i + 1).map(String::as_str));
connect = Some(addr);
if took {
i += 1;
}
}
a if a.starts_with("--connect=") => connect = Some(a["--connect=".len()..].to_string()),
a if a.starts_with("--connect=") => {
let (addr, _) = connect_value(Some(&a["--connect=".len()..]));
connect = Some(addr);
}
"--headless" => connect = None,
"--demo" => demo = true,
"--compact" => compact = true,
Expand Down Expand Up @@ -525,14 +525,17 @@ fn run(args: &[String]) -> Result<(), String> {
i += 1;
break;
}
"--connect" => match args.get(i + 1).filter(|a| a.contains(':') && !a.contains('=')) {
Some(a) => {
connect = Some(a.clone());
"--connect" => {
let (addr, took) = connect_value(args.get(i + 1).map(String::as_str));
connect = Some(addr);
if took {
i += 1;
}
None => connect = Some(DEFAULT_ADDR.to_string()),
},
a if a.starts_with("--connect=") => connect = Some(a["--connect=".len()..].to_string()),
}
a if a.starts_with("--connect=") => {
let (addr, _) = connect_value(Some(&a["--connect=".len()..]));
connect = Some(addr);
}
"--demo" => demo = true,
"--library" => library = Some(take_value(args, &mut i, "--library")?.to_string()),
"--import" => imports.push(take_value(args, &mut i, "--import")?.to_string()),
Expand Down Expand Up @@ -627,6 +630,18 @@ fn take_value<'a>(args: &'a [String], i: &mut usize, flag: &str) -> Result<&'a s

/// The port an `--connect` address names, for the recovery hint. The whole address when it has
/// no port, so a hint is never built from a guess.
/// `--connect` takes an address, or a bare port (`7980` → `127.0.0.1:7980`). A following
/// command id is left alone (#1178).
fn connect_value(next: Option<&str>) -> (String, bool) {
match next {
Some(a) if !a.starts_with('-') && a.contains(':') && !a.contains('=') => (a.to_string(), true),
Some(a) if !a.is_empty() && a.bytes().all(|c| c.is_ascii_digit()) && a.parse::<u16>().ok().is_some_and(|p| p > 0) => {
(format!("127.0.0.1:{a}"), true)
}
_ => (DEFAULT_ADDR.to_string(), false),
}
}

fn connect_port(addr: &str) -> &str {
addr.rsplit_once(':').map_or(addr, |(_, port)| port)
}
Expand Down Expand Up @@ -965,6 +980,20 @@ fn denoise_serve(args: &[String]) -> Result<(), String> {
serve(listener, s.model, s.tile, s.device, s.run, opts, std::sync::Arc::new(|m: &str| eprintln!("lightcraft-cli denoise-serve: {m}")))
}

#[cfg(test)]
mod connect_tests {
use super::connect_value;

#[test]
fn a_bare_port_is_loopback_and_a_command_is_not_consumed() {
assert_eq!(connect_value(Some("7980")), ("127.0.0.1:7980".into(), true));
assert_eq!(connect_value(Some("127.0.0.1:7980")), ("127.0.0.1:7980".into(), true));
assert_eq!(connect_value(Some("photo.rate")), ("127.0.0.1:7980".into(), false));
assert_eq!(connect_value(Some("0")), ("127.0.0.1:7980".into(), false));
assert_eq!(connect_value(None), ("127.0.0.1:7980".into(), false));
}
}

#[cfg(not(feature = "denoise"))]
fn denoise_serve(_: &[String]) -> Result<(), String> {
Err("denoise-serve: this build has no denoise support (build with the `denoise` feature)".into())
Expand Down
5 changes: 5 additions & 0 deletions contributors/people.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ sync_github_name = true

[people.sanyamsingh001]
display_name = "sanyamsingh001"

[people.switch87]
real_name = "Gert Pellin"
display_name = "Gert Pellin"
sync_github_name = false
56 changes: 52 additions & 4 deletions crates/codecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,25 @@ pub fn decode_unguarded(bytes: &[u8], format: Format, opts: &DecodeOptions) -> R

/// Convert a decode result to linear Rec.2020 D65 (Bradford-adapted), the develop working space.
pub fn to_working(d: &Decoded) -> Rgb32f {
if d.space.is_working() {
return d.image.clone();
let mut image = if d.space.is_working() {
d.image.clone()
} else {
let m = d.space.to_working().to_f32();
d.image.map(|p| mat_apply(&m, p))
};
// Straight alpha onto white. JPEG and contact sheets have no alpha, and a transparent
// pixel is usually stored as black (#1212).
if let Some(alpha) = &d.alpha {
let w = image.width;
lightcraft_raster::par_rows(&mut image.data, w, |y, row| {
let a = alpha.row(y);
for (p, &alpha) in row.iter_mut().zip(a) {
let a = alpha.clamp(0.0, 1.0);
*p = p.map(|c| c * a + (1.0 - a));
}
});
}
let m = d.space.to_working().to_f32();
d.image.map(|p| mat_apply(&m, p))
image
}

/// Where a thumbnail came from.
Expand Down Expand Up @@ -323,3 +337,37 @@ pub fn decode_thumbnail_with(bytes: &[u8], opts: &ThumbnailOptions) -> Result<Th
source_height: d.source_height,
})
}

#[cfg(test)]
mod alpha_tests {
use super::*;
use lightcraft_raster::Plane;

#[test]
fn straight_alpha_composites_onto_white_in_the_working_space() {
let image = Rgb32f::filled(2, 1, [0.0, 0.0, 0.0]);
let alpha = Plane::from_fn(2, 1, |x, _| if x == 0 { 0.0 } else { 0.5 });
let d = Decoded {
format: Format::Png,
image,
alpha: Some(alpha),
space: SourceSpace::named(NamedSpace::Rec2020, SpaceOrigin::Container),
bit_depth: 8,
float: false,
has_alpha: true,
grayscale: false,
cmyk: false,
orientation: 1,
exif: None,
xmp: None,
icc: None,
width: 2,
height: 1,
source_width: 2,
source_height: 1,
};
let w = to_working(&d);
assert!((w.get(0, 0)[0] - 1.0).abs() < 1e-5, "a fully transparent black pixel becomes white");
assert!((w.get(1, 0)[0] - 0.5).abs() < 1e-5);
}
}
25 changes: 24 additions & 1 deletion crates/mcp/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::backend::{Backend, ProgressHook};
/// File extensions recognised as photos when expanding folders.
pub const PHOTO_EXTENSIONS: &[&str] = &[
"jpg", "jpeg", "png", "tif", "tiff", "webp", "dng", "cr2", "cr3", "nef", "arw", "raf", "orf", "rw2", "rwl", "raw", "pef", "srw", "psd", "jxl",
"gif", "bmp", "avif", // containers LightCraft cannot decode but imports as preview only (their embedded JPEG)
"gif", "bmp", "avif", "heic", "heif", "nrw", // avif is preview-only; heic/heif/nrw match the engine list (#1080)
"iiq", "crw", "mrw", "x3f", "kdc", "mos", "erf", "3fr", "fff",
];

Expand Down Expand Up @@ -193,6 +193,29 @@ pub fn expand_paths(paths: &[String]) -> Vec<String> {
out
}

#[cfg(test)]
mod expand_tests {
use super::expand_paths;

#[test]
fn a_folder_import_includes_heic_heif_and_nrw() {
let dir = std::env::temp_dir().join(format!("lightcraft-ext-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
for name in ["a.heic", "b.HEIF", "c.nrw", "d.png", "note.txt"] {
std::fs::write(dir.join(name), b"x").unwrap();
}
let got = expand_paths(&[dir.to_string_lossy().to_string()]);
let names: Vec<String> = got.iter().map(|p| std::path::Path::new(p).file_name().unwrap().to_string_lossy().to_lowercase()).collect();
assert!(names.contains(&"a.heic".into()), "{names:?}");
assert!(names.contains(&"b.heif".into()), "{names:?}");
assert!(names.contains(&"c.nrw".into()), "{names:?}");
assert!(names.contains(&"d.png".into()), "{names:?}");
assert!(!names.iter().any(|n| n == "note.txt"), "{names:?}");
let _ = std::fs::remove_dir_all(&dir);
}
}

/// Encode by extension: `.png` (default), `.jpg`/`.jpeg` (quality), `.tif`/`.tiff`, `.webp` (lossless),
/// `.avif`, `.jxl` — via the shared export encoder (embeds an sRGB profile).
pub fn encode_image(ext: &str, img: &Rgba8, quality: u8) -> Result<Vec<u8>, String> {
Expand Down
5 changes: 3 additions & 2 deletions crates/pipeline/src/spots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ fn fill_box(src: &mut [[f32; 3]], tgt: &[[f32; 3]], alpha: &[f32], bw: usize, bh
let flat: Vec<f32> = tgt.iter().flatten().copied().collect();
let out = lightcraft_inpaint::complete(bw, bh, 3, &flat, &hole, &lightcraft_inpaint::CompleteParams::default())
.unwrap_or_else(|| lightcraft_inpaint::membrane_fill(bw, bh, 3, &flat, &hole));
for (d, v) in src.iter_mut().zip(out.chunks_exact(3)) {
*d = [v[0], v[1], v[2]];
let (pixels, _) = out.as_chunks::<3>();
for (d, v) in src.iter_mut().zip(pixels) {
*d = *v;
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@
"In memory — nothing is saved": "Im Arbeitsspeicher — nichts wird gespeichert",
"In use": "In Verwendung",
"In-memory session: these settings last until LightCraft quits.": "Sitzung im Arbeitsspeicher: Diese Einstellungen gelten bis zum Beenden von LightCraft.",
"Include selected photos": "Ausgewählte Fotos einschließen",
"Include subfolders": "Unterordner einbeziehen",
"Increase Brush Feather": "Weiche Pinselkante vergrößern",
"Increase Brush Size": "Pinselgröße vergrößern",
Expand Down
2 changes: 1 addition & 1 deletion crates/ui-egui/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ mod tests {
}
assert_eq!(h.app.ui.dialog, None, "Return confirmed the dialog ({typed})");
};
confirm(&mut h, Dialog::NewAlbum { name: String::new(), folder: false, parent: None }, "Weddings");
confirm(&mut h, Dialog::NewAlbum { name: String::new(), folder: false, parent: None, include_selected: true }, "Weddings");
assert!(album(&h, "Weddings").is_some(), "New Album");
confirm(&mut h, Dialog::RenameAlbum { id: garden, name: "Garden".into() }, "Flowers");
assert_eq!(album(&h, "Flowers"), Some(garden), "Rename Album");
Expand Down
2 changes: 2 additions & 0 deletions crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ mod tests_sync;
#[cfg(test)]
mod tests_titlebar;
#[cfg(test)]
mod tests_toast;
#[cfg(test)]
mod tests_unsaved;
#[cfg(test)]
mod tests_wb_selector;
Expand Down
17 changes: 13 additions & 4 deletions crates/ui-egui/src/menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,13 +1069,22 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option<Re
Ok(Value::Null)
}
"dialog.newFolder" => {
app.ui.dialog =
Some(Dialog::NewAlbum { name: p.get("name").and_then(Value::as_str).unwrap_or("").into(), folder: true, parent: parent_param(p) });
app.ui.dialog = Some(Dialog::NewAlbum {
name: p.get("name").and_then(Value::as_str).unwrap_or("").into(),
folder: true,
parent: parent_param(p),
include_selected: false,
});
Ok(Value::Null)
}
"dialog.newAlbum" => {
app.ui.dialog =
Some(Dialog::NewAlbum { name: p.get("name").and_then(Value::as_str).unwrap_or("").into(), folder: false, parent: parent_param(p) });
// {name?, parent?, includeSelected? (true)}
app.ui.dialog = Some(Dialog::NewAlbum {
name: p.get("name").and_then(Value::as_str).unwrap_or("").into(),
folder: false,
parent: parent_param(p),
include_selected: p.get("includeSelected").and_then(Value::as_bool).unwrap_or(true),
});
Ok(Value::Null)
}
"dialog.autoStack" => {
Expand Down
2 changes: 1 addition & 1 deletion crates/ui-egui/src/panels/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ pub(crate) fn filmstrip(app: &mut LightcraftApp, ui: &mut egui::Ui, r: Rect) {
// a vertical mouse wheel scrolls the strip sideways (horizontal trackpad scrolls still work)
child.style_mut().always_scroll_the_only_direction = true;
// only a new active photo (or the strip appearing) scrolls it; see `grid::follow_active`
let follow = super::grid::follow_active(child.ctx(), egui::Id::new("film-follow-active"), active);
let follow = super::grid::follow_active(child.ctx(), egui::Id::new("film-follow-active"), active, app.session.source);
egui::ScrollArea::horizontal().id_salt("filmstrip").auto_shrink([false, false]).show_viewport(&mut child, |ui, vp| {
let (area, _) = ui.allocate_exact_size(vec2(ids.len() as f32 * cell_w, r.height() - 16.0), Sense::hover());
app.film_scroll = Some(vp.left());
Expand Down
17 changes: 14 additions & 3 deletions crates/ui-egui/src/panels/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,18 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) {
confirm = true;
}
}
Dialog::NewAlbum { name, .. } | Dialog::RenameAlbum { name, .. } => {
Dialog::NewAlbum { name, folder, include_selected, .. } => {
if dialog_field(ui, "field:albumName", name, "Name") {
confirm = true;
}
// as in Lightroom, the option is only there when something is selected
if !*folder && !app.session.targets(&json!({})).is_empty() {
ui.add_space(6.0);
let r = ui.checkbox(include_selected, crate::i18n::tr("Include selected photos"));
crate::widgets::register(ui.ctx(), "check:albumIncludeSelected", r.rect);
}
}
Dialog::RenameAlbum { name, .. } => {
if dialog_field(ui, "field:albumName", name, "Name") {
confirm = true;
}
Expand Down Expand Up @@ -1520,8 +1531,8 @@ pub fn confirm_dialog(app: &mut LightcraftApp, dlg: &Dialog) -> Result<serde_jso
}
r
}
Dialog::NewAlbum { name, folder, parent } => {
created_in(app, "album.create", json!({"name": name, "folder": folder, "addSelected": !folder, "parent": parent}))
Dialog::NewAlbum { name, folder, parent, include_selected } => {
created_in(app, "album.create", json!({"name": name, "folder": folder, "addSelected": !folder && *include_selected, "parent": parent}))
}
Dialog::RenameAlbum { id, name } => app.run("album.rename", json!({"id": id, "name": name})),
Dialog::TextPrompt { value, command, params, key, .. } => {
Expand Down
32 changes: 27 additions & 5 deletions crates/ui-egui/src/panels/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn show_inner(app: &mut LightcraftApp, ui: &mut egui::Ui) {
let active = app.session.selection.active;
// bring the active photo into view when it changes (keyboard, click, command) or the grid
// comes back on screen; otherwise the scroll position is the user's
let scroll_to: Option<Rect> = if follow_active(ui.ctx(), egui::Id::new("grid-follow-active"), active) {
let scroll_to: Option<Rect> = if follow_active(ui.ctx(), egui::Id::new("grid-follow-active"), active, app.session.source) {
active.and_then(|a| ids.iter().position(|x| *x == a)).and_then(|i| lay.cells.get(i).copied())
} else {
None
Expand Down Expand Up @@ -295,16 +295,29 @@ fn show_inner(app: &mut LightcraftApp, ui: &mut egui::Ui) {
/// the strip was not drawn on the previous pass (view switch, panel shown again). Otherwise the
/// scroll position is the user's: time passing, finished renders, edits to the photo or a released
/// scroll bar never move it (issue #11).
pub(crate) fn follow_active(ctx: &egui::Context, key: egui::Id, active: Option<PhotoId>) -> bool {
pub(crate) fn follow_active(ctx: &egui::Context, key: egui::Id, active: Option<PhotoId>, source: lightcraft_engine::LibrarySource) -> bool {
let pass = ctx.cumulative_pass_nr();
let last: Option<(Option<PhotoId>, u64)> = ctx.data(|d| d.get_temp(key));
ctx.data_mut(|d| d.insert_temp(key, (active, pass)));
let last: Option<(Option<PhotoId>, lightcraft_engine::LibrarySource, u64)> = ctx.data(|d| d.get_temp(key));
ctx.data_mut(|d| d.insert_temp(key, (active, source, pass)));
match last {
Some((was, drawn)) => was != active || drawn + 1 < pass,
Some((was, where_, drawn)) => follow_changed(was, where_, drawn, active, source, pass),
None => true,
}
}

/// Scroll when the active photo changes, the strip was not drawn last pass, or the same photo
/// sits in a different library source (another album) (#1142).
pub(crate) fn follow_changed(
was: Option<PhotoId>,
where_was: lightcraft_engine::LibrarySource,
drawn: u64,
active: Option<PhotoId>,
source: lightcraft_engine::LibrarySource,
pass: u64,
) -> bool {
was != active || where_was != source || drawn + 1 < pass
}

/// Height of a date header row (points).
pub const HEADER_H: f32 = 40.0;

Expand Down Expand Up @@ -1146,6 +1159,15 @@ pub fn context_menu(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) {
mod tests {
use super::*;

#[test]
fn the_same_photo_in_another_source_scrolls_into_view() {
let id = PhotoId(3);
let all = lightcraft_engine::LibrarySource::All;
let album = lightcraft_engine::LibrarySource::Album(lightcraft_catalog::AlbumId(9));
assert!(!follow_changed(Some(id), all, 4, Some(id), all, 5));
assert!(follow_changed(Some(id), all, 4, Some(id), album, 5));
}

#[test]
fn ungrouped_justified_rows_fill_the_width() {
let aspects = [1.5f32, 1.5, 0.66, 1.0, 1.5, 1.5, 1.5];
Expand Down
4 changes: 2 additions & 2 deletions crates/ui-egui/src/panels/left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ fn sections_menu(app: &mut LightcraftApp, ui: &mut egui::Ui, on: Option<SidebarS
/// The menu of Albums' +: Create Album, Smart Album, Folder…
fn new_album_menu(app: &mut LightcraftApp, ui: &mut egui::Ui) {
if ui.button(crate::i18n::tr("Create Album…")).clicked() {
app.ui.dialog = Some(crate::state::Dialog::NewAlbum { name: String::new(), folder: false, parent: None });
app.ui.dialog = Some(crate::state::Dialog::NewAlbum { name: String::new(), folder: false, parent: None, include_selected: true });
}
if ui.button(crate::i18n::tr("Create Smart Album…")).clicked() {
app.ui.dialog = Some(crate::state::Dialog::SmartRules {
Expand All @@ -547,7 +547,7 @@ fn new_album_menu(app: &mut LightcraftApp, ui: &mut egui::Ui) {
app.ui.dialog = Some(crate::state::Dialog::NewSmartAlbum { name: String::new(), parent: None });
}
if ui.button(crate::i18n::tr("Create Folder…")).clicked() {
app.ui.dialog = Some(crate::state::Dialog::NewAlbum { name: String::new(), folder: true, parent: None });
app.ui.dialog = Some(crate::state::Dialog::NewAlbum { name: String::new(), folder: true, parent: None, include_selected: false });
}
// only once the albums were put in an order by hand
if app.session.catalog.album_children_are_ordered(None) {
Expand Down
Loading