From c42612f1b48d00255710e451b5800987bcb4add8 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 24 Oct 2002 00:51:17 +0000 Subject: [PATCH] clip MVs for direct mode Originally committed as revision 1068 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/motion_est.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index c59e06b48a..f8064b126c 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1336,7 +1336,13 @@ static inline int check_bidir_mv(MpegEncContext * s, dxy = ((motion_fy & 1) << 1) | (motion_fx & 1); src_x = mb_x * 16 + (motion_fx >> 1); src_y = mb_y * 16 + (motion_fy >> 1); - + src_x = clip(src_x, -16, s->width); + if (src_x == s->width) + dxy&= 2; + src_y = clip(src_y, -16, s->height); + if (src_y == s->height) + dxy&= 1; + ptr = s->last_picture[0] + (src_y * s->linesize) + src_x; put_pixels_tab[0][dxy](dest_y , ptr , s->linesize, 16); @@ -1345,6 +1351,12 @@ static inline int check_bidir_mv(MpegEncContext * s, dxy = ((motion_by & 1) << 1) | (motion_bx & 1); src_x = mb_x * 16 + (motion_bx >> 1); src_y = mb_y * 16 + (motion_by >> 1); + src_x = clip(src_x, -16, s->width); + if (src_x == s->width) + dxy&= 2; + src_y = clip(src_y, -16, s->height); + if (src_y == s->height) + dxy&= 1; ptr = s->next_picture[0] + (src_y * s->linesize) + src_x; avg_pixels_tab[0][dxy](dest_y , ptr , s->linesize, 16);