shithub: openh264

Download patch

ref: b1c13f4954b2f81bbd08a04d55ed03f11d34a7f5
parent: 03db750ba9b8fe208aa4002d35ba7096e5daf5d2
author: Martin Storsjö <[email protected]>
date: Sun May 4 13:40:28 EDT 2014

Properly limit the range for the random target motion vectors

A 16x16 pixel block is copied to the destination pointed out by the
target motion vector. Since the motion vector is relative to the
center of the buffer, the upper bound of the range is size/2-16.

Previously we never used negative motion vectors, but there is no
reason not to test that direction. Therefore, the possible range
would be [-size/2,size/2-16]. Additionally pad this range with
INTPEL_NEEDED_MARGIN.

--- a/test/encoder/EncUT_MotionEstimate.cpp
+++ b/test/encoder/EncUT_MotionEstimate.cpp
@@ -147,7 +147,7 @@
   int32_t iTryTimes=100;
 
   sTargetMv.iMvX = 0;
-  sTargetMv.iMvY = WELS_MAX(INTPEL_NEEDED_MARGIN, rand()%m_iHeight-INTPEL_NEEDED_MARGIN);
+  sTargetMv.iMvY = -sMe.iCurMeBlockPixY + INTPEL_NEEDED_MARGIN + rand()%(m_iHeight - 16 - 2*INTPEL_NEEDED_MARGIN);
   bDataGeneratorSucceed = false;
   bFoundMatch = false;
   while (!bFoundMatch && (iTryTimes--)>0) {
@@ -207,7 +207,7 @@
   bool bFoundMatch = false;
   int32_t iTryTimes=100;
 
-  sTargetMv.iMvX = WELS_MAX(INTPEL_NEEDED_MARGIN, rand()%m_iWidth-INTPEL_NEEDED_MARGIN);
+  sTargetMv.iMvX = -sMe.iCurMeBlockPixX + INTPEL_NEEDED_MARGIN + rand()%(m_iWidth - 16 - 2*INTPEL_NEEDED_MARGIN);
   sTargetMv.iMvY = 0;
   bDataGeneratorSucceed = false;
   bFoundMatch = false;
@@ -276,7 +276,7 @@
   int32_t iTryTimes=100;
 
   sTargetMv.iMvX = 0;
-  sTargetMv.iMvY = WELS_MAX(INTPEL_NEEDED_MARGIN, rand()%m_iHeight-INTPEL_NEEDED_MARGIN);
+  sTargetMv.iMvY = -sMe.iCurMeBlockPixY + INTPEL_NEEDED_MARGIN + rand()%(m_iHeight - 16 - 2*INTPEL_NEEDED_MARGIN);
   bDataGeneratorSucceed = false;
   bFoundMatch = false;
   while (!bFoundMatch && (iTryTimes--)>0) {
@@ -341,7 +341,7 @@
   bool bFoundMatch = false;
   int32_t iTryTimes=100;
 
-  sTargetMv.iMvX = WELS_MAX(INTPEL_NEEDED_MARGIN, rand()%m_iWidth-INTPEL_NEEDED_MARGIN);
+  sTargetMv.iMvX = -sMe.iCurMeBlockPixX + INTPEL_NEEDED_MARGIN + rand()%(m_iWidth - 16 - 2*INTPEL_NEEDED_MARGIN);
   sTargetMv.iMvY = 0;
   bDataGeneratorSucceed = false;
   bFoundMatch = false;