forge
Explore
Log in

Don't you dare go Hollow

U13: remove Rotation::from_matrix and its matrix-reading tests; the mp4 demuxer maps its own display matrix and nothing calls from_matrix

Browse files at this commit

3b414c519ca6f70b77bbe8c9f0da35427ffef83dAhmet Kaan GümüşParent: 9e262a8
crates/ec-core/src/registry.rsmodified+1 -103
@@ -341,40 +341,6 @@ pub enum Rotation {
341341 }
342342
343343 impl Rotation {
344- /// The rotation an ISO-BMFF `tkhd` display matrix states, from its linear
345- /// 2x2 part read as 16.16 fixed-point `i32`s.
346- ///
347- /// The matrix transforms a point `(x, y)` to `(a*x + c*y, b*x + d*y)`, so
348- /// the columns `(a, b)` and `(c, d)` are the turned axes: a pure rotation
349- /// has both columns the same length (isotropic) and one the other's quarter
350- /// turn (`a == d`, `b == -c`). Anything else is [`Rotation::Other`].
351- ///
352- /// The reading is exact integer arithmetic: the four quarter turns are
353- /// recognised by an axis landing on an axis (`b == 0` or `a == 0`). An
354- /// encoder writes 16.16 quarter turns exactly, so a value within a fraction
355- /// of a degree of one that is not exactly one -- a hand-edited or rescaled
356- /// matrix -- reads as [`Rotation::Other`] rather than being rounded onto a
357- /// turn this decoder would then apply for real.
358- pub fn from_matrix(a: i32, b: i32, c: i32, d: i32) -> Rotation {
359- // A pure rotation: isotropic (a == d, b == -c) with something to turn.
360- // `c.checked_neg()` rather than `-c`: a crafted `tkhd` can carry
361- // `i32::MIN`, whose negation is not representable -- the plain form
362- // panics in a debug build and wraps onto a false quarter turn in a
363- // release one. `checked_neg` is `None` there, so the term falls through
364- // to `Other` below, which is the right reading for it anyway.
365- if a == d && c.checked_neg() == Some(b) && (a != 0 || b != 0) {
366- // `(a, b)` is the turned x-axis; a quarter turn lands it on an axis.
367- return match (a.signum(), b.signum()) {
368- (1, 0) => Rotation::None,
369- (-1, 0) => Rotation::Cw180,
370- (0, 1) => Rotation::Cw90,
371- (0, -1) => Rotation::Cw270,
372- _ => Rotation::Other { a, b, c, d },
373- };
374- }
375- Rotation::Other { a, b, c, d }
376- }
377-
378344 /// Quarter turns clockwise, where the stream is a quarter turn at all --
379345 /// `None` for anything [`Rotation::Other`] carries.
380346 pub fn steps(self) -> Option<u8> {
@@ -665,24 +631,7 @@ mod tests {
665631 }
666632
667633 #[test]
668- fn quarter_turn_matrices_read_as_typed_rotations() {
669- const ONE: i32 = 65_536; // 16.16 unity.
670- let cases = [
671- // A tkhd matrix and the turn it states, in this crate's clockwise
672- // convention. `(0, -1, 1, 0)` is what ffmpeg's
673- // `-display_rotation 90` writes: it asks the picture to be turned
674- // a quarter counter-clockwise here, which is Cw270.
675- ((ONE, 0, 0, ONE), Rotation::None),
676- ((0, -ONE, ONE, 0), Rotation::Cw270),
677- ((-ONE, 0, 0, -ONE), Rotation::Cw180),
678- ((0, ONE, -ONE, 0), Rotation::Cw90),
679- // A scaled identity is still no turn: the reading normalises by the
680- // matrix's own scale, so a differently-scaled copy reads the same.
681- ((2 * ONE, 0, 0, 2 * ONE), Rotation::None),
682- ];
683- for ((a, b, c, d), want) in cases {
684- assert_eq!(Rotation::from_matrix(a, b, c, d), want, "{a} {b} {c} {d}");
685- }
634+ fn quarter_turn_steps_and_axes() {
686635 assert_eq!(Rotation::None.steps(), Some(0));
687636 assert_eq!(Rotation::Cw90.steps(), Some(1));
688637 assert_eq!(Rotation::Cw180.steps(), Some(2));
@@ -692,57 +641,6 @@ mod tests {
692641 assert!(Rotation::None.is_none());
693642 }
694643
695- #[test]
696- fn a_matrix_that_is_not_a_quarter_turn_is_kept_not_rounded() {
697- const ONE: i32 = 65_536;
698- // A 45-degree turn: isotropic and pure, but no axis lands on an axis.
699- assert_eq!(
700- Rotation::from_matrix(46_340, -46_340, 46_340, 46_340),
701- Rotation::Other {
702- a: 46_340,
703- b: -46_340,
704- c: 46_340,
705- d: 46_340,
706- }
707- );
708- // A mirror (negative determinant), a mirror of a quarter turn (b != -c),
709- // a shear (a != d), and the degenerate all-zero matrix: none is a turn.
710- for (a, b, c, d) in [
711- (ONE, 0, 0, -ONE),
712- (0, ONE, ONE, 0),
713- (ONE, 0, ONE, ONE),
714- (0, 0, 0, 0),
715- ] {
716- let got = Rotation::from_matrix(a, b, c, d);
717- assert!(
718- matches!(got, Rotation::Other { .. }),
719- "{a} {b} {c} {d} read as {got:?}"
720- );
721- assert_eq!(got.steps(), None, "Other is not a quarter count");
722- }
723- }
724-
725- #[test]
726- fn a_matrix_term_at_i32_min_is_not_a_quarter_turn() {
727- // A crafted `tkhd` can carry `i32::MIN`, whose negation is not
728- // representable. `from_matrix` must not panic (debug) or wrap onto a
729- // false turn (release) deciding `b == -c`, and such a term is no
730- // quarter turn anyway. `(0, MIN, MIN, 0)` is the load-bearing case: the
731- // wrapping form would read it as `Cw270`.
732- for (a, b, c, d) in [
733- (0, i32::MIN, i32::MIN, 0),
734- (65_536, i32::MIN, i32::MIN, 65_536),
735- (i32::MIN, 0, i32::MIN, i32::MIN),
736- ] {
737- let got = Rotation::from_matrix(a, b, c, d);
738- assert!(
739- matches!(got, Rotation::Other { .. }),
740- "{a} {b} {c} {d} read as {got:?}"
741- );
742- assert_eq!(got.steps(), None, "Other is not a quarter count");
743- }
744- }
745-
746644 #[test]
747645 fn trait_objects_are_send() {
748646 fn assert_send<T: Send + ?Sized>() {}