changeset 1035:9fbad5cf7e9e libavcodec

drawing cute arrows instead of lame lines for motion vector visualization
author michaelni
date Sun, 26 Jan 2003 23:11:08 +0000
parents af7ba8d8b43a
children c7922c5becf6
files h263dec.c
diffstat 1 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/h263dec.c	Sun Jan 26 23:09:12 2003 +0000
+++ b/h263dec.c	Sun Jan 26 23:11:08 2003 +0000
@@ -377,6 +377,25 @@
     }
 }
 
+static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ 
+    int dx= ex - sx;
+    int dy= ey - sy;
+    
+    if(dx*dx + dy*dy > 3*3){
+        int rx=  dx + dy;
+        int ry= -dx + dy;
+        int length= ff_sqrt((rx*rx + ry*ry)<<8);
+        
+        //FIXME subpixel accuracy
+        rx= ROUNDED_DIV(rx*3<<4, length);
+        ry= ROUNDED_DIV(ry*3<<4, length);
+        
+        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);
+    }
+    draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
+}
+
 int ff_h263_decode_frame(AVCodecContext *avctx, 
                              void *data, int *data_size,
                              UINT8 *buf, int buf_size)
@@ -703,7 +722,7 @@
                         int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2);
                         int mx= (s->motion_val[xy][0]>>shift) + sx;
                         int my= (s->motion_val[xy][1]>>shift) + sy;
-                        draw_line(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
+                        draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
                     }
                 }else{
                     int sx= mb_x*16 + 8;
@@ -711,7 +730,7 @@
                     int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2);
                     int mx= (s->motion_val[xy][0]>>shift) + sx;
                     int my= (s->motion_val[xy][1]>>shift) + sy;
-                    draw_line(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
+                    draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
                 }
                 s->mbskip_table[mb_index]=0;
             }