Commit f32c5d1a authored by Michael Niedermayer's avatar Michael Niedermayer

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

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent d6e7881c
......@@ -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);
......
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