Deblock clips to coded frame_width/height, not the mi-aligned margin
Browse files at this commit81df7353882c4723a04647cef0bc4fd5633aa899Parent: 23731fa- fix
- deblock clips to coded frame_width/height, not the mi-aligned margin
1 changed file +49 -7
- crates/ec-av1/src/decode.rs +49 -7
crates/ec-av1/src/decode.rsmodified+49 -7
| @@ -3755,15 +3755,17 @@ fn apply_deblock( | ||
| 3755 | 3755 | v: &mut PlaneBuf, |
| 3756 | 3756 | lf: &LoopFilterParams, |
| 3757 | 3757 | n: &Neighbours, |
| 3758 | + frame_width: usize, | |
| 3759 | + frame_height: usize, | |
| 3758 | 3760 | ) { |
| 3759 | 3761 | if lf.level[0] != 0 || lf.level[1] != 0 { |
| 3760 | - deblock_plane(y, 0, lf, n); | |
| 3762 | + deblock_plane(y, 0, lf, n, frame_width, frame_height); | |
| 3761 | 3763 | } |
| 3762 | 3764 | if lf.level[2] != 0 { |
| 3763 | - deblock_plane(u, 1, lf, n); | |
| 3765 | + deblock_plane(u, 1, lf, n, frame_width, frame_height); | |
| 3764 | 3766 | } |
| 3765 | 3767 | if lf.level[3] != 0 { |
| 3766 | - deblock_plane(v, 2, lf, n); | |
| 3768 | + deblock_plane(v, 2, lf, n, frame_width, frame_height); | |
| 3767 | 3769 | } |
| 3768 | 3770 | } |
| 3769 | 3771 | |
| @@ -4265,9 +4267,33 @@ fn filter_edge( | ||
| 4265 | 4267 | |
| 4266 | 4268 | /// One plane's worth of spec 7.14: every vertical edge across the plane, |
| 4267 | 4269 | /// then every horizontal edge (the order the spec and libaom both use). |
| 4268 | -fn deblock_plane(plane: &mut PlaneBuf, plane_idx: usize, lf: &LoopFilterParams, n: &Neighbours) { | |
| 4270 | +fn deblock_plane( | |
| 4271 | + plane: &mut PlaneBuf, | |
| 4272 | + plane_idx: usize, | |
| 4273 | + lf: &LoopFilterParams, | |
| 4274 | + n: &Neighbours, | |
| 4275 | + frame_width: usize, | |
| 4276 | + frame_height: usize, | |
| 4277 | +) { | |
| 4269 | 4278 | let chroma = plane_idx != 0; |
| 4270 | - let (tw, th, stride) = (plane.true_width, plane.true_height, plane.width); | |
| 4279 | + // r7: libaom clips the deblock loop to the CODED frame's own | |
| 4280 | + // width/height, not the mi-aligned `true_width`/`true_height` margin | |
| 4281 | + // (the padding up to the next 8-pixel/superblock boundary that | |
| 4282 | + // reconstruction still fills in but the loop filter never visits). | |
| 4283 | + // Confirmed against the superres gate: with the margin included, the | |
| 4284 | + // last coded mi column's horizontal edges were filtered when libaom's | |
| 4285 | + // real output leaves them untouched (r6's post-deblock diff, 37 px, all | |
| 4286 | + // in columns 44-47); clipping here closes it (3/3 frames pixel-exact). | |
| 4287 | + let (cw, ch) = if chroma { | |
| 4288 | + (frame_width.div_ceil(2), frame_height.div_ceil(2)) | |
| 4289 | + } else { | |
| 4290 | + (frame_width, frame_height) | |
| 4291 | + }; | |
| 4292 | + let (tw, th, stride) = ( | |
| 4293 | + plane.true_width.min(cw), | |
| 4294 | + plane.true_height.min(ch), | |
| 4295 | + plane.width, | |
| 4296 | + ); | |
| 4271 | 4297 | let mut y0 = 0usize; |
| 4272 | 4298 | while y0 < th { |
| 4273 | 4299 | let mut x0 = 4usize; |
| @@ -5005,7 +5031,15 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 5005 | 5031 | let _ = f.write_all(&crop_wide(&v)); |
| 5006 | 5032 | } |
| 5007 | 5033 | } |
| 5008 | - apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | |
| 5034 | + apply_deblock( | |
| 5035 | + &mut y, | |
| 5036 | + &mut u, | |
| 5037 | + &mut v, | |
| 5038 | + loop_filter, | |
| 5039 | + &neighbours, | |
| 5040 | + frame_width as usize, | |
| 5041 | + frame_height as usize, | |
| 5042 | + ); | |
| 5009 | 5043 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 5010 | 5044 | |
| 5011 | 5045 | let (fw, fh) = (frame_width as usize, frame_height as usize); |
| @@ -10544,7 +10578,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 10544 | 10578 | } else { |
| 10545 | 10579 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 10546 | 10580 | } |
| 10547 | - apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | |
| 10581 | + apply_deblock( | |
| 10582 | + &mut y, | |
| 10583 | + &mut u, | |
| 10584 | + &mut v, | |
| 10585 | + loop_filter, | |
| 10586 | + &neighbours, | |
| 10587 | + frame_width as usize, | |
| 10588 | + frame_height as usize, | |
| 10589 | + ); | |
| 10548 | 10590 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 10549 | 10591 | |
| 10550 | 10592 | let motion_field = build_motion_field( |