Skip to content

Commit 4984e07

Browse files
rom1vtdaede
authored andcommitted
Clamp motion vectors at frame level
This fixes bitstream corruption! Lost hours here: many.
1 parent 888250e commit 4984e07

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/context.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,16 +2610,20 @@ impl<'a> ContextWriter<'a> {
26102610

26112611
/* TODO: Handle single reference frame extension */
26122612

2613+
let frame_bo = BlockOffset {
2614+
x: self.bc.blocks.x() + bo.x,
2615+
y: self.bc.blocks.y() + bo.y,
2616+
};
26132617
// clamp mvs
26142618
for mv in mv_stack {
26152619
let blk_w = bsize.width();
26162620
let blk_h = bsize.height();
26172621
let border_w = 128 + blk_w as isize * 8;
26182622
let border_h = 128 + blk_h as isize * 8;
2619-
let mvx_min = -(bo.x as isize) * (8 * MI_SIZE) as isize - border_w;
2620-
let mvx_max = (self.bc.blocks.cols() - bo.x - blk_w / MI_SIZE) as isize * (8 * MI_SIZE) as isize + border_w;
2621-
let mvy_min = -(bo.y as isize) * (8 * MI_SIZE) as isize - border_h;
2622-
let mvy_max = (self.bc.blocks.rows() - bo.y - blk_h / MI_SIZE) as isize * (8 * MI_SIZE) as isize + border_h;
2623+
let mvx_min = -(frame_bo.x as isize) * (8 * MI_SIZE) as isize - border_w;
2624+
let mvx_max = (self.bc.blocks.frame_cols - frame_bo.x - blk_w / MI_SIZE) as isize * (8 * MI_SIZE) as isize + border_w;
2625+
let mvy_min = -(frame_bo.y as isize) * (8 * MI_SIZE) as isize - border_h;
2626+
let mvy_max = (self.bc.blocks.frame_rows - frame_bo.y - blk_h / MI_SIZE) as isize * (8 * MI_SIZE) as isize + border_h;
26232627
mv.this_mv.row = (mv.this_mv.row as isize).max(mvy_min).min(mvy_max) as i16;
26242628
mv.this_mv.col = (mv.this_mv.col as isize).max(mvx_min).min(mvx_max) as i16;
26252629
mv.comp_mv.row = (mv.comp_mv.row as isize).max(mvy_min).min(mvy_max) as i16;

0 commit comments

Comments
 (0)