diff --git a/Cargo.lock b/Cargo.lock index 52de4ba..e8be957 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -602,7 +602,7 @@ dependencies = [ [[package]] name = "canvas-pilot" -version = "0.10.0-rc.7" +version = "0.10.0-rc.8" dependencies = [ "base64 0.22.1", "craft-dwg", diff --git a/Cargo.toml b/Cargo.toml index 5e0cdc0..652bf36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"] resolver = "3" [workspace.package] -version = "0.10.0-rc.7" +version = "0.10.0-rc.8" edition = "2024" license = "MIT" repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot" diff --git a/crates/canvas-pilot/examples/read_input_capture.rs b/crates/canvas-pilot/examples/read_input_capture.rs index 8e69af7..0b4530f 100644 --- a/crates/canvas-pilot/examples/read_input_capture.rs +++ b/crates/canvas-pilot/examples/read_input_capture.rs @@ -12,6 +12,7 @@ fn main() -> Result<(), String> { .map_err(|_| "Invalid input number")?; let before = device::fetch_input(&host, input)?; let draft = InputDraft::read(&before, input)?; + let processed = device::input_content_resolution(&before, input)?; let bytes = device_capture::capture_for(&host, before.profile, input)?; let image = image::load_from_memory(&bytes).map_err(|e| e.to_string())?; let size = [image.width(), image.height()]; @@ -22,7 +23,7 @@ fn main() -> Result<(), String> { return Err("Capture geometry changed during the request".into()); } println!( - "{} · input {input} · PNG {} × {} · {geometry:?}", + "{} · input {input} · processed {processed:?} · PNG {} × {} · {geometry:?}", before.identity, size[0], size[1] ); Ok(()) diff --git a/crates/canvas-pilot/src/device.rs b/crates/canvas-pilot/src/device.rs index bfa5678..93c1db3 100644 --- a/crates/canvas-pilot/src/device.rs +++ b/crates/canvas-pilot/src/device.rs @@ -250,3 +250,31 @@ pub(crate) fn enrich_input( } Ok(()) } + +/// Dimensions of the selected input after device preprocessing. Midra input crop +/// is already included in imageWidth/imageHeight and must not be subtracted twice. +pub fn input_content_resolution(snapshot: &Snapshot, input: u32) -> Result<[u32; 2], String> { + let raw = value( + &snapshot.raw, + &format!( + "/device/inputList/items/{}", + snapshot.profile.input_key(input) + ), + )?; + let plug = text(raw, "/status/pp/plug")?; + let settings = value(raw, &format!("/plugList/items/{plug}"))?; + if settings + .pointer("/status/signal/pp/isValid") + .and_then(Value::as_bool) + != Some(true) + { + return Err("Input has no valid signal".into()); + } + match snapshot.profile { + Profile::Midra4k => midra::cropped_input_resolution(settings), + Profile::Aquilon6 => crate::formats::resolution_from_values([ + number(settings, "/status/signal/pp/imageWidth")?, + number(settings, "/status/signal/pp/imageHeight")?, + ]), + } +} diff --git a/crates/canvas-pilot/src/device/midra.rs b/crates/canvas-pilot/src/device/midra.rs index 907733e..85a8a09 100644 --- a/crates/canvas-pilot/src/device/midra.rs +++ b/crates/canvas-pilot/src/device/midra.rs @@ -166,3 +166,41 @@ pub(super) fn parse(identity: String, raw: &Value) -> Result { raw: raw.clone(), }) } + +/// Midra image dimensions already exclude the shared input crop. Verify that +/// controls and signal readback agree before using that processed pixel space. +pub(super) fn cropped_input_resolution(plug: &Value) -> Result<[u32; 2], String> { + let native = crate::formats::resolution_from_values([ + number(plug, "/status/signal/pp/imageWidth")?, + number(plug, "/status/signal/pp/imageHeight")?, + ])?; + let edge = |key| { + plug.pointer(&format!("/settings/cropping/control/pp/{key}")) + .and_then(Value::as_f64) + .filter(|v| v.is_finite() && *v >= 0.) + .ok_or_else(|| { + "Input crop status unavailable; refresh before switching input.".to_owned() + }) + }; + let crop = crate::formats::Crop { + left: edge("left")?, + right: edge("right")?, + top: edge("top")?, + bottom: edge("bottom")?, + }; + if crop != crate::formats::Crop::default() { + let full = [ + number(plug, "/status/signal/pp/aspectWidth")?, + number(plug, "/status/signal/pp/aspectHeight")?, + ]; + let retained = crop.remaining(full)?; + if retained + .iter() + .zip(native) + .any(|(expected, actual)| (*expected - actual as f64).abs() > 1.) + { + return Err("Input crop has not settled; refresh before switching input.".into()); + } + } + Ok(native) +} diff --git a/crates/canvas-pilot/src/device_send.rs b/crates/canvas-pilot/src/device_send.rs index dcaa377..4dc2e4c 100644 --- a/crates/canvas-pilot/src/device_send.rs +++ b/crates/canvas-pilot/src/device_send.rs @@ -137,24 +137,8 @@ impl Plan { let settings = raw .pointer(&format!("/plugList/items/{plug}")) .ok_or("Input settings unavailable")?; - let native = - crate::formats::resolution_from_values(["imageWidth", "imageHeight"].map(|k| { - settings - .pointer(&format!("/status/signal/pp/{k}")) - .and_then(Value::as_f64) - .unwrap_or(0.) - }))?; + let native = device::input_content_resolution(snapshot, *input)?; if snapshot.profile == device::Profile::Midra4k { - for edge in ["left", "right", "top", "bottom"] { - if settings - .pointer(&format!("/settings/cropping/control/pp/{edge}")) - .and_then(Value::as_f64) - .ok_or("Input crop status unavailable; refresh before switching input.")? - != 0. - { - return Err("Input switching with active input crop is not yet supported. Choose an uncropped input.".into()); - } - } for (key, expected) in [("signal", "NATIVE"), ("transformTo", "SIGNAL")] { if settings .pointer(&format!("/settings/aspect/pp/{key}")) @@ -880,6 +864,47 @@ mod tests { ) .is_err() ); + for (left, top) in [(12, 0), (978, 51), (0, 400)] { + let mut cropped = state.clone(); + let plug = &mut cropped.raw["device"]["inputList"]["items"]["INPUT_5"]["plugList"]["items"] + ["HDMI"]; + plug["status"]["signal"]["pp"]["aspectWidth"] = json!(1920); + plug["status"]["signal"]["pp"]["aspectHeight"] = json!(1080); + plug["status"]["signal"]["pp"]["imageWidth"] = json!(1920 - left); + plug["status"]["signal"]["pp"]["imageHeight"] = json!(1080 - top); + plug["settings"]["cropping"]["control"]["pp"]["left"] = json!(left); + plug["settings"]["cropping"]["control"]["pp"]["top"] = json!(top); + assert_eq!( + device::input_content_resolution(&cropped, 5).unwrap(), + [(1920 - left) as u32, (1080 - top) as u32] + ); + let plan = Plan::prepare_with_inputs( + &cropped, + &editor, + 0, + &mappings, + Target::Preview, + Sizing::OutputBox, + &[(2, 5)].into(), + ) + .unwrap(); + assert_eq!(plan.changes[0].after, json!("INPUT_5")); + assert!( + plan.changes + .iter() + .all(|change| !change.path.iter().any(|part| part == "inputList")) + ); + assert!(validate_fresh(&plan, &cropped).is_ok()); + let mut stale = cropped.clone(); + stale.raw["device"]["inputList"]["items"]["INPUT_5"]["plugList"]["items"]["HDMI"]["settings"] + ["cropping"]["control"]["pp"]["left"] = json!(left + 20); + assert!(validate_fresh(&plan, &stale).is_err()); + assert!( + device::input_content_resolution(&stale, 5) + .unwrap_err() + .contains("not settled") + ); + } } #[test] fn sending_accepts_rounded_content_dimensions_but_rejects_real_mismatches() { diff --git a/crates/canvas-pilot/src/device_ui.rs b/crates/canvas-pilot/src/device_ui.rs index 5a4e2f3..42aa6ce 100644 --- a/crates/canvas-pilot/src/device_ui.rs +++ b/crates/canvas-pilot/src/device_ui.rs @@ -701,31 +701,7 @@ impl Editor { .snapshot .as_ref() .ok_or("Refresh the connection to read input dimensions.")?; - let raw = snapshot - .raw - .pointer(&format!( - "/device/inputList/items/{}", - snapshot.profile.input_key(input) - )) - .ok_or("Input unavailable")?; - let plug = raw - .pointer("/status/pp/plug") - .and_then(serde_json::Value::as_str) - .ok_or("Input plug unavailable")?; - let signal = raw - .pointer(&format!("/plugList/items/{plug}/status/signal/pp")) - .ok_or("Input signal unavailable")?; - if signal.get("isValid").and_then(serde_json::Value::as_bool) != Some(true) { - return Err("Input has no valid signal".into()); - } - let native = canvas_pilot::formats::resolution_from_values( - ["imageWidth", "imageHeight"].map(|key| { - signal - .get(key) - .and_then(serde_json::Value::as_f64) - .unwrap_or(0.) - }), - )?; + let native = device::input_content_resolution(snapshot, input)?; self.layout.set_layer_source_resolution(i, native) })(); match result { diff --git a/docs/canvas-pilot/changelog.md b/docs/canvas-pilot/changelog.md index 81d9506..510b3e6 100644 --- a/docs/canvas-pilot/changelog.md +++ b/docs/canvas-pilot/changelog.md @@ -4,6 +4,13 @@ ## Unreleased +### v0.10.0-rc.8 + +- Support switching to cropped Midra inputs using their processed image dimensions, + without applying input crop twice. Verify crop controls against signal readback + and retain freshness checks. Preview source adaptation uses the same validation. +- Aquilon shared-crop and input aspect-correction restrictions remain unchanged. + ### v0.10.0-rc.7 - Stabilize input-preview GUI tests under CI load with a controlled capture clock. diff --git a/docs/canvas-pilot/guide/formats-and-crop.md b/docs/canvas-pilot/guide/formats-and-crop.md index 80b936f..577ae95 100644 --- a/docs/canvas-pilot/guide/formats-and-crop.md +++ b/docs/canvas-pilot/guide/formats-and-crop.md @@ -395,4 +395,7 @@ same editor source. Undo restores the previous framing. Input routing remains opt-in through **Change input**, applied only on Send. Explicit input-switch sends also adapt framing when a saved source size differs. -Existing restrictions on shared device input crop/aspect correction still apply. +Midra inputs with applied crop are supported once crop controls and processed +image dimensions agree. Input crop is already included in those dimensions; +layer crop and fit apply afterward. Input aspect correction and Aquilon shared +input crop retain their existing transfer restrictions. diff --git a/docs/interfaces/midra-input-preview.md b/docs/interfaces/midra-input-preview.md index c33fbac..e627195 100644 --- a/docs/interfaces/midra-input-preview.md +++ b/docs/interfaces/midra-input-preview.md @@ -203,3 +203,11 @@ stays fixed; ordinary framing is recalculated with the existing zoom and normali focus, while explicit fit keeps crop fractions. A shared source is copied before replacement so other layers are unaffected. This is an undoable editor change, persisted through the existing source/crop fields without a schema change. + +Midra input switching accepts active input crop. The shared input-dimension reader +checks nonnegative finite crop edges and, for active crop, verifies +`aspectWidth - left - right` / `aspectHeight - top - bottom` against the processed +`imageWidth` / `imageHeight` (one-pixel tolerance). Unsettled or incomplete state +blocks the operation. Send conversion uses processed dimensions directly and +observes the input state for preflight; no input crop writes are generated. +Aquilon cropping and aspect-corrected input switching are not enabled by this rule.