• 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 "util.h"
7 #include "macros.h"
8 #include "IWelsVP.h"
9 #include "AdaptiveQuantization.h"
10 
11 
12 using namespace WelsVP;
13 
FillWithRandomData(uint8_t * p,int32_t Len)14 static void FillWithRandomData (uint8_t* p, int32_t Len) {
15   for (int32_t i = 0; i < Len; i++) {
16     p[i] = rand() % 256;
17   }
18 }
19 
SampleVariance16x16_ref(uint8_t * pRefY,int32_t iRefStride,uint8_t * pSrcY,int32_t iSrcStride,SMotionTextureUnit * pMotionTexture)20 void SampleVariance16x16_ref (uint8_t* pRefY, int32_t iRefStride, uint8_t* pSrcY, int32_t iSrcStride,
21                               SMotionTextureUnit* pMotionTexture) {
22   uint32_t uiCurSquare = 0,  uiSquare = 0;
23   uint16_t uiCurSum = 0,  uiSum = 0;
24 
25   for (int32_t y = 0; y < MB_WIDTH_LUMA; y++) {
26     for (int32_t x = 0; x < MB_WIDTH_LUMA; x++) {
27       uint32_t uiDiff = WELS_ABS (pRefY[x] - pSrcY[x]);
28       uiSum += uiDiff;
29       uiSquare += uiDiff * uiDiff;
30 
31       uiCurSum += pSrcY[x];
32       uiCurSquare += pSrcY[x] * pSrcY[x];
33     }
34     pRefY += iRefStride;
35     pSrcY += iSrcStride;
36   }
37 
38   uiSum = uiSum >> 8;
39   pMotionTexture->uiMotionIndex = (uiSquare >> 8) - (uiSum * uiSum);
40 
41   uiCurSum = uiCurSum >> 8;
42   pMotionTexture->uiTextureIndex = (uiCurSquare >> 8) - (uiCurSum * uiCurSum);
43 }
44 
45 #define GENERATE_AQTEST(method, flag) \
46 TEST (AdaptiveQuantization, method) {\
47   uint32_t uiCPUFlags = WelsCPUFeatureDetect(NULL); \
48   if ((uiCPUFlags & flag) == 0 && flag != 0) \
49     return; \
50   ENFORCE_STACK_ALIGN_1D (uint8_t, pRefY,32*16,16)\
51   ENFORCE_STACK_ALIGN_1D (uint8_t, pSrcY,48*16,16)\
52   SMotionTextureUnit pMotionTexture[2];\
53   FillWithRandomData (pRefY,32*16);\
54   FillWithRandomData (pSrcY,48*16);\
55   SampleVariance16x16_ref (pRefY,32,pSrcY,48,&pMotionTexture[0]);\
56   method(pRefY,32,pSrcY,48,&pMotionTexture[1]);\
57   ASSERT_EQ(pMotionTexture[0].uiMotionIndex,pMotionTexture[1].uiMotionIndex);\
58   ASSERT_EQ(pMotionTexture[0].uiMotionIndex,pMotionTexture[1].uiMotionIndex);\
59   memset (pRefY,0,32*16);\
60   memset (pSrcY,255,48*16);\
61   SampleVariance16x16_ref (pRefY,32,pSrcY,48,&pMotionTexture[0]);\
62   method(pRefY,32,pSrcY,48,&pMotionTexture[1]);\
63   ASSERT_EQ(pMotionTexture[0].uiMotionIndex,pMotionTexture[1].uiMotionIndex);\
64   ASSERT_EQ(pMotionTexture[0].uiMotionIndex,pMotionTexture[1].uiMotionIndex);\
65 }
66 
67 GENERATE_AQTEST (SampleVariance16x16_c, 0)
68 #if defined(X86_ASM)
69 GENERATE_AQTEST (SampleVariance16x16_sse2, WELS_CPU_SSE2)
70 #endif
71 
72 #if defined(HAVE_NEON)
73 GENERATE_AQTEST (SampleVariance16x16_neon, WELS_CPU_NEON)
74 #endif
75 
76 #if defined(HAVE_NEON_AARCH64)
77 GENERATE_AQTEST (SampleVariance16x16_AArch64_neon, WELS_CPU_NEON)
78 #endif
79 
80