Browse code

motion_est: avoid generating motion vectors that point between widthxheight and mb_widthxmb_height. No difference in PSNR or bitrate in the printed precission with the matrix lobby scene at 322x242

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 56bf2c2a192523e1d0f2328bd755e63b4a0a79f8)

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

Michael Niedermayer authored on 2011/12/18 03:55:47
Showing 1 changed files
... ...
@@ -536,8 +536,8 @@ static inline void get_limits(MpegEncContext *s, int x, int y)
536 536
     if (s->unrestricted_mv) {
537 537
         c->xmin = - x - 16;
538 538
         c->ymin = - y - 16;
539
-        c->xmax = - x + s->mb_width *16;
540
-        c->ymax = - y + s->mb_height*16;
539
+        c->xmax = - x + s->width;
540
+        c->ymax = - y + s->height;
541 541
     } else if (s->out_format == FMT_H261){
542 542
         // Search range of H261 is different from other codec standards
543 543
         c->xmin = (x > 15) ? - 15 : 0;
... ...
@@ -576,10 +576,11 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
576 576
     const int h=8;
577 577
     int block;
578 578
     int P[10][2];
579
-    int dmin_sum=0, mx4_sum=0, my4_sum=0;
579
+    int dmin_sum=0, mx4_sum=0, my4_sum=0, i;
580 580
     int same=1;
581 581
     const int stride= c->stride;
582 582
     uint8_t *mv_penalty= c->current_mv_penalty;
583
+    int saftey_cliping= s->unrestricted_mv && (s->width&15) && (s->height&15);
583 584
 
584 585
     init_mv4_ref(c);
585 586
 
... ...
@@ -591,6 +592,11 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
591 591
         const int mot_stride = s->b8_stride;
592 592
         const int mot_xy = s->block_index[block];
593 593
 
594
+        if(saftey_cliping){
595
+            c->xmax = - 16*s->mb_x + s->width  - 8*(block &1);
596
+            c->ymax = - 16*s->mb_y + s->height - 8*(block>>1);
597
+        }
598
+
594 599
         P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0];
595 600
         P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1];
596 601
 
... ...
@@ -618,6 +624,11 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
618 618
         }
619 619
         P_MV1[0]= mx;
620 620
         P_MV1[1]= my;
621
+        if(saftey_cliping)
622
+            for(i=0; i<10; i++){
623
+                if(P[i][0] > (c->xmax<<shift)) P[i][0]= (c->xmax<<shift);
624
+                if(P[i][1] > (c->ymax<<shift)) P[i][1]= (c->ymax<<shift);
625
+            }
621 626
 
622 627
         dmin4 = epzs_motion_search4(s, &mx4, &my4, P, block, block, s->p_mv_table, (1<<16)>>shift);
623 628