diff --git a/crates/ec-vp8/src/modes.rs b/crates/ec-vp8/src/modes.rs index aceadaff..e69fe3b7 100644 --- a/crates/ec-vp8/src/modes.rs +++ b/crates/ec-vp8/src/modes.rs @@ -462,9 +462,11 @@ pub fn find_near_mvs( } } - // libvpx checks `cnt[CNT_SPLITMV]` BEFORE computing it (the write - // happens later in the same branch), so the above-left merge is - // effectively dead there; ported as-is with the same dead guard. + // Above-left merge (libvpx decodemv.c:366): when the above-left + // pushed a THIRD distinct candidate, its count landed in + // cnt[CNT_SPLITMV] (cntx reached slot 3), and if that candidate + // equals the nearest candidate, NEAREST absorbs it. The split count + // is then overwritten with the SPLITMV-neighbour census below. if cnt[CNT_SPLITMV] != 0 && mvs[idx] == mvs[CNT_NEAREST] { cnt[CNT_NEAREST] += 1; } diff --git a/scripts/vp8ref_model.py b/scripts/vp8ref_model.py index ea9788b2..a22b787b 100755 --- a/scripts/vp8ref_model.py +++ b/scripts/vp8ref_model.py @@ -342,6 +342,12 @@ def main(): cnt[cx] += wgt else: cnt[0] += wgt + # libvpx decodemv.c:366 — when the above-left pushed a THIRD + # distinct candidate it counted into cnt[CNT_SPLITMV] (cntx + # reached slot 3), and if that candidate equals the nearest, + # NEAREST absorbs it. Alive, not dead. + if cnt[3] != 0 and mvs[ix] == mvs[1]: + cnt[1] += 1 cnt[3] = (above["split"] * 2) + (left["split"] * 2) + aboveleft["split"] if cnt[2] > cnt[1]: cnt[1], cnt[2] = cnt[2], cnt[1] @@ -525,7 +531,7 @@ def main(): import traceback; traceback.print_exc() print(f"EXC at r={r} c={c}: {e}") raise SystemExit(1) - mvref_print = 4 if mbsplit[r][c] else {-1: 3, -2: 1, -3: 2, -4: 3}.get( + mvref_print = 4 if mbsplit[r][c] else {-1: 0, -2: 1, -3: 2, -4: 3}.get( mbmode[r][c], 0 ) print(