]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpegvideo.c
Merge commit 'e0d73fda361729d207e51fa2afd8ba6102e58d98'
[ffmpeg] / libavcodec / mpegvideo.c
index 6b9103da85f3831200639e041cb7d9b4fa07fa43..4672359d71f0b0e7d79e3e00a0edab6bfe263ada 100644 (file)
@@ -380,10 +380,10 @@ static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
 av_cold int ff_dct_common_init(MpegEncContext *s)
 {
     ff_blockdsp_init(&s->bdsp, s->avctx);
-    ff_dsputil_init(&s->dsp, s->avctx);
     ff_h264chroma_init(&s->h264chroma, 8); //for lowres
     ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
     ff_idctdsp_init(&s->idsp, s->avctx);
+    ff_me_cmp_init(&s->mecc, s->avctx);
     ff_mpegvideodsp_init(&s->mdsp);
     ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
 
@@ -409,6 +409,9 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
         s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
     s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
 
+    if (HAVE_INTRINSICS_NEON)
+        ff_MPV_common_init_neon(s);
+
     if (ARCH_ALPHA)
         ff_MPV_common_init_axp(s);
     if (ARCH_ARM)
@@ -1106,7 +1109,7 @@ static int init_er(MpegEncContext *s)
     int i;
 
     er->avctx       = s->avctx;
-    er->dsp         = &s->dsp;
+    er->mecc        = &s->mecc;
 
     er->mb_index2xy = s->mb_index2xy;
     er->mb_num      = s->mb_num;
@@ -1975,6 +1978,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 +2013,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);
@@ -2036,10 +2067,15 @@ static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey,
  * @param color color of the arrow
  */
 static void draw_arrow(uint8_t *buf, int sx, int sy, int ex,
-                       int ey, int w, int h, int stride, int color)
+                       int ey, int w, int h, int stride, int color, int tail, int direction)
 {
     int dx,dy;
 
+    if (direction) {
+        FFSWAP(int, sx, ex);
+        FFSWAP(int, sy, ey);
+    }
+
     sx = av_clip(sx, -100, w + 100);
     sy = av_clip(sy, -100, h + 100);
     ex = av_clip(ex, -100, w + 100);
@@ -2057,6 +2093,11 @@ static void draw_arrow(uint8_t *buf, int sx, int sy, int ex,
         rx = ROUNDED_DIV(rx * 3 << 4, length);
         ry = ROUNDED_DIV(ry * 3 << 4, length);
 
+        if (tail) {
+            rx = -rx;
+            ry = -ry;
+        }
+
         draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color);
         draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color);
     }
@@ -2210,7 +2251,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_
                                 int mx = (motion_val[direction][xy][0] >> shift) + sx;
                                 int my = (motion_val[direction][xy][1] >> shift) + sy;
                                 draw_arrow(ptr, sx, sy, mx, my, width,
-                                           height, pict->linesize[0], 100);
+                                           height, pict->linesize[0], 100, 0, direction);
                             }
                         } else if (IS_16X8(mbtype_table[mb_index])) {
                             int i;
@@ -2225,7 +2266,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_
                                     my *= 2;
 
                                 draw_arrow(ptr, sx, sy, mx + sx, my + sy, width,
-                                           height, pict->linesize[0], 100);
+                                           height, pict->linesize[0], 100, 0, direction);
                             }
                         } else if (IS_8X16(mbtype_table[mb_index])) {
                             int i;
@@ -2240,7 +2281,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_
                                     my *= 2;
 
                                 draw_arrow(ptr, sx, sy, mx + sx, my + sy, width,
-                                           height, pict->linesize[0], 100);
+                                           height, pict->linesize[0], 100, 0, direction);
                             }
                         } else {
                               int sx= mb_x * 16 + 8;
@@ -2248,7 +2289,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_
                               int xy= (mb_x + mb_y * mv_stride) << mv_sample_log2;
                               int mx= (motion_val[direction][xy][0]>>shift) + sx;
                               int my= (motion_val[direction][xy][1]>>shift) + sy;
-                              draw_arrow(ptr, sx, sy, mx, my, width, height, pict->linesize[0], 100);
+                              draw_arrow(ptr, sx, sy, mx, my, width, height, pict->linesize[0], 100, 0, direction);
                         }
                     }
                 }