Round fractional device content resolutions with warnings
This commit is contained in:
parent
89697bd1a2
commit
49c576351b
|
|
@ -35,6 +35,7 @@ pub struct Layer {
|
|||
pub container: Geometry,
|
||||
pub framing: Option<(crate::formats::Source, crate::formats::Crop)>,
|
||||
pub unsupported: Option<String>,
|
||||
pub warning: Option<String>,
|
||||
}
|
||||
fn value<'a>(v: &'a Value, path: &str) -> Result<&'a Value, String> {
|
||||
v.pointer(path)
|
||||
|
|
@ -126,6 +127,18 @@ impl Snapshot {
|
|||
height,
|
||||
}
|
||||
.validate()?;
|
||||
let warning = content_resolution(layer).ok().and_then(|native| {
|
||||
let reported = [
|
||||
number(layer, "/status/pp/contentWidth").ok()?,
|
||||
number(layer, "/status/pp/contentHeight").ok()?,
|
||||
];
|
||||
(reported != native.map(f64::from)).then(|| {
|
||||
format!(
|
||||
"Device content resolution rounded from {} × {} to {} × {} pixels.",
|
||||
reported[0], reported[1], native[0], native[1]
|
||||
)
|
||||
})
|
||||
});
|
||||
let mut unsupported = None;
|
||||
for field in ["crop", "mask"] {
|
||||
for edge in ["left", "right", "top", "bottom"] {
|
||||
|
|
@ -169,6 +182,7 @@ impl Snapshot {
|
|||
container,
|
||||
framing,
|
||||
unsupported,
|
||||
warning,
|
||||
});
|
||||
}
|
||||
screens.push(Screen {
|
||||
|
|
@ -197,15 +211,24 @@ pub(crate) fn has_content_size(layer: &Value) -> bool {
|
|||
.is_some_and(|value| value.is_finite() && value > 0.0)
|
||||
})
|
||||
}
|
||||
/// Quantize reported native content dimensions without accepting invalid ranges.
|
||||
pub(crate) fn content_resolution(layer: &Value) -> Result<[u32; 2], String> {
|
||||
let reported = [
|
||||
number(layer, "/status/pp/contentWidth")?,
|
||||
number(layer, "/status/pp/contentHeight")?,
|
||||
];
|
||||
if reported.iter().any(|v| !(1.0..=16384.0).contains(v)) {
|
||||
return Err("Device content resolution must be from 1 to 16384 pixels per side.".into());
|
||||
}
|
||||
crate::formats::resolution_from_values(reported.map(f64::round))
|
||||
}
|
||||
|
||||
fn centered_framing(
|
||||
layer: &Value,
|
||||
container: Geometry,
|
||||
) -> Result<(Geometry, crate::formats::Source, crate::formats::Crop), String> {
|
||||
use crate::formats::{self, Aspect, Crop, Source};
|
||||
let native = formats::resolution_from_values([
|
||||
number(layer, "/status/pp/contentWidth")?,
|
||||
number(layer, "/status/pp/contentHeight")?,
|
||||
])?;
|
||||
let native = content_resolution(layer)?;
|
||||
let edge = |name: &str, axis: usize| -> Result<f64, String> {
|
||||
let value = number(layer, &format!("/crop/pp/{name}"))?;
|
||||
if value.fract() != 0.0 || !(0.0..=65535.0).contains(&value) {
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ impl Plan {
|
|||
.and_then(Value::as_f64),
|
||||
];
|
||||
if crate::device::has_content_size(device_layer)
|
||||
&& content != [Some(native[0]), Some(native[1])]
|
||||
&& crate::device::content_resolution(device_layer)? != source.native
|
||||
{
|
||||
return Err(format!(
|
||||
"Layer {destination}: editor native source {} × {} differs from device content {} × {}. Match source resolution before sending.",
|
||||
|
|
@ -383,6 +383,52 @@ mod tests {
|
|||
.unwrap();
|
||||
l
|
||||
}
|
||||
#[test]
|
||||
fn sending_accepts_rounded_content_dimensions_but_rejects_real_mismatches() {
|
||||
let mut state = snapshot();
|
||||
let editor = layout();
|
||||
let path = "/device/screenList/items/1/presetList/items/UP/liveLayerList/items/2/status/pp";
|
||||
*state.raw.pointer_mut(path).unwrap() =
|
||||
json!({"contentWidth":1919.7,"contentHeight":1080.2});
|
||||
for sizing in [Sizing::OutputBox, Sizing::SourceAspect] {
|
||||
assert!(
|
||||
Plan::prepare(
|
||||
&state,
|
||||
&editor,
|
||||
0,
|
||||
&[(2, "2".into())],
|
||||
Target::Preview,
|
||||
sizing
|
||||
)
|
||||
.is_ok()
|
||||
);
|
||||
}
|
||||
state.raw.pointer_mut(path).unwrap()["contentWidth"] = json!(1800.2);
|
||||
assert!(
|
||||
Plan::prepare(
|
||||
&state,
|
||||
&editor,
|
||||
0,
|
||||
&[(2, "2".into())],
|
||||
Target::Preview,
|
||||
Sizing::OutputBox
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
state.raw.pointer_mut(path).unwrap()["contentWidth"] = json!(16384.1);
|
||||
assert!(
|
||||
Plan::prepare(
|
||||
&state,
|
||||
&editor,
|
||||
0,
|
||||
&[(2, "2".into())],
|
||||
Target::Preview,
|
||||
Sizing::OutputBox
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allocated_layers_only_are_valid_send_destinations() {
|
||||
let mut raw = snapshot().raw;
|
||||
|
|
|
|||
|
|
@ -306,6 +306,19 @@ impl DeviceUi {
|
|||
"Send complete. Preset update sent; geometry verified by device readback."
|
||||
.into();
|
||||
}
|
||||
for screen in &snapshot.screens {
|
||||
for layer in &screen.layers {
|
||||
if let Some(warning) = &layer.warning {
|
||||
if !self.message.is_empty() {
|
||||
self.message.push('\n');
|
||||
}
|
||||
self.message.push_str(&format!(
|
||||
"Screen {} · Layer {}: {warning}",
|
||||
screen.id, layer.id
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
self.screen = self.screen.min(snapshot.screens.len() - 1);
|
||||
self.destinations =
|
||||
vec![Destination::Skip; snapshot.screens[self.screen].layers.len()];
|
||||
|
|
@ -508,10 +521,15 @@ impl Editor {
|
|||
match result {
|
||||
Ok(()) => {
|
||||
self.sync();
|
||||
let warnings = std::mem::take(&mut self.device.message);
|
||||
self.device.message = format!(
|
||||
"Loaded {} linked Preview layers. Undo restores the previous layout.",
|
||||
links.len()
|
||||
);
|
||||
if !warnings.is_empty() {
|
||||
self.device.message.push('\n');
|
||||
self.device.message.push_str(&warnings);
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
self.device.error = error;
|
||||
|
|
@ -651,6 +669,7 @@ impl Editor {
|
|||
}
|
||||
if let Some(snapshot) = &self.device.snapshot { ui.label(format!("Online · {}", snapshot.identity)); }
|
||||
else { ui.label("Offline"); }
|
||||
if !self.device.message.is_empty() { ui.label(&self.device.message); }
|
||||
if !self.device.error.is_empty() { ui.colored_label(ui.visuals().error_fg_color, &self.device.error); }
|
||||
if let Some(error) = &self.settings.error { ui.colored_label(ui.visuals().error_fg_color, error); }
|
||||
});
|
||||
|
|
@ -776,6 +795,7 @@ impl Editor {
|
|||
});
|
||||
ui.label(format!("{} × {} at {}, {}", midra_layout::view_pixels(layer.geometry.width), midra_layout::view_pixels(layer.geometry.height), midra_layout::view_pixels(layer.geometry.x), midra_layout::view_pixels(layer.geometry.y)));
|
||||
});
|
||||
if let Some(warning) = &layer.warning { ui.colored_label(ui.visuals().warn_fg_color, warning); }
|
||||
if let Some(reason) = &layer.unsupported { ui.weak(reason); }
|
||||
}
|
||||
});
|
||||
|
|
@ -974,6 +994,9 @@ fn send_review(
|
|||
"Preview snapshot container: {}",
|
||||
container_label(layer.container)
|
||||
));
|
||||
if let Some(warning) = &layer.warning {
|
||||
ui.colored_label(ui.visuals().warn_fg_color, warning);
|
||||
}
|
||||
if let Some(reason) = &layer.unsupported {
|
||||
ui.weak(reason);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -273,3 +273,39 @@ fn fetch_uses_custom_port_for_identity_and_state() {
|
|||
server.join().unwrap();
|
||||
assert!(result.unwrap().identity.starts_with("Eikos 4K"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractional_device_content_rounds_with_a_nonblocking_warning() {
|
||||
let (identity, mut raw) = fixture();
|
||||
let path = "/device/screenList/items/2/presetList/items/UP/liveLayerList/items/1";
|
||||
let layer = raw.pointer_mut(path).unwrap();
|
||||
layer["crop"]["pp"]["aspectOverride"] = json!("CENTERED");
|
||||
layer["crop"]["pp"]["left"] = json!(500);
|
||||
layer["status"] = json!({"pp":{"contentWidth":1919.7,"contentHeight":1080.2}});
|
||||
let state = Snapshot::parse(&identity, &raw).unwrap();
|
||||
let layer = &state.screens[0].layers[0];
|
||||
assert!(layer.unsupported.is_none());
|
||||
assert_eq!(layer.framing.unwrap().0.native, [1920, 1080]);
|
||||
assert!(
|
||||
layer
|
||||
.warning
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.contains("1919.7 × 1080.2 to 1920 × 1080")
|
||||
);
|
||||
assert!(state.screens[0].import(&[0]).is_ok());
|
||||
assert_eq!(state.raw, raw, "Keep the original device snapshot intact");
|
||||
for width in [0.5, 16384.1, 20000.0] {
|
||||
raw.pointer_mut(path).unwrap()["status"]["pp"]["contentWidth"] = json!(width);
|
||||
let invalid = Snapshot::parse(&identity, &raw).unwrap();
|
||||
assert!(invalid.screens[0].layers[0].unsupported.is_some());
|
||||
assert!(invalid.screens[0].import(&[0]).is_err());
|
||||
}
|
||||
raw.pointer_mut(path).unwrap()["status"]["pp"] =
|
||||
json!({"contentWidth":1920,"contentHeight":1080});
|
||||
assert!(
|
||||
Snapshot::parse(&identity, &raw).unwrap().screens[0].layers[0]
|
||||
.warning
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,3 +51,19 @@ input crop, zoom, visibility, borders, effects or device connection is encoded.
|
|||
The desktop SVG mapping dialog must be reviewed before applying; the image's
|
||||
visible bounds are not guaranteed to equal the container. This format must not
|
||||
be presented as a full device/project backup or as validated crop conversion.
|
||||
|
||||
## Fractional content resolution in the Rust adapter
|
||||
|
||||
Device-reported `status/pp/contentWidth` and `contentHeight` can be fractional.
|
||||
For centered crop reconstruction, the Rust adapter rounds them to the nearest
|
||||
whole pixel (positive half-pixels round upward), while keeping raw vendor state
|
||||
unchanged. Each original value must still be finite and within 1–16384; rounding
|
||||
does not rescue out-of-range values. The rounded dimensions become the editor's
|
||||
native source resolution, and normalized crop edges use those same dimensions.
|
||||
Container positions/sizes and the existing SVG bridge retain fractional precision.
|
||||
|
||||
A nonblocking layer warning gives both original and rounded dimensions. It is
|
||||
shown in connection/import/mapping feedback and retained after linked loading.
|
||||
Whole-pixel reports produce no rounding warning. The existing no-content fallback
|
||||
for unrouted, uncropped layers is unchanged. Invalid crops and real resolution
|
||||
mismatches remain errors.
|
||||
|
|
|
|||
|
|
@ -218,3 +218,13 @@ This is session-only state, not part of project JSON, SVG, preferences or
|
|||
recovery. Uncheck, disconnect, address change and project load discard staged
|
||||
input edits and reset opt-in. Existing files migrate without changes and never
|
||||
opt into shared input writes. No persistent format/version change is introduced.
|
||||
|
||||
### Fractional device content reports
|
||||
|
||||
Native-source compatibility compares the editor's integer resolution with the
|
||||
same rounded content dimensions used during snapshot import (nearest pixel,
|
||||
positive halves upward, original values bounded to 1–16384). Fractional reports
|
||||
such as 1919.7 × 1080.2 therefore match 1920 × 1080 instead of blocking a send.
|
||||
Actual resolution mismatches still fail. Snapshot feedback reports the rounding;
|
||||
raw device state is not rewritten. Existing whole-pixel size/position export and
|
||||
crop quantization remain unchanged.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Round fractional device-reported content dimensions to whole pixels for centered crop import/readback and send compatibility, with nonblocking before/after warnings. Preserve raw state and fractional box geometry; invalid ranges and genuine source mismatches still fail. Regression tests cover cropped import, warning behavior, both send sizing strategies and invalid ranges.
|
||||
|
||||
- Restore recovery sessions silently instead of opening a “Recovery restored” message. Keep recovery failures and retry information visible; regression coverage checks restored edits and absence of the success popup.
|
||||
|
||||
- Investigate Aquilon/LivePremier compatibility against the upstream web-control implementation; document firmware-specific geometry, bank and apply paths, saved-link constraints, and the staged adapter/acceptance plan. Research only: no Aquilon support or hardware verification claimed.
|
||||
|
|
|
|||
Loading…
Reference in New Issue