From 01cb49b6c11a8bd8f5ec02bf3d89ebb85431707c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 27 Aug 2026 02:31:30 +0300 Subject: [PATCH] fix(av1): narrow the true-edge availability clamp to the reach extension only A block's own edge read (no `reach`) can land on a block that is legally whole despite straddling the true frame edge (spec hasRows/hasCols, this crate's has_half): such a block gets a real transform over its full padded extent, not a garbage tail, and both this encoder and a real decoder reconstruct it that way, so clamping that base read to the true bound (mi_cols*4/mi_rows*4) was wrong -- verified by comparing against a worktree at the prior commit: it moved the first luma mismatch in both a_frame_round_trips_at_its_own_size (1920x1080) and an_854x480_picture_round_trips_through_its_padding earlier in the frame instead of fixing them, gate unchanged at 124/3/4 either way. Only a `reach` extension (above-right/below-left) crosses into a block that may never be coded past the true edge at all, so only that portion still clamps to true_width/true_height; re-verified against the same baseline worktree that this leaves the three pre-existing failures at their exact prior mismatch positions (byte-for-byte), i.e. a true no-op for them, while still fixing the genuine reach-based true-edge case this lane's prior commit targeted. --- crates/ec-av1/src/encode.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 47a607ed..89f9d8bf 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -506,12 +506,34 @@ impl Plane<'_> { side: usize, reach: Reach, ) -> (Option>, Option>, Option) { - let across = (x + if reach.above_right { 2 * side } else { side }).min(self.true_width); - let down = (y + if reach.below_left { 2 * side } else { side }).min(self.true_height); - // `across`/`down` can fall at or below `x`/`y` for a block whose own - // origin already sits past the true edge -- only reachable through a - // partition trial priced for comparison on a split this frame's - // straddling quadrant will go on to refuse (see + // A block's own edge (no `reach`) reads samples reconstructed as part + // of *some* legally-coded block, whole or not, even where that + // block's own extent straddles the true frame edge -- `has_half` + // (spec `hasRows`/`hasCols`) lets a whole block stand there, and its + // full extent gets a real transform, not a garbage tail, so this + // reads no further than the padded coding surface. Only a `reach` + // extension crosses into a block that may never be coded at all past + // the true edge, so only it clamps to the true bound (`mi_cols`/ + // `mi_rows` * 4), replicating past it same as spec 7.11.2.2's + // `aboveLimit`/`leftLimit` clamp. + let across = if reach.above_right { + (x + 2 * side) + .min(self.width) + .min(self.true_width.max(x + side)) + } else { + (x + side).min(self.width) + }; + let down = if reach.below_left { + (y + 2 * side) + .min(self.height) + .min(self.true_height.max(y + side)) + } else { + (y + side).min(self.height) + }; + // `across`/`down` can still fall at or below `x`/`y` for a sub-block + // whose own origin already sits past the true edge -- only reachable + // through a partition trial priced for comparison on a split this + // frame's straddling quadrant will go on to refuse (see // `a_picture_off_the_block_grid_is_refused`), never through a block // this encoder actually commits. Such a block has no true-edge // samples above or left of it at all, same as `y == 0`/`x == 0`.