Writer support for NEAR_NEAR / NEAREST_NEW / NEW_NEAREST compound modes
Browse files at this commitd49885fa31e0c52e148b732300e7980badcb9de2Parent: 583d98d- feat
- writer support for NEAR_NEAR / NEAREST_NEW / NEW_NEAREST compound modes
1 changed file +58 -2
- crates/ec-av1/src/tile.rs +58 -2
crates/ec-av1/src/tile.rsmodified+58 -2
| @@ -324,7 +324,7 @@ pub(crate) fn take_compound_pair_hits() -> [usize; 7] { | |||
| 324 | /// order. Returns the two motion vectors the decoder derives (what the MI | 324 | /// order. Returns the two motion vectors the decoder derives (what the MI |
| 325 | /// grid must record) and whether the mode was a `NEW*` one. | 325 | /// grid must record) and whether the mode was a `NEW*` one. |
| 326 | /// | 326 | /// |
| 327 | -/// Only the three modes [`InterMode::compound_index`] names are written, and | 327 | +/// Only the modes [`InterMode::compound_index`] names are written, and |
| 328 | /// only the `comp_group_idx == 0`, `compound_idx == 1` blend (spec | 328 | /// only the `comp_group_idx == 0`, `compound_idx == 1` blend (spec |
| 329 | /// `COMPOUND_AVERAGE`) -- masked compound and the distance-weighted blend are | 329 | /// `COMPOUND_AVERAGE`) -- masked compound and the distance-weighted blend are |
| 330 | /// not searched. | 330 | /// not searched. |
| @@ -386,6 +386,41 @@ fn write_compound_block( | |||
| 386 | let mvs = match info.mode { | 386 | let mvs = match info.mode { |
| 387 | InterMode::NearestNearestMv => stack.nearest_mv, | 387 | InterMode::NearestNearestMv => stack.nearest_mv, |
| 388 | InterMode::GlobalGlobalMv => ((0, 0), (0, 0)), | 388 | InterMode::GlobalGlobalMv => ((0, 0), (0, 0)), |
| 389 | + InterMode::NearNearMv => { | ||
| 390 | + // decode.rs `assign_compound_mv`'s second DRL loop: the index | ||
| 391 | + // starts at 1 and the mode's own `ref_mv_idx` is `idx - 1`, so | ||
| 392 | + // this walk starts at 1 too and reads entry `ref_mv_idx + 1`. | ||
| 393 | + let idx = usize::from(info.ref_mv_idx) + 1; | ||
| 394 | + let mut walk = 1usize; | ||
| 395 | + while walk < 3 && stack.entries.len() > walk + 1 { | ||
| 396 | + let advance = walk < idx; | ||
| 397 | + enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[walk]]); | ||
| 398 | + if !advance { | ||
| 399 | + break; | ||
| 400 | + } | ||
| 401 | + walk += 1; | ||
| 402 | + } | ||
| 403 | + stack | ||
| 404 | + .entries | ||
| 405 | + .get(idx) | ||
| 406 | + .map_or(stack.near_mv, |e| (e.mv0, e.mv1)) | ||
| 407 | + } | ||
| 408 | + InterMode::NearestNewMv | InterMode::NewNearestMv => { | ||
| 409 | + // Neither mode codes a DRL index (the decoder leaves `ref_mv_idx` | ||
| 410 | + // at 0): the NEAREST half is derived, the NEW half codes a | ||
| 411 | + // residual against stack entry 0. | ||
| 412 | + let base = stack | ||
| 413 | + .entries | ||
| 414 | + .first() | ||
| 415 | + .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1)); | ||
| 416 | + if matches!(info.mode, InterMode::NearestNewMv) { | ||
| 417 | + write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv1, base.1)?; | ||
| 418 | + (stack.nearest_mv.0, info.mv1) | ||
| 419 | + } else { | ||
| 420 | + write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base.0)?; | ||
| 421 | + (info.mv, stack.nearest_mv.1) | ||
| 422 | + } | ||
| 423 | + } | ||
| 389 | _ => { | 424 | _ => { |
| 390 | let idx = usize::from(info.ref_mv_idx); | 425 | let idx = usize::from(info.ref_mv_idx); |
| 391 | let mut walk = 0usize; | 426 | let mut walk = 0usize; |
| @@ -420,7 +455,15 @@ fn write_compound_block( | |||
| 420 | COMPOUND_MODE_HITS[mode].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 455 | COMPOUND_MODE_HITS[mode].fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 421 | COMPOUND_PAIR_HITS[(ref1.max(1) - 1) as usize % 7] | 456 | COMPOUND_PAIR_HITS[(ref1.max(1) - 1) as usize % 7] |
| 422 | .fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 457 | .fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 423 | - Ok((mvs.0, mvs.1, matches!(info.mode, InterMode::NewNewMv))) | 458 | + // decode.rs' own `is_new_mv` for a compound block: modes 2, 3, 4, 5, 7. |
| 459 | + Ok(( | ||
| 460 | + mvs.0, | ||
| 461 | + mvs.1, | ||
| 462 | + matches!( | ||
| 463 | + info.mode, | ||
| 464 | + InterMode::NewNewMv | InterMode::NearestNewMv | InterMode::NewNearestMv | ||
| 465 | + ), | ||
| 466 | + )) | ||
| 424 | } | 467 | } |
| 425 | 468 | ||
| 426 | /// Writer-side counterpart of decode.rs `read_comp_mode` (spec 5.11.25's | 469 | /// Writer-side counterpart of decode.rs `read_comp_mode` (spec 5.11.25's |
| @@ -977,6 +1020,16 @@ pub enum InterMode { | |||
| 977 | /// `NEAREST_NEARESTMV`: both sides take the compound stack's own nearest | 1020 | /// `NEAREST_NEARESTMV`: both sides take the compound stack's own nearest |
| 978 | /// pair, no residual, no DRL. | 1021 | /// pair, no residual, no DRL. |
| 979 | NearestNearestMv, | 1022 | NearestNearestMv, |
| 1023 | + /// `NEAR_NEARMV`: both sides take compound stack entry | ||
| 1024 | + /// [`InterInfo::ref_mv_idx`]` + 1` (decode.rs `assign_compound_mv`'s own | ||
| 1025 | + /// `ref_mv_idx + 1`), reached by a DRL walk that starts at index 1. | ||
| 1026 | + NearNearMv, | ||
| 1027 | + /// `NEAREST_NEWMV`: the first side takes the stack's nearest vector, the | ||
| 1028 | + /// second codes a residual against stack entry 0. | ||
| 1029 | + NearestNewMv, | ||
| 1030 | + /// `NEW_NEARESTMV`: the first side codes a residual against stack entry 0, | ||
| 1031 | + /// the second takes the stack's nearest vector. | ||
| 1032 | + NewNearestMv, | ||
| 980 | /// `GLOBAL_GLOBALMV`: both sides take the identity global model's zero | 1033 | /// `GLOBAL_GLOBALMV`: both sides take the identity global model's zero |
| 981 | /// vector. | 1034 | /// vector. |
| 982 | GlobalGlobalMv, | 1035 | GlobalGlobalMv, |
| @@ -992,6 +1045,9 @@ impl InterMode { | |||
| 992 | fn compound_index(self) -> Option<usize> { | 1045 | fn compound_index(self) -> Option<usize> { |
| 993 | match self { | 1046 | match self { |
| 994 | InterMode::NearestNearestMv => Some(0), | 1047 | InterMode::NearestNearestMv => Some(0), |
| 1048 | + InterMode::NearNearMv => Some(1), | ||
| 1049 | + InterMode::NearestNewMv => Some(2), | ||
| 1050 | + InterMode::NewNearestMv => Some(3), | ||
| 995 | InterMode::GlobalGlobalMv => Some(6), | 1051 | InterMode::GlobalGlobalMv => Some(6), |
| 996 | InterMode::NewNewMv => Some(7), | 1052 | InterMode::NewNewMv => Some(7), |
| 997 | _ => None, | 1053 | _ => None, |