OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include <stdlib.h> | |
12 | |
13 #include "./vp9_rtcd.h" | |
14 #include "./vpx_config.h" | |
15 | |
16 #include "vpx/vpx_integer.h" | |
17 #if CONFIG_VP9_HIGHBITDEPTH | |
18 #include "vp9/common/vp9_common.h" | |
19 #endif | |
20 #include "vp9/encoder/vp9_variance.h" | |
21 | |
22 static INLINE unsigned int sad(const uint8_t *a, int a_stride, | |
23 const uint8_t *b, int b_stride, | |
24 int width, int height) { | |
25 int y, x; | |
26 unsigned int sad = 0; | |
27 | |
28 for (y = 0; y < height; y++) { | |
29 for (x = 0; x < width; x++) | |
30 sad += abs(a[x] - b[x]); | |
31 | |
32 a += a_stride; | |
33 b += b_stride; | |
34 } | |
35 return sad; | |
36 } | |
37 | |
38 #define sadMxN(m, n) \ | |
39 unsigned int vp9_sad##m##x##n##_c(const uint8_t *src, int src_stride, \ | |
40 const uint8_t *ref, int ref_stride) { \ | |
41 return sad(src, src_stride, ref, ref_stride, m, n); \ | |
42 } \ | |
43 unsigned int vp9_sad##m##x##n##_avg_c(const uint8_t *src, int src_stride, \ | |
44 const uint8_t *ref, int ref_stride, \ | |
45 const uint8_t *second_pred) { \ | |
46 uint8_t comp_pred[m * n]; \ | |
47 vp9_comp_avg_pred(comp_pred, second_pred, m, n, ref, ref_stride); \ | |
48 return sad(src, src_stride, comp_pred, m, m, n); \ | |
49 } | |
50 | |
51 #define sadMxNxK(m, n, k) \ | |
52 void vp9_sad##m##x##n##x##k##_c(const uint8_t *src, int src_stride, \ | |
53 const uint8_t *ref, int ref_stride, \ | |
54 unsigned int *sads) { \ | |
55 int i; \ | |
56 for (i = 0; i < k; ++i) \ | |
57 sads[i] = vp9_sad##m##x##n##_c(src, src_stride, &ref[i], ref_stride); \ | |
58 } | |
59 | |
60 #define sadMxNx4D(m, n) \ | |
61 void vp9_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \ | |
62 const uint8_t *const refs[], int ref_stride, \ | |
63 unsigned int *sads) { \ | |
64 int i; \ | |
65 for (i = 0; i < 4; ++i) \ | |
66 sads[i] = vp9_sad##m##x##n##_c(src, src_stride, refs[i], ref_stride); \ | |
67 } | |
68 | |
69 // 64x64 | |
70 sadMxN(64, 64) | |
71 sadMxNxK(64, 64, 3) | |
72 sadMxNxK(64, 64, 8) | |
73 sadMxNx4D(64, 64) | |
74 | |
75 // 64x32 | |
76 sadMxN(64, 32) | |
77 sadMxNx4D(64, 32) | |
78 | |
79 // 32x64 | |
80 sadMxN(32, 64) | |
81 sadMxNx4D(32, 64) | |
82 | |
83 // 32x32 | |
84 sadMxN(32, 32) | |
85 sadMxNxK(32, 32, 3) | |
86 sadMxNxK(32, 32, 8) | |
87 sadMxNx4D(32, 32) | |
88 | |
89 // 32x16 | |
90 sadMxN(32, 16) | |
91 sadMxNx4D(32, 16) | |
92 | |
93 // 16x32 | |
94 sadMxN(16, 32) | |
95 sadMxNx4D(16, 32) | |
96 | |
97 // 16x16 | |
98 sadMxN(16, 16) | |
99 sadMxNxK(16, 16, 3) | |
100 sadMxNxK(16, 16, 8) | |
101 sadMxNx4D(16, 16) | |
102 | |
103 // 16x8 | |
104 sadMxN(16, 8) | |
105 sadMxNxK(16, 8, 3) | |
106 sadMxNxK(16, 8, 8) | |
107 sadMxNx4D(16, 8) | |
108 | |
109 // 8x16 | |
110 sadMxN(8, 16) | |
111 sadMxNxK(8, 16, 3) | |
112 sadMxNxK(8, 16, 8) | |
113 sadMxNx4D(8, 16) | |
114 | |
115 // 8x8 | |
116 sadMxN(8, 8) | |
117 sadMxNxK(8, 8, 3) | |
118 sadMxNxK(8, 8, 8) | |
119 sadMxNx4D(8, 8) | |
120 | |
121 // 8x4 | |
122 sadMxN(8, 4) | |
123 sadMxNxK(8, 4, 8) | |
124 sadMxNx4D(8, 4) | |
125 | |
126 // 4x8 | |
127 sadMxN(4, 8) | |
128 sadMxNxK(4, 8, 8) | |
129 sadMxNx4D(4, 8) | |
130 | |
131 // 4x4 | |
132 sadMxN(4, 4) | |
133 sadMxNxK(4, 4, 3) | |
134 sadMxNxK(4, 4, 8) | |
135 sadMxNx4D(4, 4) | |
136 | |
137 #if CONFIG_VP9_HIGHBITDEPTH | |
138 static INLINE unsigned int highbd_sad(const uint8_t *a8, int a_stride, | |
139 const uint8_t *b8, int b_stride, | |
140 int width, int height) { | |
141 int y, x; | |
142 unsigned int sad = 0; | |
143 const uint16_t *a = CONVERT_TO_SHORTPTR(a8); | |
144 const uint16_t *b = CONVERT_TO_SHORTPTR(b8); | |
145 for (y = 0; y < height; y++) { | |
146 for (x = 0; x < width; x++) | |
147 sad += abs(a[x] - b[x]); | |
148 | |
149 a += a_stride; | |
150 b += b_stride; | |
151 } | |
152 return sad; | |
153 } | |
154 | |
155 static INLINE unsigned int highbd_sadb(const uint8_t *a8, int a_stride, | |
156 const uint16_t *b, int b_stride, | |
157 int width, int height) { | |
158 int y, x; | |
159 unsigned int sad = 0; | |
160 const uint16_t *a = CONVERT_TO_SHORTPTR(a8); | |
161 for (y = 0; y < height; y++) { | |
162 for (x = 0; x < width; x++) | |
163 sad += abs(a[x] - b[x]); | |
164 | |
165 a += a_stride; | |
166 b += b_stride; | |
167 } | |
168 return sad; | |
169 } | |
170 | |
171 #define highbd_sadMxN(m, n) \ | |
172 unsigned int vp9_highbd_sad##m##x##n##_c(const uint8_t *src, int src_stride, \ | |
173 const uint8_t *ref, int ref_stride) { \ | |
174 return highbd_sad(src, src_stride, ref, ref_stride, m, n); \ | |
175 } \ | |
176 unsigned int vp9_highbd_sad##m##x##n##_avg_c(const uint8_t *src, \ | |
177 int src_stride, \ | |
178 const uint8_t *ref, \ | |
179 int ref_stride, \ | |
180 const uint8_t *second_pred) { \ | |
181 uint16_t comp_pred[m * n]; \ | |
182 vp9_highbd_comp_avg_pred(comp_pred, second_pred, m, n, ref, ref_stride); \ | |
183 return highbd_sadb(src, src_stride, comp_pred, m, m, n); \ | |
184 } | |
185 | |
186 #define highbd_sadMxNxK(m, n, k) \ | |
187 void vp9_highbd_sad##m##x##n##x##k##_c(const uint8_t *src, int src_stride, \ | |
188 const uint8_t *ref, int ref_stride, \ | |
189 unsigned int *sads) { \ | |
190 int i; \ | |
191 for (i = 0; i < k; ++i) { \ | |
192 sads[i] = vp9_highbd_sad##m##x##n##_c(src, src_stride, &ref[i], \ | |
193 ref_stride); \ | |
194 } \ | |
195 } | |
196 | |
197 #define highbd_sadMxNx4D(m, n) \ | |
198 void vp9_highbd_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \ | |
199 const uint8_t *const refs[], \ | |
200 int ref_stride, unsigned int *sads) { \ | |
201 int i; \ | |
202 for (i = 0; i < 4; ++i) { \ | |
203 sads[i] = vp9_highbd_sad##m##x##n##_c(src, src_stride, refs[i], \ | |
204 ref_stride); \ | |
205 } \ | |
206 } | |
207 | |
208 // 64x64 | |
209 highbd_sadMxN(64, 64) | |
210 highbd_sadMxNxK(64, 64, 3) | |
211 highbd_sadMxNxK(64, 64, 8) | |
212 highbd_sadMxNx4D(64, 64) | |
213 | |
214 // 64x32 | |
215 highbd_sadMxN(64, 32) | |
216 highbd_sadMxNx4D(64, 32) | |
217 | |
218 // 32x64 | |
219 highbd_sadMxN(32, 64) | |
220 highbd_sadMxNx4D(32, 64) | |
221 | |
222 // 32x32 | |
223 highbd_sadMxN(32, 32) | |
224 highbd_sadMxNxK(32, 32, 3) | |
225 highbd_sadMxNxK(32, 32, 8) | |
226 highbd_sadMxNx4D(32, 32) | |
227 | |
228 // 32x16 | |
229 highbd_sadMxN(32, 16) | |
230 highbd_sadMxNx4D(32, 16) | |
231 | |
232 // 16x32 | |
233 highbd_sadMxN(16, 32) | |
234 highbd_sadMxNx4D(16, 32) | |
235 | |
236 // 16x16 | |
237 highbd_sadMxN(16, 16) | |
238 highbd_sadMxNxK(16, 16, 3) | |
239 highbd_sadMxNxK(16, 16, 8) | |
240 highbd_sadMxNx4D(16, 16) | |
241 | |
242 // 16x8 | |
243 highbd_sadMxN(16, 8) | |
244 highbd_sadMxNxK(16, 8, 3) | |
245 highbd_sadMxNxK(16, 8, 8) | |
246 highbd_sadMxNx4D(16, 8) | |
247 | |
248 // 8x16 | |
249 highbd_sadMxN(8, 16) | |
250 highbd_sadMxNxK(8, 16, 3) | |
251 highbd_sadMxNxK(8, 16, 8) | |
252 highbd_sadMxNx4D(8, 16) | |
253 | |
254 // 8x8 | |
255 highbd_sadMxN(8, 8) | |
256 highbd_sadMxNxK(8, 8, 3) | |
257 highbd_sadMxNxK(8, 8, 8) | |
258 highbd_sadMxNx4D(8, 8) | |
259 | |
260 // 8x4 | |
261 highbd_sadMxN(8, 4) | |
262 highbd_sadMxNxK(8, 4, 8) | |
263 highbd_sadMxNx4D(8, 4) | |
264 | |
265 // 4x8 | |
266 highbd_sadMxN(4, 8) | |
267 highbd_sadMxNxK(4, 8, 8) | |
268 highbd_sadMxNx4D(4, 8) | |
269 | |
270 // 4x4 | |
271 highbd_sadMxN(4, 4) | |
272 highbd_sadMxNxK(4, 4, 3) | |
273 highbd_sadMxNxK(4, 4, 8) | |
274 highbd_sadMxNx4D(4, 4) | |
275 | |
276 #endif // CONFIG_VP9_HIGHBITDEPTH | |
OLD | NEW |