Support switching to cropped Midra inputs

This commit is contained in:
Dandaedre 2026-11-18 19:00:45 +01:00
parent 99260367ac
commit 5a574686a3
10 changed files with 132 additions and 46 deletions

2
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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(())

View File

@ -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")?,
]),
}
}

View File

@ -166,3 +166,41 @@ pub(super) fn parse(identity: String, raw: &Value) -> Result<Snapshot, String> {
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)
}

View File

@ -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() {

View File

@ -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 {

View File

@ -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.

View File

@ -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.

View File

@ -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.