forge
Explore
Log in

Don't you dare go Hollow

Clamp intra reference reads to the true edge even off a block's own row/col

Browse files at this commit

dc2d88c55ef361321ded597efbeaf4f8b2af4345Ahmet Kaan GümüşParent: 01cb49b
  • fix
    • clamp intra reference reads to the true edge even off a block's own row/col
Show full message
fix(av1): clamp intra reference reads to the true edge even off a block's own row/col

libaom's av1_predict_intra_block (av1/common/reconintra.c) derives xr/yd --
the distance from a block's own right/bottom to the frame edge -- from
mb_to_right_edge/mb_to_bottom_edge, which are built from mi_cols/mi_rows
(the true, decodable extent), never any padded coding surface. n_top_px/
n_left_px is min(side, xr + side) even for a block whose own extent
straddles that edge legally (has_half) -- prediction does not get real
reconstructed pixels past the true edge for its own row/column either,
only reach ever got that clamp before. Plane::edges() now clamps the
own-portion the same way libaom's xr/yd do.

Verified pixel-exact against aomdec on the 216x96 col-edge repro
(mi(8,48)) that was silently wrong before (0 diffs, previously untested).
Gate unchanged at 124/127 -- the remaining 3 reds (854x480, 1920x1080,
non-multiple-size sequence) trace to a separate, not-yet-isolated defect:
a uniform -3 luma offset across every straddling block in a column strip,
first appearing at mi_row=8 mi_col=208 in 854x480 with a nonzero DC
coefficient present, i.e. downstream of this fix (dequant/IDCT or mode
choice, not reference-sample availability).
crates/ec-av1/src/encode.rsmodified+24 -20
@@ -506,30 +506,34 @@ impl Plane<'_> {
506506 side: usize,
507507 reach: Reach,
508508 ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) {
509- // A block's own edge (no `reach`) reads samples reconstructed as part
510- // of *some* legally-coded block, whole or not, even where that
511- // block's own extent straddles the true frame edge -- `has_half`
512- // (spec `hasRows`/`hasCols`) lets a whole block stand there, and its
513- // full extent gets a real transform, not a garbage tail, so this
514- // reads no further than the padded coding surface. Only a `reach`
515- // extension crosses into a block that may never be coded at all past
516- // the true edge, so only it clamps to the true bound (`mi_cols`/
517- // `mi_rows` * 4), replicating past it same as spec 7.11.2.2's
518- // `aboveLimit`/`leftLimit` clamp.
509+ // Even a block's *own* edge is clamped to the true frame bound, not
510+ // just a `reach` extension: libaom's `av1_predict_intra_block`
511+ // (`av1/common/reconintra.c`) derives `xr`/`yd` -- the distance from
512+ // this block's own right/bottom to the frame edge -- from
513+ // `mb_to_right_edge`/`mb_to_bottom_edge`, which are built from
514+ // `mi_cols`/`mi_rows` (the true, decodable extent), never from any
515+ // padded coding surface. `n_top_px`/`n_left_px` (how many *real*
516+ // samples the row/column above/left holds before the decoder starts
517+ // repeating the last one, same clamp as spec 7.11.2.2's `aboveLimit`/
518+ // `leftLimit`) is `min(side, xr + side)` even for a block whose own
519+ // extent straddles that edge legally (`has_half`) -- the transform
520+ // still covers the whole block, but prediction does not get to read
521+ // real reconstructed pixels past the true edge for its own row/column,
522+ // only for the padded tail it invents.
523+ let own_across = x + side.min(self.true_width.saturating_sub(x));
519524 let across = if reach.above_right {
520- (x + 2 * side)
521- .min(self.width)
522- .min(self.true_width.max(x + side))
525+ own_across + side.min(self.true_width.saturating_sub(own_across))
523526 } else {
524- (x + side).min(self.width)
525- };
527+ own_across
528+ }
529+ .min(self.width);
530+ let own_down = y + side.min(self.true_height.saturating_sub(y));
526531 let down = if reach.below_left {
527- (y + 2 * side)
528- .min(self.height)
529- .min(self.true_height.max(y + side))
532+ own_down + side.min(self.true_height.saturating_sub(own_down))
530533 } else {
531- (y + side).min(self.height)
532- };
534+ own_down
535+ }
536+ .min(self.height);
533537 // `across`/`down` can still fall at or below `x`/`y` for a sub-block
534538 // whose own origin already sits past the true edge -- only reachable
535539 // through a partition trial priced for comparison on a split this