• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2009-2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  *
32  * \file    sample.c
33  *
34  * \brief   compute SAD and SATD
35  *
36  * \date    2009.06.02 Created
37  *
38  *************************************************************************************
39  */
40 
41 #include "sad_common.h"
42 #include "macros.h"
43 
WelsSampleSad4x4_c(uint8_t * pSample1,int32_t iStride1,uint8_t * pSample2,int32_t iStride2)44 int32_t WelsSampleSad4x4_c (uint8_t* pSample1, int32_t iStride1, uint8_t* pSample2, int32_t iStride2) {
45   int32_t iSadSum = 0;
46   int32_t i = 0;
47   uint8_t* pSrc1 = pSample1;
48   uint8_t* pSrc2 = pSample2;
49   for (i = 0; i < 4; i++) {
50     iSadSum += WELS_ABS ((pSrc1[0] - pSrc2[0]));
51     iSadSum += WELS_ABS ((pSrc1[1] - pSrc2[1]));
52     iSadSum += WELS_ABS ((pSrc1[2] - pSrc2[2]));
53     iSadSum += WELS_ABS ((pSrc1[3] - pSrc2[3]));
54 
55     pSrc1 += iStride1;
56     pSrc2 += iStride2;
57   }
58 
59   return iSadSum;
60 }
61 
WelsSampleSad8x4_c(uint8_t * pSample1,int32_t iStride1,uint8_t * pSample2,int32_t iStride2)62 int32_t WelsSampleSad8x4_c (uint8_t* pSample1, int32_t iStride1, uint8_t* pSample2, int32_t iStride2) {
63   int32_t iSadSum = 0;
64   iSadSum += WelsSampleSad4x4_c (pSample1,     iStride1, pSample2,     iStride2);
65   iSadSum += WelsSampleSad4x4_c (pSample1 + 4, iStride1, pSample2 + 4, iStride2);
66   return iSadSum;
67 }
68 
WelsSampleSad4x8_c(uint8_t * pSample1,int32_t iStride1,uint8_t * pSample2,int32_t iStride2)69 int32_t WelsSampleSad4x8_c (uint8_t* pSample1, int32_t iStride1, uint8_t* pSample2, int32_t iStride2) {
70   int32_t iSadSum = 0;
71   iSadSum += WelsSampleSad4x4_c (pSample1,                   iStride1, pSample2,                   iStride2);
72   iSadSum += WelsSampleSad4x4_c (pSample1 + (iStride1 << 2), iStride1, pSample2 + (iStride2 << 2), iStride2);
73   return iSadSum;
74 }
75 
WelsSampleSad8x8_c(uint8_t * pSample1,int32_t iStride1,uint8_t * pSample2,int32_t iStride2)76 int32_t WelsSampleSad8x8_c (uint8_t* pSample1, int32_t iStride1, uint8_t* pSample2, int32_t iStride2) {
77   int32_t iSadSum = 0;
78   int32_t i = 0;
79   uint8_t* pSrc1 = pSample1;
80   uint8_t* pSrc2 = pSample2;
81   for (i = 0; i < 8; i++) {
82     iSadSum += WELS_ABS ((pSrc1[0] - pSrc2[0]));
83     iSadSum += WELS_ABS ((pSrc1[1] - pSrc2[1]));
84     iSadSum += WELS_ABS ((pSrc1[2] - pSrc2[2]));
85     iSadSum += WELS_ABS ((pSrc1[3] - pSrc2[3]));
86     iSadSum += WELS_ABS ((pSrc1[4] - pSrc2[4]));
87     iSadSum += WELS_ABS ((pSrc1[5] - pSrc2[5]));
88     iSadSum += WELS_ABS ((pSrc1[6] - pSrc2[6]));
89     iSadSum += WELS_ABS ((pSrc1[7] - pSrc2[7]));
90 
91     pSrc1 += iStride1;
92     pSrc2 += iStride2;
93   }
94 
95   return iSadSum;
96 }
WelsSampleSad16x8_c(uint8_t * pSample1,int32_t iStride1,uint8_t * pSample2,int32_t iStride2)97 int32_t WelsSampleSad16x8_c (uint8_t* pSample1, int32_t iStride1, uint8_t* pSample2, int32_t iStride2) {
98   int32_t iSadSum = 0;
99 
100   iSadSum += WelsSampleSad8x8_c (pSample1,     iStride1, pSample2,     iStride2);
101   iSadSum += WelsSampleSad8x8_c (pSample1 + 8, iStride1, pSample2 + 8, iStride2);
102 
103   return iSadSum;
104 }
WelsSampleSad8x16_c(uint8_t * pSample1,int32_t iStride1,uint8_t * pSample2,int32_t iStride2)105 int32_t WelsSampleSad8x16_c (uint8_t* pSample1, int32_t iStride1, uint8_t* pSample2, int32_t iStride2) {
106   int32_t iSadSum = 0;
107   iSadSum += WelsSampleSad8x8_c (pSample1,                   iStride1, pSample2,                   iStride2);
108   iSadSum += WelsSampleSad8x8_c (pSample1 + (iStride1 << 3), iStride1, pSample2 + (iStride2 << 3), iStride2);
109 
110   return iSadSum;
111 }
WelsSampleSad16x16_c(uint8_t * pSample1,int32_t iStride1,uint8_t * pSample2,int32_t iStride2)112 int32_t WelsSampleSad16x16_c (uint8_t* pSample1, int32_t iStride1, uint8_t* pSample2, int32_t iStride2) {
113   int32_t iSadSum = 0;
114   iSadSum += WelsSampleSad8x8_c (pSample1,                     iStride1, pSample2,                     iStride2);
115   iSadSum += WelsSampleSad8x8_c (pSample1 + 8,                   iStride1, pSample2 + 8,                   iStride2);
116   iSadSum += WelsSampleSad8x8_c (pSample1 + (iStride1 << 3),   iStride1, pSample2 + (iStride2 << 3),   iStride2);
117   iSadSum += WelsSampleSad8x8_c (pSample1 + (iStride1 << 3) + 8, iStride1, pSample2 + (iStride2 << 3) + 8, iStride2);
118 
119   return iSadSum;
120 }
121 
WelsSampleSadFour16x16_c(uint8_t * iSample1,int32_t iStride1,uint8_t * iSample2,int32_t iStride2,int32_t * pSad)122 void WelsSampleSadFour16x16_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2,
123                                int32_t* pSad) {
124   * (pSad)     = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
125   * (pSad + 1) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
126   * (pSad + 2) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 - 1), iStride2);
127   * (pSad + 3) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 + 1), iStride2);
128 }
WelsSampleSadFour16x8_c(uint8_t * iSample1,int32_t iStride1,uint8_t * iSample2,int32_t iStride2,int32_t * pSad)129 void WelsSampleSadFour16x8_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
130   * (pSad)     = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
131   * (pSad + 1) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
132   * (pSad + 2) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 - 1), iStride2);
133   * (pSad + 3) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 + 1), iStride2);
134 }
WelsSampleSadFour8x16_c(uint8_t * iSample1,int32_t iStride1,uint8_t * iSample2,int32_t iStride2,int32_t * pSad)135 void WelsSampleSadFour8x16_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
136   * (pSad)     = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
137   * (pSad + 1) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
138   * (pSad + 2) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 - 1), iStride2);
139   * (pSad + 3) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 + 1), iStride2);
140 
141 }
WelsSampleSadFour8x8_c(uint8_t * iSample1,int32_t iStride1,uint8_t * iSample2,int32_t iStride2,int32_t * pSad)142 void WelsSampleSadFour8x8_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
143   * (pSad)     = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
144   * (pSad + 1) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
145   * (pSad + 2) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 - 1), iStride2);
146   * (pSad + 3) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 + 1), iStride2);
147 }
WelsSampleSadFour4x4_c(uint8_t * iSample1,int32_t iStride1,uint8_t * iSample2,int32_t iStride2,int32_t * pSad)148 void WelsSampleSadFour4x4_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
149   * (pSad)     = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
150   * (pSad + 1) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
151   * (pSad + 2) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 - 1), iStride2);
152   * (pSad + 3) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 + 1), iStride2);
153 }
WelsSampleSadFour8x4_c(uint8_t * iSample1,int32_t iStride1,uint8_t * iSample2,int32_t iStride2,int32_t * pSad)154 void WelsSampleSadFour8x4_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
155   * (pSad)     = WelsSampleSad8x4_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
156   * (pSad + 1) = WelsSampleSad8x4_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
157   * (pSad + 2) = WelsSampleSad8x4_c (iSample1, iStride1, (iSample2 - 1), iStride2);
158   * (pSad + 3) = WelsSampleSad8x4_c (iSample1, iStride1, (iSample2 + 1), iStride2);
159 }
WelsSampleSadFour4x8_c(uint8_t * iSample1,int32_t iStride1,uint8_t * iSample2,int32_t iStride2,int32_t * pSad)160 void WelsSampleSadFour4x8_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
161   * (pSad)     = WelsSampleSad4x8_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
162   * (pSad + 1) = WelsSampleSad4x8_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
163   * (pSad + 2) = WelsSampleSad4x8_c (iSample1, iStride1, (iSample2 - 1), iStride2);
164   * (pSad + 3) = WelsSampleSad4x8_c (iSample1, iStride1, (iSample2 + 1), iStride2);
165 }
166