• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <math.h>
3 #include <string.h>
4 #include "cpu.h"
5 #include "cpu_core.h"
6 #include "IWelsVP.h"
7 #include "ScrollDetection.h"
8 #include "ScrollDetectionFuncs.h"
9 #include "utils/DataGenerator.h"
10 
11 using namespace WelsVP;
12 
13 #define ASSERT_MEMORY_FAIL2X(A, B)     \
14   if (NULL == B) {                     \
15   delete []A;\
16   ASSERT_TRUE(0);                    \
17   }
18 
TEST(ScrollDetectionTest,TestScroll)19 TEST (ScrollDetectionTest, TestScroll) {
20   unsigned char* pSrc, *pRef;
21   int iWidthSets[4] = {640, 1024, 1280, 1980};
22   int iHeightSets[4] = {360, 768, 720, 1080};
23   int iStride = 0;
24 
25   for (int i = 0; i < 4; i++) {
26     int iWidth = iWidthSets[i];
27     int iHeight = iHeightSets[i];
28     iStride = iWidth + 16;
29     pSrc = new unsigned char[iHeight * iStride];
30     ASSERT_TRUE (NULL != pSrc);
31     pRef = new unsigned char[iHeight * iStride];
32     ASSERT_MEMORY_FAIL2X (pSrc, pRef)
33     RandomPixelDataGenerator (pRef, iWidth, iHeight, iStride);
34 
35     int iMvRange = iHeight / 3;
36     int iScrollMv = rand() % (iMvRange << 1) - iMvRange;
37     unsigned char* pSrcTmp = pSrc;
38     unsigned char* pRefTmp = pRef;
39 
40     for (int j = 0; j < iHeight; j++) {
41       if ((j + iScrollMv) >= 0 && (j + iScrollMv) < iHeight)
42         for (int i = 0; i < iWidth; i++) {
43           memcpy (pSrcTmp , &pRefTmp[ (j + iScrollMv)*iStride], iWidth * sizeof (unsigned char));
44         }
45       else {
46         for (int i = 0; i < iWidth; i++)
47           pSrcTmp[i] = rand() % 256;
48       }
49       pSrcTmp += iStride;
50     }
51 
52 
53     SPixMap sSrcMap = { { 0 } };
54     SPixMap sRefMap = { { 0 } };
55 
56     sSrcMap.pPixel[0] = pSrc;
57     sRefMap.pPixel[0] = pRef;
58     sSrcMap.iStride[0] = sRefMap.iStride[0] = iStride;
59     sSrcMap.sRect.iRectWidth = sRefMap.sRect.iRectWidth = iWidth;
60     sSrcMap.sRect.iRectHeight = sRefMap.sRect.iRectHeight = iHeight;
61 
62     SScrollDetectionParam sScrollDetectionResult;
63     WelsMemset (&sScrollDetectionResult, 0, sizeof (sScrollDetectionResult));
64     int iCoreNum = 1;
65     unsigned int uiCPUFlag = WelsCPUFeatureDetect (&iCoreNum);
66 
67     CScrollDetection* pTest = new CScrollDetection (uiCPUFlag);
68     int iMethodIdx = METHOD_SCROLL_DETECTION;
69 
70     pTest->Set (iMethodIdx, (&sScrollDetectionResult));
71     int ret = pTest->Process (iMethodIdx, &sSrcMap, &sRefMap);
72     EXPECT_EQ (ret, 0);
73     pTest->Get (iMethodIdx, (&sScrollDetectionResult));
74 
75     EXPECT_EQ (sScrollDetectionResult.bScrollDetectFlag, true);
76     EXPECT_EQ (sScrollDetectionResult.iScrollMvY, iScrollMv);
77 
78     delete pTest;
79     delete []pSrc;
80     delete []pRef;
81   }
82 }
83