Wire read_lr into both SB loops
Browse files at this commitdc215f73dd0570ea92b2ffa15af5e21cd62c0e72Parent: 4c75e5c- feat
- wire read_lr into both SB loops
- narrow the whole-frame LR refusal to 'filters not applied'
2 changed files +43 -2
crates/ec-av1/src/decode.rsmodified+35 -1
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | //! too). Anything outside that refuses with [`Error::unsupported`] rather than |
| 22 | 22 | //! silently miscoding. |
| 23 | 23 | |
| 24 | -use ec_av1_syntax::{CdefParams, LoopFilterParams}; | |
| 24 | +use ec_av1_syntax::{CdefParams, LoopFilterParams, LoopRestorationParams}; | |
| 25 | 25 | use ec_core::{Error, Result}; |
| 26 | 26 | |
| 27 | 27 | use crate::cdf; |
| @@ -4458,6 +4458,7 @@ pub fn decode_key_frame_tile( | ||
| 4458 | 4458 | false, |
| 4459 | 4459 | cdef, |
| 4460 | 4460 | loop_filter, |
| 4461 | + &LoopRestorationParams::default(), | |
| 4461 | 4462 | None, |
| 4462 | 4463 | tx_select, |
| 4463 | 4464 | reduced_tx_set, |
| @@ -4486,6 +4487,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 4486 | 4487 | enable_edge_filter: bool, |
| 4487 | 4488 | cdef: &CdefParams, |
| 4488 | 4489 | loop_filter: &LoopFilterParams, |
| 4490 | + lr: &LoopRestorationParams, | |
| 4489 | 4491 | initial_cdfs: Option<Cdfs>, |
| 4490 | 4492 | tx_select: bool, |
| 4491 | 4493 | reduced_tx_set: bool, |
| @@ -4543,10 +4545,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 4543 | 4545 | mi_cols as usize, |
| 4544 | 4546 | mi_rows as usize, |
| 4545 | 4547 | ); |
| 4548 | + let mut lr_grid = crate::restoration::RestorationGrid::new(lr, frame_width, frame_height); | |
| 4549 | + let mut lr_reference = [( | |
| 4550 | + crate::restoration::WienerInfo::default(), | |
| 4551 | + crate::restoration::SgrprojInfo::default(), | |
| 4552 | + ); 3]; | |
| 4546 | 4553 | |
| 4547 | 4554 | for sb_r in 0..sb_rows { |
| 4548 | 4555 | neighbours.start_row(); |
| 4549 | 4556 | for sb_c in 0..sb_cols { |
| 4557 | + crate::restoration::read_lr( | |
| 4558 | + &mut dec, | |
| 4559 | + &mut cdfs, | |
| 4560 | + lr, | |
| 4561 | + &mut lr_grid, | |
| 4562 | + &mut lr_reference, | |
| 4563 | + sb_r * SB_MI, | |
| 4564 | + sb_c * SB_MI, | |
| 4565 | + SB_MI, | |
| 4566 | + ); | |
| 4550 | 4567 | let at = (sb_r as usize * 4, sb_c as usize * 4); |
| 4551 | 4568 | let ctx = neighbours.partition_ctx(at, SB); |
| 4552 | 4569 | let (has_cols, has_rows) = ( |
| @@ -9055,6 +9072,7 @@ pub fn decode_inter_frame_tile( | ||
| 9055 | 9072 | other_refs, |
| 9056 | 9073 | cdef, |
| 9057 | 9074 | loop_filter, |
| 9075 | + &LoopRestorationParams::default(), | |
| 9058 | 9076 | None, |
| 9059 | 9077 | allow_high_precision_mv, |
| 9060 | 9078 | force_integer_mv, |
| @@ -9096,6 +9114,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9096 | 9114 | other_refs: [Option<&Picture>; 8], |
| 9097 | 9115 | cdef: &CdefParams, |
| 9098 | 9116 | loop_filter: &LoopFilterParams, |
| 9117 | + lr: &LoopRestorationParams, | |
| 9099 | 9118 | initial_cdfs: Option<Cdfs>, |
| 9100 | 9119 | allow_high_precision_mv: bool, |
| 9101 | 9120 | force_integer_mv: bool, |
| @@ -9271,10 +9290,25 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9271 | 9290 | mi_rows as usize, |
| 9272 | 9291 | ); |
| 9273 | 9292 | let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize); |
| 9293 | + let mut lr_grid = crate::restoration::RestorationGrid::new(lr, frame_width, frame_height); | |
| 9294 | + let mut lr_reference = [( | |
| 9295 | + crate::restoration::WienerInfo::default(), | |
| 9296 | + crate::restoration::SgrprojInfo::default(), | |
| 9297 | + ); 3]; | |
| 9274 | 9298 | |
| 9275 | 9299 | for sb_r in 0..sb_rows { |
| 9276 | 9300 | neighbours.start_row(); |
| 9277 | 9301 | for sb_c in 0..sb_cols { |
| 9302 | + crate::restoration::read_lr( | |
| 9303 | + &mut dec, | |
| 9304 | + &mut cdfs, | |
| 9305 | + lr, | |
| 9306 | + &mut lr_grid, | |
| 9307 | + &mut lr_reference, | |
| 9308 | + sb_r * SB_MI, | |
| 9309 | + sb_c * SB_MI, | |
| 9310 | + SB_MI, | |
| 9311 | + ); | |
| 9278 | 9312 | let sb_at = (sb_r as usize * 4, sb_c as usize * 4); |
| 9279 | 9313 | let sb_ctx = neighbours.partition_ctx(sb_at, SB); |
| 9280 | 9314 | let (has_cols, has_rows) = ( |
crates/ec-av1/src/stream.rsmodified+8 -1
| @@ -191,10 +191,15 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 191 | 191 | // silent-desync shape as the refusals above. Traced live 2026-08-27: |
| 192 | 192 | // an aomenc inter frame with `Sgrproj` on the V plane desynced the |
| 193 | 193 | // partition walk into out-of-alphabet garbage. |
| 194 | + // lane-lr r2: the per-superblock `read_lr`/`read_lr_unit` symbols are | |
| 195 | + // now read (`crate::restoration`) and no longer desync the partition | |
| 196 | + // walk -- the refusal narrows to its true remaining gap: decoded | |
| 197 | + // Wiener/SGR filters are stored per unit but never applied to | |
| 198 | + // pixels. | |
| 194 | 199 | if header.loop_restoration.uses_lr { |
| 195 | 200 | return Err(Error::unsupported( |
| 196 | 201 | "AV1 decode_stream", |
| 197 | - "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)", | |
| 202 | + "a frame with loop restoration enabled (the per-unit lr symbols are read but the Wiener/self-guided filters are not yet applied to pixels)", | |
| 198 | 203 | )); |
| 199 | 204 | } |
| 200 | 205 | // `decode_inter_block`/`decode_inter_block8`'s `GLOBALMV` arm (spec |
| @@ -370,6 +375,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 370 | 375 | enable_edge_filter, |
| 371 | 376 | &header.cdef, |
| 372 | 377 | &header.loop_filter, |
| 378 | + &header.loop_restoration, | |
| 373 | 379 | initial_cdfs, |
| 374 | 380 | header.tx_mode == TxMode::Select, |
| 375 | 381 | header.reduced_tx_set, |
| @@ -437,6 +443,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 437 | 443 | other_refs, |
| 438 | 444 | &header.cdef, |
| 439 | 445 | &header.loop_filter, |
| 446 | + &header.loop_restoration, | |
| 440 | 447 | initial_cdfs, |
| 441 | 448 | header.allow_high_precision_mv, |
| 442 | 449 | header.force_integer_mv, |