mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #13733 from SBaksa/photomerge-open-docs
Photomerge: merging the open documents no longer scans the dialog's folder (#13580)
This commit is contained in:
2 files changed
+33
-3
No files matched your search
@@ -303,12 +303,15 @@ impl Sources {
|
||||
fn load_sources(s: &Session, p: &Value, cmd: &str, budget: Option<usize>) -> Result<Loaded> {
|
||||
let mut src = Sources::default();
|
||||
let mut load = SourceLoad::new(budget);
|
||||
if p.get("useOpenDocuments").and_then(Value::as_bool).unwrap_or(false) {
|
||||
// "Use open documents" merges exactly the open documents; the dialog also sends its prefilled
|
||||
// folder (a string), which is not scanned then (#13580). Explicit file lists still add on top.
|
||||
let open = p.get("useOpenDocuments").and_then(Value::as_bool).unwrap_or(false);
|
||||
if open {
|
||||
for d in s.documents() {
|
||||
src.add(&mut load, d.doc.name.clone(), &d.doc, 0, cmd)?;
|
||||
}
|
||||
}
|
||||
let paths: Vec<String> = match p.get("paths").or_else(|| p.get("input")) {
|
||||
let paths: Vec<String> = match p.get("paths").or_else(|| p.get("input")).filter(|v| !(open && v.is_string())) {
|
||||
Some(Value::Array(a)) => a.iter().filter_map(Value::as_str).map(str::to_string).collect(),
|
||||
Some(Value::String(dir)) => list_images(dir)?,
|
||||
_ => Vec::new(),
|
||||
@@ -335,7 +338,8 @@ pub(crate) fn luma_alpha(surf: &Surface, area: Rect, k: usize) -> (usize, usize,
|
||||
for y in 0..h {
|
||||
let row = surf.read_region(Rect::new(area.x0, area.y0 + y as i32, area.x1, area.y0 + y as i32 + 1));
|
||||
for x in 0..w {
|
||||
let p = to_rgba(&fmt, &row[x * n..(x + 1) * n]);
|
||||
let Some(px) = row.get(x * n..(x + 1) * n) else { break };
|
||||
let p = to_rgba(&fmt, px);
|
||||
let i = (y / k) * sw + x / k;
|
||||
l[i] += (0.2126 * p[0] + 0.7152 * p[1] + 0.0722 * p[2]) * p[3] + (1.0 - p[3]) * 0.0;
|
||||
a[i] += p[3];
|
||||
|
||||
@@ -628,3 +628,29 @@ fn merge_to_hdr_pro_accepts_sources_without_the_photomerge_budget() {
|
||||
assert_eq!(srcs.len(), 2);
|
||||
assert_eq!(fmt, PixelFormat::RGBA8);
|
||||
}
|
||||
|
||||
/// Ticking "Use open documents" merges the open documents only: the dialog also sends its
|
||||
/// prefilled folder, which must not be scanned (#13580).
|
||||
#[test]
|
||||
fn photomerge_open_documents_ignores_the_folder() {
|
||||
let (sw, sh) = (520, 220);
|
||||
let sc = scene(sw, sh, 5);
|
||||
let open_two = |sc: &[[f32; 4]]| {
|
||||
let mut s = Session::new();
|
||||
for (k, x0) in [0usize, 180].into_iter().enumerate() {
|
||||
s.add_document(doc_from(&format!("o{k}"), &crop(sc, sw, x0, 10, 260, 200, 1.0), 260, 200, SampleType::U8), None);
|
||||
}
|
||||
s
|
||||
};
|
||||
for paths in [json!("."), json!("/no/such/folder"), json!("")] {
|
||||
let mut s = open_two(&sc);
|
||||
let r = s.execute("file.automate.photomerge", json!({"useOpenDocuments": true, "layout": "reposition", "paths": paths}));
|
||||
let r = r.unwrap_or_else(|e| panic!("{paths}: {e}"));
|
||||
assert_eq!(r["placed"].as_array().map(Vec::len), Some(2), "{paths}: {r}");
|
||||
}
|
||||
// Hostile shapes are errors or successes, never panics.
|
||||
let mut s = open_two(&sc);
|
||||
for paths in [json!(7), json!(null), json!([1, 2])] {
|
||||
let _ = s.execute("file.automate.photomerge", json!({"useOpenDocuments": true, "layout": "reposition", "paths": paths}));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user