summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-07-09 15:53:23 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-07-09 16:04:32 +0200
commitf32c5d1a8daeaf95877757202f78f99ea25adb3c (patch)
tree47f05ea64f2e52e20d9f52955eb9d1fa17c68ef3 /libavcodec/mpegvideo.c
parentd6e7881c2e6000d8bf74b3f68ba0c1bacd8c3688 (diff)
avcodec/mpegvideo: clip mv visualization arrows so that their direction is maintained
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/mpegvideo.c')
-rw-r--r--libavcodec/mpegvideo.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index c173aac7c5..a9024a978e 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);