Clamp intra reference reads to the true edge even off a block's own row/col
Browse files at this commitdc2d88c55ef361321ded597efbeaf4f8b2af4345Parent: 01cb49b- fix
- clamp intra reference reads to the true edge even off a block's own row/col
1 changed file +24 -20
- crates/ec-av1/src/encode.rs +24 -20
crates/ec-av1/src/encode.rsmodified+24 -20
| @@ -506,30 +506,34 @@ impl Plane<'_> { | |||
| 506 | side: usize, | 506 | side: usize, |
| 507 | reach: Reach, | 507 | reach: Reach, |
| 508 | ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) { | 508 | ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) { |
| 509 | - // A block's own edge (no `reach`) reads samples reconstructed as part | 509 | + // Even a block's *own* edge is clamped to the true frame bound, not |
| 510 | - // of *some* legally-coded block, whole or not, even where that | 510 | + // just a `reach` extension: libaom's `av1_predict_intra_block` |
| 511 | - // block's own extent straddles the true frame edge -- `has_half` | 511 | + // (`av1/common/reconintra.c`) derives `xr`/`yd` -- the distance from |
| 512 | - // (spec `hasRows`/`hasCols`) lets a whole block stand there, and its | 512 | + // this block's own right/bottom to the frame edge -- from |
| 513 | - // full extent gets a real transform, not a garbage tail, so this | 513 | + // `mb_to_right_edge`/`mb_to_bottom_edge`, which are built from |
| 514 | - // reads no further than the padded coding surface. Only a `reach` | 514 | + // `mi_cols`/`mi_rows` (the true, decodable extent), never from any |
| 515 | - // extension crosses into a block that may never be coded at all past | 515 | + // padded coding surface. `n_top_px`/`n_left_px` (how many *real* |
| 516 | - // the true edge, so only it clamps to the true bound (`mi_cols`/ | 516 | + // samples the row/column above/left holds before the decoder starts |
| 517 | - // `mi_rows` * 4), replicating past it same as spec 7.11.2.2's | 517 | + // repeating the last one, same clamp as spec 7.11.2.2's `aboveLimit`/ |
| 518 | - // `aboveLimit`/`leftLimit` clamp. | 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)); | ||
| 519 | let across = if reach.above_right { | 524 | let across = if reach.above_right { |
| 520 | - (x + 2 * side) | 525 | + own_across + side.min(self.true_width.saturating_sub(own_across)) |
| 521 | - .min(self.width) | ||
| 522 | - .min(self.true_width.max(x + side)) | ||
| 523 | } else { | 526 | } else { |
| 524 | - (x + side).min(self.width) | 527 | + own_across |
| 525 | - }; | 528 | + } |
| 529 | + .min(self.width); | ||
| 530 | + let own_down = y + side.min(self.true_height.saturating_sub(y)); | ||
| 526 | let down = if reach.below_left { | 531 | let down = if reach.below_left { |
| 527 | - (y + 2 * side) | 532 | + own_down + side.min(self.true_height.saturating_sub(own_down)) |
| 528 | - .min(self.height) | ||
| 529 | - .min(self.true_height.max(y + side)) | ||
| 530 | } else { | 533 | } else { |
| 531 | - (y + side).min(self.height) | 534 | + own_down |
| 532 | - }; | 535 | + } |
| 536 | + .min(self.height); | ||
| 533 | // `across`/`down` can still fall at or below `x`/`y` for a sub-block | 537 | // `across`/`down` can still fall at or below `x`/`y` for a sub-block |
| 534 | // whose own origin already sits past the true edge -- only reachable | 538 | // whose own origin already sits past the true edge -- only reachable |
| 535 | // through a partition trial priced for comparison on a split this | 539 | // through a partition trial priced for comparison on a split this |