From a557fed94e0f528c281b4bab241eb518b7f756ac Mon Sep 17 00:00:00 2001 From: FredApps Date: Wed, 18 Nov 2026 13:15:03 +0100 Subject: [PATCH 1/2] psd: expose path record knot decoding for consumer adapters --- crates/psd/src/path.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/psd/src/path.rs b/crates/psd/src/path.rs index 17604e654..dc1a091c9 100644 --- a/crates/psd/src/path.rs +++ b/crates/psd/src/path.rs @@ -64,6 +64,15 @@ impl PathRecord { pub fn is_knot(&self) -> bool { matches!(self.selector, 1 | 2 | 4 | 5) } + /// Decodes a knot's signed 8.24 coordinates as `(x, y)` document fractions. + /// Non-knot records return `None`; grouping and recovery policy remain with the caller. + pub fn knot(&self) -> Option { + if !self.is_knot() { + return None; + } + let pt = |i: usize| (fixed_to_f64(self.i32_at(i * 8 + 4)), fixed_to_f64(self.i32_at(i * 8))); + Some(PsdKnot { linked: matches!(self.selector, 1 | 4), pre: pt(0), anchor: pt(1), post: pt(2) }) + } } /// A Bézier knot as fractions of the document size: `(x, y)` pairs. @@ -158,15 +167,14 @@ impl PathData { // No preallocation: the count is untrusted (u16) and PsdKnot is 56 bytes. knots: Vec::new(), }); - } else if r.is_knot() { + } else if let Some(knot) = r.knot() { let closed = r.selector <= 2; if remaining == 0 && out.last().is_none_or(|s| s.closed != closed) { out.push(PsdSubpath { closed, operation: -1, knots: Vec::new() }); } remaining = remaining.saturating_sub(1); - let pt = |i: usize| (fixed_to_f64(r.i32_at(i * 8 + 4)), fixed_to_f64(r.i32_at(i * 8))); if let Some(s) = out.last_mut() { - s.knots.push(PsdKnot { linked: matches!(r.selector, 1 | 4), pre: pt(0), anchor: pt(1), post: pt(2) }); + s.knots.push(knot); } } } @@ -248,6 +256,23 @@ impl VectorMaskBlock { mod tests { use super::*; + #[test] + fn record_knot_decodes_signed_y_first_coordinates_without_grouping() { + let mut data = [0; 24]; + for (chunk, value) in data.chunks_exact_mut(4).zip([-(1i32 << 23), 1 << 22, 1 << 24, -(1 << 24), i32::MIN, i32::MAX]) { + chunk.copy_from_slice(&value.to_be_bytes()); + } + for selector in [1, 2, 4, 5] { + let knot = PathRecord { selector, data }.knot().unwrap(); + assert_eq!(knot.linked, matches!(selector, 1 | 4)); + assert_eq!(knot.pre, (0.25, -0.5)); + assert_eq!(knot.anchor, (-1.0, 1.0)); + assert_eq!(knot.post, (f64::from(i32::MAX) / 16_777_216.0, -128.0)); + } + for selector in [0, 3, 6, 7, 8, u16::MAX] { + assert_eq!(PathRecord { selector, data }.knot(), None); + } + } fn sample() -> Vec { vec![ PsdSubpath { From 4d2784ec90413e53b8f6c1a1c6b8526b8077e8c5 Mon Sep 17 00:00:00 2001 From: FredApps Date: Wed, 18 Nov 2026 13:38:03 +0100 Subject: [PATCH 2/2] psd: use fixed-size chunks in vector record fixture --- crates/psd/src/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/psd/src/path.rs b/crates/psd/src/path.rs index dc1a091c9..3520a71d8 100644 --- a/crates/psd/src/path.rs +++ b/crates/psd/src/path.rs @@ -259,7 +259,7 @@ mod tests { #[test] fn record_knot_decodes_signed_y_first_coordinates_without_grouping() { let mut data = [0; 24]; - for (chunk, value) in data.chunks_exact_mut(4).zip([-(1i32 << 23), 1 << 22, 1 << 24, -(1 << 24), i32::MIN, i32::MAX]) { + for (chunk, value) in data.as_chunks_mut::<4>().0.iter_mut().zip([-(1i32 << 23), 1 << 22, 1 << 24, -(1 << 24), i32::MIN, i32::MAX]) { chunk.copy_from_slice(&value.to_be_bytes()); } for selector in [1, 2, 4, 5] {