From 3b414c519ca6f70b77bbe8c9f0da35427ffef83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 13:36:08 +0300 Subject: [PATCH] U13: remove Rotation::from_matrix and its matrix-reading tests; the mp4 demuxer maps its own display matrix and nothing calls from_matrix --- crates/ec-core/src/registry.rs | 104 +-------------------------------- 1 file changed, 1 insertion(+), 103 deletions(-) diff --git a/crates/ec-core/src/registry.rs b/crates/ec-core/src/registry.rs index 3a50c986..cc9a57ce 100644 --- a/crates/ec-core/src/registry.rs +++ b/crates/ec-core/src/registry.rs @@ -341,40 +341,6 @@ pub enum Rotation { } impl Rotation { - /// The rotation an ISO-BMFF `tkhd` display matrix states, from its linear - /// 2x2 part read as 16.16 fixed-point `i32`s. - /// - /// The matrix transforms a point `(x, y)` to `(a*x + c*y, b*x + d*y)`, so - /// the columns `(a, b)` and `(c, d)` are the turned axes: a pure rotation - /// has both columns the same length (isotropic) and one the other's quarter - /// turn (`a == d`, `b == -c`). Anything else is [`Rotation::Other`]. - /// - /// The reading is exact integer arithmetic: the four quarter turns are - /// recognised by an axis landing on an axis (`b == 0` or `a == 0`). An - /// encoder writes 16.16 quarter turns exactly, so a value within a fraction - /// of a degree of one that is not exactly one -- a hand-edited or rescaled - /// matrix -- reads as [`Rotation::Other`] rather than being rounded onto a - /// turn this decoder would then apply for real. - pub fn from_matrix(a: i32, b: i32, c: i32, d: i32) -> Rotation { - // A pure rotation: isotropic (a == d, b == -c) with something to turn. - // `c.checked_neg()` rather than `-c`: a crafted `tkhd` can carry - // `i32::MIN`, whose negation is not representable -- the plain form - // panics in a debug build and wraps onto a false quarter turn in a - // release one. `checked_neg` is `None` there, so the term falls through - // to `Other` below, which is the right reading for it anyway. - if a == d && c.checked_neg() == Some(b) && (a != 0 || b != 0) { - // `(a, b)` is the turned x-axis; a quarter turn lands it on an axis. - return match (a.signum(), b.signum()) { - (1, 0) => Rotation::None, - (-1, 0) => Rotation::Cw180, - (0, 1) => Rotation::Cw90, - (0, -1) => Rotation::Cw270, - _ => Rotation::Other { a, b, c, d }, - }; - } - Rotation::Other { a, b, c, d } - } - /// Quarter turns clockwise, where the stream is a quarter turn at all -- /// `None` for anything [`Rotation::Other`] carries. pub fn steps(self) -> Option { @@ -665,24 +631,7 @@ mod tests { } #[test] - fn quarter_turn_matrices_read_as_typed_rotations() { - const ONE: i32 = 65_536; // 16.16 unity. - let cases = [ - // A tkhd matrix and the turn it states, in this crate's clockwise - // convention. `(0, -1, 1, 0)` is what ffmpeg's - // `-display_rotation 90` writes: it asks the picture to be turned - // a quarter counter-clockwise here, which is Cw270. - ((ONE, 0, 0, ONE), Rotation::None), - ((0, -ONE, ONE, 0), Rotation::Cw270), - ((-ONE, 0, 0, -ONE), Rotation::Cw180), - ((0, ONE, -ONE, 0), Rotation::Cw90), - // A scaled identity is still no turn: the reading normalises by the - // matrix's own scale, so a differently-scaled copy reads the same. - ((2 * ONE, 0, 0, 2 * ONE), Rotation::None), - ]; - for ((a, b, c, d), want) in cases { - assert_eq!(Rotation::from_matrix(a, b, c, d), want, "{a} {b} {c} {d}"); - } + fn quarter_turn_steps_and_axes() { assert_eq!(Rotation::None.steps(), Some(0)); assert_eq!(Rotation::Cw90.steps(), Some(1)); assert_eq!(Rotation::Cw180.steps(), Some(2)); @@ -692,57 +641,6 @@ mod tests { assert!(Rotation::None.is_none()); } - #[test] - fn a_matrix_that_is_not_a_quarter_turn_is_kept_not_rounded() { - const ONE: i32 = 65_536; - // A 45-degree turn: isotropic and pure, but no axis lands on an axis. - assert_eq!( - Rotation::from_matrix(46_340, -46_340, 46_340, 46_340), - Rotation::Other { - a: 46_340, - b: -46_340, - c: 46_340, - d: 46_340, - } - ); - // A mirror (negative determinant), a mirror of a quarter turn (b != -c), - // a shear (a != d), and the degenerate all-zero matrix: none is a turn. - for (a, b, c, d) in [ - (ONE, 0, 0, -ONE), - (0, ONE, ONE, 0), - (ONE, 0, ONE, ONE), - (0, 0, 0, 0), - ] { - let got = Rotation::from_matrix(a, b, c, d); - assert!( - matches!(got, Rotation::Other { .. }), - "{a} {b} {c} {d} read as {got:?}" - ); - assert_eq!(got.steps(), None, "Other is not a quarter count"); - } - } - - #[test] - fn a_matrix_term_at_i32_min_is_not_a_quarter_turn() { - // A crafted `tkhd` can carry `i32::MIN`, whose negation is not - // representable. `from_matrix` must not panic (debug) or wrap onto a - // false turn (release) deciding `b == -c`, and such a term is no - // quarter turn anyway. `(0, MIN, MIN, 0)` is the load-bearing case: the - // wrapping form would read it as `Cw270`. - for (a, b, c, d) in [ - (0, i32::MIN, i32::MIN, 0), - (65_536, i32::MIN, i32::MIN, 65_536), - (i32::MIN, 0, i32::MIN, i32::MIN), - ] { - let got = Rotation::from_matrix(a, b, c, d); - assert!( - matches!(got, Rotation::Other { .. }), - "{a} {b} {c} {d} read as {got:?}" - ); - assert_eq!(got.steps(), None, "Other is not a quarter count"); - } - } - #[test] fn trait_objects_are_send() { fn assert_send() {}