lane-av1422lpf: fix the 4:2:2 lossless chroma extent family (7 sites)
Browse files at this commit4058fb3b0e3412b0fb60f88b3783b9b169caaf2cParent: 1766d691 changed file +134 -10
- crates/ec-av1/src/decode.rs +134 -10
crates/ec-av1/src/decode.rsmodified+134 -10
| @@ -37393,7 +37393,16 @@ fn read_intra_chroma_lossless( | |||
| 37393 | } else { | 37393 | } else { |
| 37394 | &mut *v_out | 37394 | &mut *v_out |
| 37395 | }, | 37395 | }, |
| 37396 | - stride * stride, | 37396 | + // lane-av1422lpf site 7: `stride * blk_h`, the intra twin |
| 37397 | + // of site 1. `read_intra_chroma_lossless`'s own | ||
| 37398 | + // `(blk_w, blk_h)` parameter is the block's whole CHROMA | ||
| 37399 | + // PLANE BLOCK, per-axis, and the walk below addresses up | ||
| 37400 | + // to row `org_y + reg_h - 1` at `stride` -- so the | ||
| 37401 | + // requirement is `stride * blk_h` and `stride * stride` | ||
| 37402 | + // underruns by exactly the ratio the plane block's height | ||
| 37403 | + // exceeds its width. Identical number at 4:2:0 | ||
| 37404 | + // (`blk_h == stride`) and 4:4:4. | ||
| 37405 | + stride * blk_h, | ||
| 37397 | ); | 37406 | ); |
| 37398 | for row in 0..4 { | 37407 | for row in 0..4 { |
| 37399 | let start = (oy + row) * stride + ox; | 37408 | let start = (oy + row) * stride + ox; |
| @@ -37557,7 +37566,29 @@ fn read_inter_chroma_lossless( | |||
| 37557 | } else { | 37566 | } else { |
| 37558 | &mut *v_out | 37567 | &mut *v_out |
| 37559 | }, | 37568 | }, |
| 37560 | - stride * stride, | 37569 | + // lane-av1422lpf site 1: `stride * blk_h`, NOT |
| 37570 | + // `stride * stride`. The composed `u_out`/`v_out` grid is | ||
| 37571 | + // the block's whole CHROMA PLANE BLOCK read at `stride`, | ||
| 37572 | + // and libaom's plane block is PER-AXIS | ||
| 37573 | + // (`(bw >> ss_x) x (bh >> ss_y)`, decodeframe.c's | ||
| 37574 | + // `dec->uv_buffer` extent) -- square only when | ||
| 37575 | + // `ss_x == ss_y`. The walk above addresses row | ||
| 37576 | + // `org_y + reg_h - 1` at column `org_x + reg_w`, and every | ||
| 37577 | + // call site passes a region that is a sub-rect of `blk` | ||
| 37578 | + // with `org` inside `blk`, so the requirement is exactly | ||
| 37579 | + // `stride * blk_h` (the last row's end | ||
| 37580 | + // `(blk_h - 1) * stride + blk_w` fits because | ||
| 37581 | + // `blk_w <= stride` at all nine call sites). | ||
| 37582 | + // | ||
| 37583 | + // Where the plane block IS square -- 4:2:0 (`side/2` both | ||
| 37584 | + // axes) and 4:4:4 (`side` both axes) on a square block -- | ||
| 37585 | + // `blk_h == stride` and this reduces to the old | ||
| 37586 | + // `stride * stride` verbatim, so it cannot move a byte | ||
| 37587 | + // there. It is not 4:2:2-only either: a 64x128 4:2:0 block | ||
| 37588 | + // has a 32x64 chroma plane block, and `ll420_a.obu` | ||
| 37589 | + // (`range end index 1028 out of range for slice of | ||
| 37590 | + // length 1024`) panicked on the old expression. | ||
| 37591 | + stride * blk_h, | ||
| 37561 | ); | 37592 | ); |
| 37562 | for row in 0..4 { | 37593 | for row in 0..4 { |
| 37563 | let start = (oy + row) * stride + ox; | 37594 | let start = (oy + row) * stride + ox; |
| @@ -39972,10 +40003,37 @@ fn decode_inter_block( | |||
| 39972 | Some(s) if s.has_chroma => { | 40003 | Some(s) if s.has_chroma => { |
| 39973 | // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 / | 40004 | // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 / |
| 39974 | // 4x16 (lane-av1-444; no pair at ss 0/0). | 40005 | // 4x16 (lane-av1-444; no pair at ss 0/0). |
| 40006 | + // | ||
| 40007 | + // lane-av1422lpf site 4: the VERT arm's third shape. A | ||
| 40008 | + // `PARTITION_VERT_4` strip is 4x16 luma and pairs on COLUMNS | ||
| 40009 | + // while `ss_x == 1` (`is_chroma_reference` on `mi_col` parity, | ||
| 40010 | + // av1_common_int.h:1454), so the pair is 8x16 luma -- and 4:2:2 | ||
| 40011 | + // subsamples X ONLY (`subsampling_x = 1, subsampling_y = 0`, | ||
| 40012 | + // spec 5.5.2's `color_config`), which leaves the pair's chroma | ||
| 40013 | + // plane block at 8>>1 x 16>>0 = **4x16**, twice as tall as the | ||
| 40014 | + // 4:2:0 pair's 4x8. The old `else` handed 4:2:2 the 4:2:0 shape, | ||
| 40015 | + // halving `write_chroma_h` for the WHOLE of `decode_inter_block` | ||
| 40016 | + // at ss (1,0) -- `chroma_stride`/`chroma_buf_h` at 40017 and so | ||
| 40017 | + // every prediction buffer, every grid and every mu-chunk replay | ||
| 40018 | + // below. Measured on `W_intrabc.obu` frame 1: a 4x16 vert strip | ||
| 40019 | + // got `chroma_stride = 4`, `chroma_buf_h = 8`, a 32-sample grid, | ||
| 40020 | + // and the lossless TX_4x4 replay's last unit row read index 64 of | ||
| 40021 | + // it (`range end index 36 out of range for slice of length 32` | ||
| 40022 | + // at the composed-grid read). | ||
| 40023 | + // | ||
| 40024 | + // The HORZ arm needs no third shape at 4:2:2 and gets none: a | ||
| 40025 | + // HORZ_4 strip pairs on ROWS only while `ss_y == 1`, and 4:2:2 | ||
| 40026 | + // has `ss_y == 0`, so each 16x4 strip is its own chroma reference | ||
| 40027 | + // and its own 8x4 chroma block -- the number `(8, 4)` already | ||
| 40028 | + // returns. At 4:2:0 (`ss_x == ss_y == 1`) the pair halves on both | ||
| 40029 | + // axes and at 4:4:4 there is no pair at all, so both of those | ||
| 40030 | + // arms are untouched by this line. | ||
| 39975 | if ss_x(fctx) == 0 && ss_y(fctx) == 0 { | 40031 | if ss_x(fctx) == 0 && ss_y(fctx) == 0 { |
| 39976 | if s.horz { (16, 4) } else { (4, 16) } | 40032 | if s.horz { (16, 4) } else { (4, 16) } |
| 39977 | } else if s.horz { | 40033 | } else if s.horz { |
| 39978 | (8, 4) | 40034 | (8, 4) |
| 40035 | + } else if ss_y(fctx) == 0 { | ||
| 40036 | + (4, 16) | ||
| 39979 | } else { | 40037 | } else { |
| 39980 | (4, 8) | 40038 | (4, 8) |
| 39981 | } | 40039 | } |
| @@ -41495,7 +41553,33 @@ fn decode_inter_block( | |||
| 41495 | (cc * chunk_chroma_w, cr * chunk_chroma_h), | 41553 | (cc * chunk_chroma_w, cr * chunk_chroma_h), |
| 41496 | (chunk_chroma_w, chunk_chroma_h), | 41554 | (chunk_chroma_w, chunk_chroma_h), |
| 41497 | (write_chroma_w, write_chroma_h), | 41555 | (write_chroma_w, write_chroma_h), |
| 41498 | - chroma_side, | 41556 | + // lane-av1422lpf site 5: the stride |
| 41557 | + // the walk indexes `su`/`sv` at is the | ||
| 41558 | + // PREDICTION BUFFER's own | ||
| 41559 | + // `chroma_stride` -- the same number | ||
| 41560 | + // `su`/`sv` were built at, and the one | ||
| 41561 | + // the composed `u_units`/`v_units` | ||
| 41562 | + // grid is sized and written at (site | ||
| 41563 | + // 1's `stride * blk_h`). `chroma_side` | ||
| 41564 | + // is the ENCLOSING SQUARE | ||
| 41565 | + // (`max(side >> ss_x, side >> ss_y)`) | ||
| 41566 | + // and at 4:2:2 it is the LUMA side: a | ||
| 41567 | + // 128x128 block's chroma plane block is | ||
| 41568 | + // 64x128, so the walk addressed | ||
| 41569 | + // `oy * 128 + ox` on a 64-wide, 8192- | ||
| 41570 | + // sample buffer and the last unit row | ||
| 41571 | + // ran off the end | ||
| 41572 | + // (`offset 8192 .. 8580 of 8192`, | ||
| 41573 | + // X_intrabc_tiled frame 1, at | ||
| 41574 | + // `push_mc_rect_tx`). | ||
| 41575 | + // | ||
| 41576 | + // At 4:2:0 `chroma_stride == | ||
| 41577 | + // chroma_side == side >> 1` and at | ||
| 41578 | + // 4:4:4 both are `side`, so this | ||
| 41579 | + // argument is the same number on every | ||
| 41580 | + // shape this decoder admits except | ||
| 41581 | + // 4:2:2. | ||
| 41582 | + chroma_stride, | ||
| 41499 | mode_for_tx, | 41583 | mode_for_tx, |
| 41500 | base_q_idx, | 41584 | base_q_idx, |
| 41501 | &mut u_units, | 41585 | &mut u_units, |
| @@ -43282,7 +43366,13 @@ fn decode_inter_block( | |||
| 43282 | (cc * chunk_chroma_w, cr * chunk_chroma_h), | 43366 | (cc * chunk_chroma_w, cr * chunk_chroma_h), |
| 43283 | (chunk_chroma_w, chunk_chroma_h), | 43367 | (chunk_chroma_w, chunk_chroma_h), |
| 43284 | (write_chroma_w, write_chroma_h), | 43368 | (write_chroma_w, write_chroma_h), |
| 43285 | - chroma_side, | 43369 | + // lane-av1422lpf site 5 (the compound |
| 43370 | + // twin of the single-reference fix at | ||
| 43371 | + // 41572): the prediction buffer's own | ||
| 43372 | + // `chroma_stride`, never the enclosing | ||
| 43373 | + // square `chroma_side`. Identical | ||
| 43374 | + // number at 4:2:0 and 4:4:4. | ||
| 43375 | + chroma_stride, | ||
| 43286 | mode_for_tx, | 43376 | mode_for_tx, |
| 43287 | base_q_idx, | 43377 | base_q_idx, |
| 43288 | &mut u_units, | 43378 | &mut u_units, |
| @@ -44257,10 +44347,21 @@ fn decode_inter_block( | |||
| 44257 | (px, py), | 44347 | (px, py), |
| 44258 | (cpx, cpy), | 44348 | (cpx, cpy), |
| 44259 | side, | 44349 | side, |
| 44260 | - (chroma_side, chroma_side), | 44350 | + // lane-av1422lpf site 6 (the intra-in-inter twin of |
| 44351 | + // site 5 at 41572): the plane block's own per-axis | ||
| 44352 | + // shape and stride, never the enclosing square. | ||
| 44353 | + // `palette_uv_bufs` is the decoded colour-index map | ||
| 44354 | + // at `(write_w >> ss_x, write_h >> ss_y)` (44144), | ||
| 44355 | + // i.e. per-axis already, and the lossless walk | ||
| 44356 | + // windows it at this `stride` -- at 4:2:2 a | ||
| 44357 | + // 16-wide square stride over an 8-wide map put the | ||
| 44358 | + // third unit row at index 180 of 128 samples | ||
| 44359 | + // (`palette_window`, decode.rs:2946; measured on | ||
| 44360 | + // `Y_intrabc_10b.obu`). | ||
| 44361 | + (chroma_stride, chroma_buf_h), | ||
| 44261 | (cc * chunk_chroma_w, cr * chunk_chroma_h), | 44362 | (cc * chunk_chroma_w, cr * chunk_chroma_h), |
| 44262 | (chunk_chroma_w, chunk_chroma_h), | 44363 | (chunk_chroma_w, chunk_chroma_h), |
| 44263 | - chroma_side, | 44364 | + chroma_stride, |
| 44264 | reach, | 44365 | reach, |
| 44265 | (y.width, y.height), | 44366 | (y.width, y.height), |
| 44266 | mode, | 44367 | mode, |
| @@ -44536,10 +44637,15 @@ fn decode_inter_block( | |||
| 44536 | (px, py), | 44637 | (px, py), |
| 44537 | (cpx, cpy), | 44638 | (cpx, cpy), |
| 44538 | side, | 44639 | side, |
| 44539 | - (chroma_side, chroma_side), | 44640 | + // lane-av1422lpf site 6 (the whole-block twin of the mu |
| 44641 | + // chunk fix at 44374): the plane block's own per-axis shape | ||
| 44642 | + // and its own stride, never the enclosing square | ||
| 44643 | + // `chroma_side`. At 4:2:0 and 4:4:4 all three are the same | ||
| 44644 | + // number. | ||
| 44645 | + (chroma_stride, chroma_buf_h), | ||
| 44540 | (0, 0), | 44646 | (0, 0), |
| 44541 | - (chroma_side, chroma_side), | 44647 | + (chroma_stride, chroma_buf_h), |
| 44542 | - chroma_side, | 44648 | + chroma_stride, |
| 44543 | reach, | 44649 | reach, |
| 44544 | (y.width, y.height), | 44650 | (y.width, y.height), |
| 44545 | mode, | 44651 | mode, |
| @@ -44994,7 +45100,25 @@ fn decode_inter_block( | |||
| 44994 | for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { | 45100 | for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { |
| 44995 | let mut unit = Vec::with_capacity(cu * cu); | 45101 | let mut unit = Vec::with_capacity(cu * cu); |
| 44996 | for rr in 0..cu { | 45102 | for rr in 0..cu { |
| 44997 | - let start = (cr * cu + rr) * chroma_side + cc * cu; | 45103 | + // lane-av1422lpf site 2: the composed grid this |
| 45104 | + // replays is the block's CHROMA PLANE BLOCK at | ||
| 45105 | + // `chroma_stride` -- the same per-axis stride | ||
| 45106 | + // site 1 sized `u_out`/`v_out` at and the same | ||
| 45107 | + // `read_inter_chroma_lossless` wrote them at | ||
| 45108 | + // (`src.offset(..)` + `(oy + row) * stride + ox`). | ||
| 45109 | + // `chroma_side` is the ENCLOSING SQUARE | ||
| 45110 | + // (`max(side >> ss_x, side >> ss_y)`), which is | ||
| 45111 | + // the plane block's own width only when | ||
| 45112 | + // `ss_x == ss_y`: at 4:2:2 it is the full luma | ||
| 45113 | + // side, twice a strip block's plane-block width, | ||
| 45114 | + // and the last unit row ran off the end | ||
| 45115 | + // (`range end index 68 out of range for slice of | ||
| 45116 | + // length 64`, W_intrabc frame 1). | ||
| 45117 | + // | ||
| 45118 | + // At 4:2:0 (`chroma_stride == chroma_side == | ||
| 45119 | + // side >> 1`) and 4:4:4 (`side`) the two are the | ||
| 45120 | + // same number and this line is unchanged. | ||
| 45121 | + let start = (cr * cu + rr) * chroma_stride + cc * cu; | ||
| 44998 | unit.extend_from_slice(&grid[start..start + cu]); | 45122 | unit.extend_from_slice(&grid[start..start + cu]); |
| 44999 | } | 45123 | } |
| 45000 | units.push(( | 45124 | units.push(( |