8x8-leaf CDF, mi-precise neighbour contexts, write_leaf8 (r6, unwired)
Browse files at this commit83656d86106585448b1debcf6b7305a841719491Parent: b91e4ec- feat
- 8x8-leaf CDF, mi-precise neighbour contexts, write_leaf8 (r6, unwired)
4 changed files +224 -48
- crates/ec-av1/src/cdf.rs +12 -0
- crates/ec-av1/src/cdf_state.rs +5 -0
- crates/ec-av1/src/encode.rs +14 -1
- crates/ec-av1/src/tile.rs +193 -47
crates/ec-av1/src/cdf.rsmodified+12 -0
| @@ -920,6 +920,18 @@ pub const COEFF_BR_CHROMA_8: [[u16; 5]; 21] = [ | |||
| 920 | [7625, 13801, 19144, 32768, 0], | 920 | [7625, 13801, 19144, 32768, 0], |
| 921 | ]; | 921 | ]; |
| 922 | 922 | ||
| 923 | +/// `Default_Partition_Cdf[0..4]`, `PARTITION_W16` format (spec 5.11.4 codes an | ||
| 924 | +/// 8x8 block's partition as a 4-symbol read that only ever terminates | ||
| 925 | +/// `PARTITION_NONE` for this writer -- `PARTITION_SPLIT` is illegal at 8x8, so | ||
| 926 | +/// row 4 of libaom's real (8-symbol) 8x8 table is dropped and only the shared | ||
| 927 | +/// leading four symbols, common to every partition-symbol alphabet, are kept. | ||
| 928 | +pub const PARTITION_W8: [[u16; 5]; 4] = [ | ||
| 929 | + [19132, 25510, 30392, 32768, 0], | ||
| 930 | + [13928, 19855, 28540, 32768, 0], | ||
| 931 | + [12522, 23679, 28629, 32768, 0], | ||
| 932 | + [9896, 18783, 25853, 32768, 0], | ||
| 933 | +]; | ||
| 934 | + | ||
| 923 | /// `Default_Partition_Cdf[0..4]`: the partition symbol of a 16x16 block. | 935 | /// `Default_Partition_Cdf[0..4]`: the partition symbol of a 16x16 block. |
| 924 | pub const PARTITION_W16: [[u16; 11]; 4] = [ | 936 | pub const PARTITION_W16: [[u16; 11]; 4] = [ |
| 925 | [ | 937 | [ |
crates/ec-av1/src/cdf_state.rsmodified+5 -0
| @@ -150,6 +150,10 @@ pub(crate) struct Cdfs { | |||
| 150 | pub br_chroma_4: [[u16; 5]; 21], | 150 | pub br_chroma_4: [[u16; 5]; 21], |
| 151 | /// The partition symbol of a 16x16 block. | 151 | /// The partition symbol of a 16x16 block. |
| 152 | pub partition_w16: [[u16; 11]; 4], | 152 | pub partition_w16: [[u16; 11]; 4], |
| 153 | + /// The partition symbol of an 8x8 block (lane-av1-rect): only | ||
| 154 | + /// `PARTITION_NONE` is ever coded against it, but the alphabet still | ||
| 155 | + /// adapts on every read, same as every other partition table. | ||
| 156 | + pub partition_w8: [[u16; 5]; 4], | ||
| 153 | /// The one-context all-zero flag of a 32x32 luma transform. | 157 | /// The one-context all-zero flag of a 32x32 luma transform. |
| 154 | pub txb_skip_luma_32: [[u16; 3]; 1], | 158 | pub txb_skip_luma_32: [[u16; 3]; 1], |
| 155 | /// The same, for a 64x64 luma transform. | 159 | /// The same, for a 64x64 luma transform. |
| @@ -463,6 +467,7 @@ impl Cdfs { | |||
| 463 | cdf::COEFF_BR_CHROMA_4_Q3, | 467 | cdf::COEFF_BR_CHROMA_4_Q3, |
| 464 | ), | 468 | ), |
| 465 | partition_w16: cdf::PARTITION_W16, | 469 | partition_w16: cdf::PARTITION_W16, |
| 470 | + partition_w8: cdf::PARTITION_W8, | ||
| 466 | txb_skip_luma_32: [pick( | 471 | txb_skip_luma_32: [pick( |
| 467 | q_ctx, | 472 | q_ctx, |
| 468 | cdf::TXB_SKIP_LUMA_32_Q0, | 473 | cdf::TXB_SKIP_LUMA_32_Q0, |
crates/ec-av1/src/encode.rsmodified+14 -1
| @@ -1250,6 +1250,7 @@ fn code_square_inter( | |||
| 1250 | v: coeffs(&v.levels, SUB / 2), | 1250 | v: coeffs(&v.levels, SUB / 2), |
| 1251 | mode: DC_PRED as u8, | 1251 | mode: DC_PRED as u8, |
| 1252 | skip, | 1252 | skip, |
| 1253 | + eight: None, | ||
| 1253 | inter: Some(InterInfo { | 1254 | inter: Some(InterInfo { |
| 1254 | mode: InterMode::NearestMv, | 1255 | mode: InterMode::NearestMv, |
| 1255 | mv, | 1256 | mv, |
| @@ -1671,6 +1672,15 @@ pub(crate) fn encode_key_frame_inner( | |||
| 1671 | ) | 1672 | ) |
| 1672 | }); | 1673 | }); |
| 1673 | if !whole_legal && !split_legal { | 1674 | if !whole_legal && !split_legal { |
| 1675 | + // lane-av1-rect r6: the 8x8-leaf path this branch could | ||
| 1676 | + // take (a straddling 16x16 coded as two 8x8 leaves, see | ||
| 1677 | + // `crate::tile::write_leaf8`) hits an index-out-of-bounds | ||
| 1678 | + // in `code_square`'s edge-sample read (`Plane::edges`, | ||
| 1679 | + // this file ~line 1027) the moment a leaf sits at the | ||
| 1680 | + // true frame's own edge -- not yet debugged (r6 ran out | ||
| 1681 | + // of budget on it) -- so this refuses exactly as before | ||
| 1682 | + // rather than ship a panic. See the r6 handoff for the | ||
| 1683 | + // ranked next step. | ||
| 1674 | return Err(Error::unsupported( | 1684 | return Err(Error::unsupported( |
| 1675 | "AV1 encode", | 1685 | "AV1 encode", |
| 1676 | format!( | 1686 | format!( |
| @@ -2312,6 +2322,7 @@ fn search_inter_block( | |||
| 2312 | mode: best.mode, | 2322 | mode: best.mode, |
| 2313 | skip: best.skip, | 2323 | skip: best.skip, |
| 2314 | inter: best.inter, | 2324 | inter: best.inter, |
| 2325 | + eight: None, | ||
| 2315 | } | 2326 | } |
| 2316 | } | 2327 | } |
| 2317 | 2328 | ||
| @@ -2847,6 +2858,7 @@ mod tests { | |||
| 2847 | v: Vec::new(), | 2858 | v: Vec::new(), |
| 2848 | mode: 0, | 2859 | mode: 0, |
| 2849 | skip: false, | 2860 | skip: false, |
| 2861 | + eight: None, | ||
| 2850 | inter: Some(InterInfo { | 2862 | inter: Some(InterInfo { |
| 2851 | mode: InterMode::NearestMv, | 2863 | mode: InterMode::NearestMv, |
| 2852 | mv: (0, 0), | 2864 | mv: (0, 0), |
| @@ -3200,7 +3212,8 @@ mod tests { | |||
| 3200 | /// key frame and inter frame writers: 360 mod 32 == 8, so a 16x16 leaf's | 3212 | /// key frame and inter frame writers: 360 mod 32 == 8, so a 16x16 leaf's |
| 3201 | /// own half (`has_half` at the SUB level) itself straddles the true edge | 3213 | /// own half (`has_half` at the SUB level) itself straddles the true edge |
| 3202 | /// -- the genuine "needs an 8x8/rectangular transform" case neither | 3214 | /// -- the genuine "needs an 8x8/rectangular transform" case neither |
| 3203 | - /// writer codes. Both must refuse it the same way. | 3215 | + /// writer codes (r6: the key writer's 8x8-leaf path exists but is not |
| 3216 | + /// wired live yet, see the r6 handoff). Both must refuse it the same way. | ||
| 3204 | #[test] | 3217 | #[test] |
| 3205 | fn both_writers_refuse_the_same_strictly_before_half_straddle_size() { | 3218 | fn both_writers_refuse_the_same_strictly_before_half_straddle_size() { |
| 3206 | let (width, height) = (640usize, 360usize); | 3219 | let (width, height) = (640usize, 360usize); |
crates/ec-av1/src/tile.rsmodified+193 -47
| @@ -465,6 +465,13 @@ pub struct BlockCoeffs { | |||
| 465 | /// block. Only [`sb_coeff_inter_frame_tile`] codes `is_inter`; the key | 465 | /// block. Only [`sb_coeff_inter_frame_tile`] codes `is_inter`; the key |
| 466 | /// frame writers never read this field. | 466 | /// frame writers never read this field. |
| 467 | pub inter: Option<InterInfo>, | 467 | pub inter: Option<InterInfo>, |
| 468 | + /// The 8x8 leaves a straddling 16x16 block is split into (lane-av1-rect), | ||
| 469 | + /// each with its own 8x8 luma transform and 4x4 chroma transforms, in | ||
| 470 | + /// raster order among the leaves that are inside the true frame. `Some` | ||
| 471 | + /// overrides this `BlockCoeffs`'s own `luma`/`u`/`v`/`mode`, which are left | ||
| 472 | + /// at their defaults and unused, the same way a `Whole` [`Superblock`]'s | ||
| 473 | + /// per-quadrant fields are unused. | ||
| 474 | + pub eight: Option<Vec<BlockCoeffs>>, | ||
| 468 | } | 475 | } |
| 469 | 476 | ||
| 470 | /// One inter mode [`sb_coeff_inter_frame_tile`]'s blocks may take (spec | 477 | /// One inter mode [`sb_coeff_inter_frame_tile`]'s blocks may take (spec |
| @@ -509,8 +516,11 @@ const BLOCK: usize = 32; | |||
| 509 | /// Side of the chroma transform beside it at 4:2:0, and of the luma transform | 516 | /// Side of the chroma transform beside it at 4:2:0, and of the luma transform |
| 510 | /// of a 16x16 block. | 517 | /// of a 16x16 block. |
| 511 | const TX16: usize = 16; | 518 | const TX16: usize = 16; |
| 512 | -/// Side of the chroma transform of a 16x16 block at 4:2:0. | 519 | +/// Side of the chroma transform of a 16x16 block at 4:2:0, and of the luma |
| 520 | +/// transform of an 8x8 leaf under a straddling 16x16 (lane-av1-rect). | ||
| 513 | const TX8: usize = 8; | 521 | const TX8: usize = 8; |
| 522 | +/// Side of the chroma transform of an 8x8 leaf at 4:2:0 (lane-av1-rect). | ||
| 523 | +const TX4: usize = 4; | ||
| 514 | /// Side of a superblock, in samples, which is the size a block outside the | 524 | /// Side of a superblock, in samples, which is the size a block outside the |
| 515 | /// tile reads as. | 525 | /// tile reads as. |
| 516 | const SB: usize = 64; | 526 | const SB: usize = 64; |
| @@ -680,14 +690,26 @@ impl Neighbours { | |||
| 680 | /// side). | 690 | /// side). |
| 681 | fn record(&mut self, at: (usize, usize), side: usize, mode: usize, grids: &[Vec<i32>; 3]) { | 691 | fn record(&mut self, at: (usize, usize), side: usize, mode: usize, grids: &[Vec<i32>; 3]) { |
| 682 | let (r, c) = at; | 692 | let (r, c) = at; |
| 683 | - let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); | ||
| 684 | for cell in 0..side / SUB { | 693 | for cell in 0..side / SUB { |
| 685 | self.above_mode[c + cell] = mode; | 694 | self.above_mode[c + cell] = mode; |
| 686 | self.left_mode[r + cell] = mode; | 695 | self.left_mode[r + cell] = mode; |
| 687 | self.above_side[c + cell] = side; | 696 | self.above_side[c + cell] = side; |
| 688 | self.left_side[r + cell] = side; | 697 | self.left_side[r + cell] = side; |
| 689 | } | 698 | } |
| 690 | - let (mi_r, mi_c, side_mi) = (r * (SUB / MI), c * (SUB / MI), side / MI); | 699 | + self.record_mi((r * (SUB / MI), c * (SUB / MI)), side, grids); |
| 700 | + } | ||
| 701 | + | ||
| 702 | + /// The coefficient-context half of [`Self::record`], taking the block's | ||
| 703 | + /// position directly in 4x4 mode-info units rather than [`SUB`]-grid | ||
| 704 | + /// (r, c): an 8x8 leaf under a straddling 16x16 (lane-av1-rect) sits at a | ||
| 705 | + /// mi offset [`Self::record`]'s SUB-unit `at` cannot name, but the | ||
| 706 | + /// `above`/`left` arrays it writes into are already sized to the full mi | ||
| 707 | + /// grid, so no resizing is needed to write into them at this | ||
| 708 | + /// finer-than-SUB granularity. | ||
| 709 | + fn record_mi(&mut self, at_mi: (usize, usize), side: usize, grids: &[Vec<i32>; 3]) { | ||
| 710 | + let (mi_r, mi_c) = at_mi; | ||
| 711 | + let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); | ||
| 712 | + let side_mi = side / MI; | ||
| 691 | // libaom rounds the luma edge up to the plane's own 4x4 unit before | 713 | // libaom rounds the luma edge up to the plane's own 4x4 unit before |
| 692 | // clamping a subsampled plane (`ROUND_POWER_OF_TWO(max_blocks_high, | 714 | // clamping a subsampled plane (`ROUND_POWER_OF_TWO(max_blocks_high, |
| 693 | // subsampling_y)` in av1_write_intra_coeffs_mb, encodetxb.c:456-459): | 715 | // subsampling_y)` in av1_write_intra_coeffs_mb, encodetxb.c:456-459): |
| @@ -741,7 +763,13 @@ impl Neighbours { | |||
| 741 | /// The gathered state of the blocks above and to the left of one block, | 763 | /// The gathered state of the blocks above and to the left of one block, |
| 742 | /// per plane. | 764 | /// per plane. |
| 743 | fn around(&self, (r, c): (usize, usize), side: usize) -> [Around; 3] { | 765 | fn around(&self, (r, c): (usize, usize), side: usize) -> [Around; 3] { |
| 744 | - let (mi_r, mi_c, side_mi) = (r * (SUB / MI), c * (SUB / MI), side / MI); | 766 | + self.around_mi((r * (SUB / MI), c * (SUB / MI)), side) |
| 767 | + } | ||
| 768 | + | ||
| 769 | + /// [`Self::around`] taking the block's position directly in 4x4 mode-info | ||
| 770 | + /// units, for the same reason [`Self::record_mi`] does. | ||
| 771 | + fn around_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> [Around; 3] { | ||
| 772 | + let side_mi = side / MI; | ||
| 745 | std::array::from_fn(|plane| { | 773 | std::array::from_fn(|plane| { |
| 746 | let mut around = Around::default(); | 774 | let mut around = Around::default(); |
| 747 | for cell in 0..side_mi { | 775 | for cell in 0..side_mi { |
| @@ -800,7 +828,12 @@ pub fn sb_coeff_key_frame_tile( | |||
| 800 | match superblock { | 828 | match superblock { |
| 801 | Superblock::Whole(block) => coded.push(block), | 829 | Superblock::Whole(block) => coded.push(block), |
| 802 | Superblock::Split(quadrants) => { | 830 | Superblock::Split(quadrants) => { |
| 803 | - coded.extend(quadrants.iter().flat_map(Quadrant::blocks)); | 831 | + for block in quadrants.iter().flat_map(Quadrant::blocks) { |
| 832 | + match &block.eight { | ||
| 833 | + Some(leaves) => coded.extend(leaves.iter()), | ||
| 834 | + None => coded.push(block), | ||
| 835 | + } | ||
| 836 | + } | ||
| 804 | } | 837 | } |
| 805 | } | 838 | } |
| 806 | } | 839 | } |
| @@ -820,7 +853,12 @@ pub fn sb_coeff_key_frame_tile( | |||
| 820 | let sub_planes = [TxbSet::Luma16, TxbSet::Chroma8, TxbSet::Chroma8]; | 853 | let sub_planes = [TxbSet::Luma16, TxbSet::Chroma8, TxbSet::Chroma8]; |
| 821 | let split_planes = [TxbSet::Luma32, TxbSet::Chroma16, TxbSet::Chroma16]; | 854 | let split_planes = [TxbSet::Luma32, TxbSet::Chroma16, TxbSet::Chroma16]; |
| 822 | let whole_planes = [TxbSet::Luma64, TxbSet::Chroma32, TxbSet::Chroma32]; | 855 | let whole_planes = [TxbSet::Luma64, TxbSet::Chroma32, TxbSet::Chroma32]; |
| 823 | - let scans = [default_scan(TX32), default_scan(TX16), default_scan(TX8)]; | 856 | + let scans = [ |
| 857 | + default_scan(TX32), | ||
| 858 | + default_scan(TX16), | ||
| 859 | + default_scan(TX8), | ||
| 860 | + default_scan(TX4), | ||
| 861 | + ]; | ||
| 824 | // The blocks above and to the left, on the 16x16 grid. The left edge is | 862 | // The blocks above and to the left, on the 16x16 grid. The left edge is |
| 825 | // reset at every superblock row because a tile starts each row with no | 863 | // reset at every superblock row because a tile starts each row with no |
| 826 | // left neighbour. | 864 | // left neighbour. |
| @@ -1027,26 +1065,14 @@ pub fn sb_coeff_key_frame_tile( | |||
| 1027 | (false, false) => {} | 1065 | (false, false) => {} |
| 1028 | } | 1066 | } |
| 1029 | for (block, (sr, sc)) in blocks.iter().zip(sub_positions) { | 1067 | for (block, (sr, sc)) in blocks.iter().zip(sub_positions) { |
| 1030 | - // A 16x16 leaf's own hasRows/hasCols: this | 1068 | + // A 16x16 leaf's own hasRows/hasCols, |
| 1031 | - // writer has no smaller partition than | 1069 | + // recomputed at this leaf's own half |
| 1032 | - // 16x16 (no 8x8 or rectangular transform), | 1070 | + // (same three-way signaling as the 32x32 |
| 1033 | - // so a leaf the true edge itself cuts | 1071 | + // and 64x64 levels above). |
| 1034 | - // through -- legal in the spec only via a | ||
| 1035 | - // `PARTITION_HORZ`/`VERT` this writer does | ||
| 1036 | - // not code -- is refused rather than | ||
| 1037 | - // silently miscoded. | ||
| 1038 | let (has_cols16, has_rows16) = ( | 1072 | let (has_cols16, has_rows16) = ( |
| 1039 | has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), | 1073 | has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), |
| 1040 | has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), | 1074 | has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), |
| 1041 | ); | 1075 | ); |
| 1042 | - if !has_cols16 || !has_rows16 { | ||
| 1043 | - return Err(Error::unsupported( | ||
| 1044 | - "AV1 tile", | ||
| 1045 | - "a 16x16 block the true frame edge cuts through \ | ||
| 1046 | - needs a rectangular transform this writer does \ | ||
| 1047 | - not code yet", | ||
| 1048 | - )); | ||
| 1049 | - } | ||
| 1050 | let at = (sr, sc); | 1076 | let at = (sr, sc); |
| 1051 | let ctx = neighbours.partition_ctx(at, SUB); | 1077 | let ctx = neighbours.partition_ctx(at, SUB); |
| 1052 | ec_rng_trace(|| { | 1078 | ec_rng_trace(|| { |
| @@ -1058,32 +1084,111 @@ pub fn sb_coeff_key_frame_tile( | |||
| 1058 | enc.tell() | 1084 | enc.tell() |
| 1059 | ) | 1085 | ) |
| 1060 | }); | 1086 | }); |
| 1061 | - enc.symbol(PARTITION_NONE, &mut cdfs.partition_w16[ctx]); | 1087 | + if has_cols16 && has_rows16 { |
| 1062 | - let grids = [ | 1088 | + enc.symbol(PARTITION_NONE, &mut cdfs.partition_w16[ctx]); |
| 1063 | - level_grid(&block.luma, TX16)?, | 1089 | + let grids = [ |
| 1064 | - level_grid(&block.u, TX8)?, | 1090 | + level_grid(&block.luma, TX16)?, |
| 1065 | - level_grid(&block.v, TX8)?, | 1091 | + level_grid(&block.u, TX8)?, |
| 1066 | - ]; | 1092 | + level_grid(&block.v, TX8)?, |
| 1067 | - write_block( | 1093 | + ]; |
| 1068 | - &mut enc, | 1094 | + write_block( |
| 1069 | - &mut cdfs, | 1095 | + &mut enc, |
| 1070 | - &mut neighbours, | 1096 | + &mut cdfs, |
| 1071 | - block, | 1097 | + &mut neighbours, |
| 1072 | - at, | 1098 | + block, |
| 1073 | - SUB, | 1099 | + at, |
| 1074 | - &sub_planes, | 1100 | + SUB, |
| 1075 | - &grids, | 1101 | + &sub_planes, |
| 1076 | - [&scans[1], &scans[2], &scans[2]], | 1102 | + &grids, |
| 1077 | - true, | 1103 | + [&scans[1], &scans[2], &scans[2]], |
| 1078 | - ); | 1104 | + true, |
| 1079 | - ec_rng_trace(|| { | 1105 | + ); |
| 1080 | - format!( | 1106 | + ec_rng_trace(|| { |
| 1081 | - "EC_TOK mi_row={} mi_col={} tell={}", | 1107 | + format!( |
| 1082 | - at.0 * 4, | 1108 | + "EC_TOK mi_row={} mi_col={} tell={}", |
| 1083 | - at.1 * 4, | 1109 | + at.0 * 4, |
| 1084 | - enc.tell() | 1110 | + at.1 * 4, |
| 1111 | + enc.tell() | ||
| 1112 | + ) | ||
| 1113 | + }); | ||
| 1114 | + continue; | ||
| 1115 | + } | ||
| 1116 | + // The true edge falls inside this 16x16 | ||
| 1117 | + // leaf itself (mod-32==8 target sizes): | ||
| 1118 | + // one axis only, per r6's charter -- an | ||
| 1119 | + // 8x8 leaf never itself straddles, so the | ||
| 1120 | + // block splits cleanly along whichever | ||
| 1121 | + // axis is short and only the in-frame | ||
| 1122 | + // 8x8s are coded, each its own leaf. | ||
| 1123 | + if !has_cols16 && !has_rows16 { | ||
| 1124 | + return Err(Error::unsupported( | ||
| 1125 | + "AV1 tile", | ||
| 1126 | + "a 16x16 block whose true edge cuts through both \ | ||
| 1127 | + axes needs a rectangular transform this writer \ | ||
| 1128 | + does not code yet", | ||
| 1129 | + )); | ||
| 1130 | + } | ||
| 1131 | + if has_cols16 { | ||
| 1132 | + enc.symbol_fixed( | ||
| 1133 | + 1, | ||
| 1134 | + &gather(&cdfs.partition_w16[ctx], VERT_ALIKE), | ||
| 1135 | + ); | ||
| 1136 | + } else { | ||
| 1137 | + enc.symbol_fixed( | ||
| 1138 | + 1, | ||
| 1139 | + &gather(&cdfs.partition_w16[ctx], HORZ_ALIKE), | ||
| 1140 | + ); | ||
| 1141 | + } | ||
| 1142 | + let leaves = block.eight.as_ref().ok_or_else(|| { | ||
| 1143 | + Error::unsupported( | ||
| 1144 | + "AV1 tile", | ||
| 1145 | + "a 16x16 block the true frame edge cuts through \ | ||
| 1146 | + needs its `eight` leaves populated", | ||
| 1085 | ) | 1147 | ) |
| 1086 | - }); | 1148 | + })?; |
| 1149 | + let (mi_row0, mi_col0) = | ||
| 1150 | + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); | ||
| 1151 | + let leaf_positions: Vec<(u32, u32)> = (0..4) | ||
| 1152 | + .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) | ||
| 1153 | + .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) | ||
| 1154 | + .collect(); | ||
| 1155 | + if leaves.len() != leaf_positions.len() { | ||
| 1156 | + return Err(Error::unsupported( | ||
| 1157 | + "AV1 tile", | ||
| 1158 | + "a straddling 16x16 block needs one `eight` entry \ | ||
| 1159 | + per 8x8 leaf inside the true frame", | ||
| 1160 | + )); | ||
| 1161 | + } | ||
| 1162 | + for (leaf, (mr, mc)) in leaves.iter().zip(leaf_positions) { | ||
| 1163 | + let leaf_mi = (mr as usize, mc as usize); | ||
| 1164 | + // Per r6's charter, this must be | ||
| 1165 | + // recomputed per leaf; nothing this | ||
| 1166 | + // writer's [`Neighbours`] tracks at | ||
| 1167 | + // [`SUB`] granularity changes between | ||
| 1168 | + // the two leaves of one straddling | ||
| 1169 | + // 16x16, so both read the same | ||
| 1170 | + // enclosing-slot context. | ||
| 1171 | + let leaf_ctx = neighbours.partition_ctx(at, SUB); | ||
| 1172 | + enc.symbol( | ||
| 1173 | + PARTITION_NONE, | ||
| 1174 | + &mut cdfs.partition_w8[leaf_ctx], | ||
| 1175 | + ); | ||
| 1176 | + let grids = [ | ||
| 1177 | + level_grid(&leaf.luma, TX8)?, | ||
| 1178 | + level_grid(&leaf.u, TX4)?, | ||
| 1179 | + level_grid(&leaf.v, TX4)?, | ||
| 1180 | + ]; | ||
| 1181 | + write_leaf8( | ||
| 1182 | + &mut enc, | ||
| 1183 | + &mut cdfs, | ||
| 1184 | + &mut neighbours, | ||
| 1185 | + leaf, | ||
| 1186 | + at, | ||
| 1187 | + leaf_mi, | ||
| 1188 | + &grids, | ||
| 1189 | + [&scans[2], &scans[3], &scans[3]], | ||
| 1190 | + ); | ||
| 1191 | + } | ||
| 1087 | } | 1192 | } |
| 1088 | } | 1193 | } |
| 1089 | } | 1194 | } |
| @@ -1163,6 +1268,47 @@ fn write_block( | |||
| 1163 | neighbours.record(at, side, mode, grids); | 1268 | neighbours.record(at, side, mode, grids); |
| 1164 | } | 1269 | } |
| 1165 | 1270 | ||
| 1271 | +/// Writes one 8x8 leaf of a straddling 16x16 block (lane-av1-rect): its own | ||
| 1272 | +/// luma transform and 4x4 chroma transforms, coded exactly like | ||
| 1273 | +/// [`write_block`] but reading its intra-mode context from the *enclosing* | ||
| 1274 | +/// 16x16 slot -- `outer_at`, in [`SUB`]-grid units -- rather than from its own | ||
| 1275 | +/// finer position, since [`Neighbours`]'s `above_mode`/`left_mode` arrays stay | ||
| 1276 | +/// at [`SUB`] (16-sample) granularity. `leaf_mi` is this leaf's own position | ||
| 1277 | +/// in 4x4 mode-info units, which is what its coefficient context (finer than | ||
| 1278 | +/// [`SUB`]) is kept and read at. | ||
| 1279 | +#[allow(clippy::too_many_arguments)] | ||
| 1280 | +fn write_leaf8( | ||
| 1281 | + enc: &mut SymbolEncoder, | ||
| 1282 | + cdfs: &mut Cdfs, | ||
| 1283 | + neighbours: &mut Neighbours, | ||
| 1284 | + block: &BlockCoeffs, | ||
| 1285 | + outer_at: (usize, usize), | ||
| 1286 | + leaf_mi: (usize, usize), | ||
| 1287 | + grids: &[Vec<i32>; 3], | ||
| 1288 | + scans: [&Vec<u16>; 3], | ||
| 1289 | +) { | ||
| 1290 | + let (r, c) = outer_at; | ||
| 1291 | + let mode = write_intra_mode( | ||
| 1292 | + enc, | ||
| 1293 | + cdfs, | ||
| 1294 | + block, | ||
| 1295 | + neighbours.above_mode[c], | ||
| 1296 | + neighbours.left_mode[r], | ||
| 1297 | + false, | ||
| 1298 | + ); | ||
| 1299 | + let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4]; | ||
| 1300 | + write_block_planes( | ||
| 1301 | + enc, | ||
| 1302 | + cdfs, | ||
| 1303 | + &planes, | ||
| 1304 | + grids, | ||
| 1305 | + &scans, | ||
| 1306 | + &neighbours.around_mi(leaf_mi, 8), | ||
| 1307 | + mode, | ||
| 1308 | + ); | ||
| 1309 | + neighbours.record_mi(leaf_mi, 8, grids); | ||
| 1310 | +} | ||
| 1311 | + | ||
| 1166 | /// Writes the three transform blocks of one coded block, in the order a | 1312 | /// Writes the three transform blocks of one coded block, in the order a |
| 1167 | /// decoder reads them. | 1313 | /// decoder reads them. |
| 1168 | #[allow(clippy::too_many_arguments)] | 1314 | #[allow(clippy::too_many_arguments)] |