Commit 4984e073 authored by Romain Vimont's avatar Romain Vimont Committed by Thomas Daede

Clamp motion vectors at frame level

This fixes bitstream corruption!

Lost hours here: many.
parent 888250e2
......@@ -2610,16 +2610,20 @@ impl<'a> ContextWriter<'a> {
/* TODO: Handle single reference frame extension */
let frame_bo = BlockOffset {
x: self.bc.blocks.x() + bo.x,
y: self.bc.blocks.y() + bo.y,
};
// clamp mvs
for mv in mv_stack {
let blk_w = bsize.width();
let blk_h = bsize.height();
let border_w = 128 + blk_w as isize * 8;
let border_h = 128 + blk_h as isize * 8;
let mvx_min = -(bo.x as isize) * (8 * MI_SIZE) as isize - border_w;
let mvx_max = (self.bc.blocks.cols() - bo.x - blk_w / MI_SIZE) as isize * (8 * MI_SIZE) as isize + border_w;
let mvy_min = -(bo.y as isize) * (8 * MI_SIZE) as isize - border_h;
let mvy_max = (self.bc.blocks.rows() - bo.y - blk_h / MI_SIZE) as isize * (8 * MI_SIZE) as isize + border_h;
let mvx_min = -(frame_bo.x as isize) * (8 * MI_SIZE) as isize - border_w;
let mvx_max = (self.bc.blocks.frame_cols - frame_bo.x - blk_w / MI_SIZE) as isize * (8 * MI_SIZE) as isize + border_w;
let mvy_min = -(frame_bo.y as isize) * (8 * MI_SIZE) as isize - border_h;
let mvy_max = (self.bc.blocks.frame_rows - frame_bo.y - blk_h / MI_SIZE) as isize * (8 * MI_SIZE) as isize + border_h;
mv.this_mv.row = (mv.this_mv.row as isize).max(mvy_min).min(mvy_max) as i16;
mv.this_mv.col = (mv.this_mv.col as isize).max(mvx_min).min(mvx_max) as i16;
mv.comp_mv.row = (mv.comp_mv.row as isize).max(mvy_min).min(mvy_max) as i16;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment