[FFmpeg-cvslog] avcodec/mpegvideo: clip mv visualization arrows so that their direction is maintained

Michael Niedermayer git at videolan.org
Wed Jul 9 16:10:52 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Jul  9 15:53:23 2014 +0200| [f32c5d1a8daeaf95877757202f78f99ea25adb3c] | committer: Michael Niedermayer

avcodec/mpegvideo: clip mv visualization arrows so that their direction is maintained

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f32c5d1a8daeaf95877757202f78f99ea25adb3c
---

 libavcodec/mpegvideo.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index c173aac..a9024a9 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1975,6 +1975,29 @@ void ff_MPV_frame_end(MpegEncContext *s)
         ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);
 }
 
+
+static int clip_line(int *sx, int *sy, int *ex, int *ey, int maxx)
+{
+    if(*sx > *ex)
+        return clip_line(ex, ey, sx, sy, maxx);
+
+    if (*sx < 0) {
+        if (*ex < 0)
+            return 1;
+        *sy = *ey + (*sy - *ey) * (int64_t)*ex / (*ex - *sx);
+        *sx = 0;
+    }
+
+    if (*ex > maxx) {
+        if (*sx > maxx)
+            return 1;
+        *ey = *sy + (*ey - *sy) * (int64_t)(maxx - *sx) / (*ex - *sx);
+        *ex = maxx;
+    }
+    return 0;
+}
+
+
 /**
  * Draw a line from (ex, ey) -> (sx, sy).
  * @param w width of the image
@@ -1987,6 +2010,11 @@ static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey,
 {
     int x, y, fr, f;
 
+    if (clip_line(&sx, &sy, &ex, &ey, w - 1))
+        return;
+    if (clip_line(&sy, &sx, &ey, &ex, h - 1))
+        return;
+
     sx = av_clip(sx, 0, w - 1);
     sy = av_clip(sy, 0, h - 1);
     ex = av_clip(ex, 0, w - 1);



More information about the ffmpeg-cvslog mailing list