Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
view libavcodec/dsputil.c @ 9:ea1ba68cf0ed
update to match api changes + add sscc produced source
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Wed, 05 Jun 2013 14:43:26 +0200 |
| parents | |
| children |
line source
1 /*
2 * DSP utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
25 /**
26 * @file
27 * DSP utils
28 */
30 #include "libavutil/log.h"
31 #include "dsputil.h"
32 #include "simple_idct.h"
33 #include "mathops.h"
34 #include "config.h"
36 uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
37 uint32_t ff_squareTbl[512] = {0, };
39 const uint8_t ff_zigzag_direct[64] = {
40 0, 1, 8, 16, 9, 2, 3, 10,
41 17, 24, 32, 25, 18, 11, 4, 5,
42 12, 19, 26, 33, 40, 48, 41, 34,
43 27, 20, 13, 6, 7, 14, 21, 28,
44 35, 42, 49, 56, 57, 50, 43, 36,
45 29, 22, 15, 23, 30, 37, 44, 51,
46 58, 59, 52, 45, 38, 31, 39, 46,
47 53, 60, 61, 54, 47, 55, 62, 63
48 };
51 #define PIXOP2(OPNAME, OP) \
52 static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
53 int i;\
54 for(i=0; i<h; i++){\
55 OP(*((uint16_t*)(block )), AV_RN16(pixels ));\
56 pixels+=line_size;\
57 block +=line_size;\
58 }\
59 }\
60 static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
61 int i;\
62 for(i=0; i<h; i++){\
63 OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
64 pixels+=line_size;\
65 block +=line_size;\
66 }\
67 }\
68 static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
69 int i;\
70 for(i=0; i<h; i++){\
71 OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
72 OP(*((uint32_t*)(block+4)), AV_RN32(pixels+4));\
73 pixels+=line_size;\
74 block +=line_size;\
75 }\
76 }\
77 static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
78 OPNAME ## _pixels8_c(block, pixels, line_size, h);\
79 }\
80 \
81 static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
82 int src_stride1, int src_stride2, int h){\
83 int i;\
84 for(i=0; i<h; i++){\
85 uint32_t a,b;\
86 a= AV_RN32(&src1[i*src_stride1 ]);\
87 b= AV_RN32(&src2[i*src_stride2 ]);\
88 OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
89 a= AV_RN32(&src1[i*src_stride1+4]);\
90 b= AV_RN32(&src2[i*src_stride2+4]);\
91 OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
92 }\
93 }\
94 \
95 static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
96 int src_stride1, int src_stride2, int h){\
97 int i;\
98 for(i=0; i<h; i++){\
99 uint32_t a,b;\
100 a= AV_RN32(&src1[i*src_stride1 ]);\
101 b= AV_RN32(&src2[i*src_stride2 ]);\
102 OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
103 a= AV_RN32(&src1[i*src_stride1+4]);\
104 b= AV_RN32(&src2[i*src_stride2+4]);\
105 OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
106 }\
107 }\
108 \
109 static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
110 int src_stride1, int src_stride2, int h){\
111 int i;\
112 for(i=0; i<h; i++){\
113 uint32_t a,b;\
114 a= AV_RN32(&src1[i*src_stride1 ]);\
115 b= AV_RN32(&src2[i*src_stride2 ]);\
116 OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
117 }\
118 }\
119 \
120 static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
121 int src_stride1, int src_stride2, int h){\
122 int i;\
123 for(i=0; i<h; i++){\
124 uint32_t a,b;\
125 a= AV_RN16(&src1[i*src_stride1 ]);\
126 b= AV_RN16(&src2[i*src_stride2 ]);\
127 OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
128 }\
129 }\
130 \
131 static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
132 int src_stride1, int src_stride2, int h){\
133 OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
134 OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
135 }\
136 \
137 static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
138 int src_stride1, int src_stride2, int h){\
139 OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
140 OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
141 }\
142 \
143 static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
144 OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
145 }\
146 \
147 static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
148 OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
149 }\
150 \
151 static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
152 OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
153 }\
154 \
155 static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
156 OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
157 }\
158 \
159 static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
160 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
161 int i;\
162 for(i=0; i<h; i++){\
163 uint32_t a, b, c, d, l0, l1, h0, h1;\
164 a= AV_RN32(&src1[i*src_stride1]);\
165 b= AV_RN32(&src2[i*src_stride2]);\
166 c= AV_RN32(&src3[i*src_stride3]);\
167 d= AV_RN32(&src4[i*src_stride4]);\
168 l0= (a&0x03030303UL)\
169 + (b&0x03030303UL)\
170 + 0x02020202UL;\
171 h0= ((a&0xFCFCFCFCUL)>>2)\
172 + ((b&0xFCFCFCFCUL)>>2);\
173 l1= (c&0x03030303UL)\
174 + (d&0x03030303UL);\
175 h1= ((c&0xFCFCFCFCUL)>>2)\
176 + ((d&0xFCFCFCFCUL)>>2);\
177 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
178 a= AV_RN32(&src1[i*src_stride1+4]);\
179 b= AV_RN32(&src2[i*src_stride2+4]);\
180 c= AV_RN32(&src3[i*src_stride3+4]);\
181 d= AV_RN32(&src4[i*src_stride4+4]);\
182 l0= (a&0x03030303UL)\
183 + (b&0x03030303UL)\
184 + 0x02020202UL;\
185 h0= ((a&0xFCFCFCFCUL)>>2)\
186 + ((b&0xFCFCFCFCUL)>>2);\
187 l1= (c&0x03030303UL)\
188 + (d&0x03030303UL);\
189 h1= ((c&0xFCFCFCFCUL)>>2)\
190 + ((d&0xFCFCFCFCUL)>>2);\
191 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
192 }\
193 }\
194 \
195 static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
196 OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
197 }\
198 \
199 static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
200 OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
201 }\
202 \
203 static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
204 OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
205 }\
206 \
207 static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
208 OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
209 }\
210 \
211 static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
212 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
213 int i;\
214 for(i=0; i<h; i++){\
215 uint32_t a, b, c, d, l0, l1, h0, h1;\
216 a= AV_RN32(&src1[i*src_stride1]);\
217 b= AV_RN32(&src2[i*src_stride2]);\
218 c= AV_RN32(&src3[i*src_stride3]);\
219 d= AV_RN32(&src4[i*src_stride4]);\
220 l0= (a&0x03030303UL)\
221 + (b&0x03030303UL)\
222 + 0x01010101UL;\
223 h0= ((a&0xFCFCFCFCUL)>>2)\
224 + ((b&0xFCFCFCFCUL)>>2);\
225 l1= (c&0x03030303UL)\
226 + (d&0x03030303UL);\
227 h1= ((c&0xFCFCFCFCUL)>>2)\
228 + ((d&0xFCFCFCFCUL)>>2);\
229 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
230 a= AV_RN32(&src1[i*src_stride1+4]);\
231 b= AV_RN32(&src2[i*src_stride2+4]);\
232 c= AV_RN32(&src3[i*src_stride3+4]);\
233 d= AV_RN32(&src4[i*src_stride4+4]);\
234 l0= (a&0x03030303UL)\
235 + (b&0x03030303UL)\
236 + 0x01010101UL;\
237 h0= ((a&0xFCFCFCFCUL)>>2)\
238 + ((b&0xFCFCFCFCUL)>>2);\
239 l1= (c&0x03030303UL)\
240 + (d&0x03030303UL);\
241 h1= ((c&0xFCFCFCFCUL)>>2)\
242 + ((d&0xFCFCFCFCUL)>>2);\
243 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
244 }\
245 }\
246 static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
247 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
248 OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
249 OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
250 }\
251 static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
252 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
253 OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
254 OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
255 }\
256 \
257 static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
258 {\
259 int i, a0, b0, a1, b1;\
260 a0= pixels[0];\
261 b0= pixels[1] + 2;\
262 a0 += b0;\
263 b0 += pixels[2];\
264 \
265 pixels+=line_size;\
266 for(i=0; i<h; i+=2){\
267 a1= pixels[0];\
268 b1= pixels[1];\
269 a1 += b1;\
270 b1 += pixels[2];\
271 \
272 block[0]= (a1+a0)>>2; /* FIXME non put */\
273 block[1]= (b1+b0)>>2;\
274 \
275 pixels+=line_size;\
276 block +=line_size;\
277 \
278 a0= pixels[0];\
279 b0= pixels[1] + 2;\
280 a0 += b0;\
281 b0 += pixels[2];\
282 \
283 block[0]= (a1+a0)>>2;\
284 block[1]= (b1+b0)>>2;\
285 pixels+=line_size;\
286 block +=line_size;\
287 }\
288 }\
289 \
290 static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
291 {\
292 int i;\
293 const uint32_t a= AV_RN32(pixels );\
294 const uint32_t b= AV_RN32(pixels+1);\
295 uint32_t l0= (a&0x03030303UL)\
296 + (b&0x03030303UL)\
297 + 0x02020202UL;\
298 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
299 + ((b&0xFCFCFCFCUL)>>2);\
300 uint32_t l1,h1;\
301 \
302 pixels+=line_size;\
303 for(i=0; i<h; i+=2){\
304 uint32_t a= AV_RN32(pixels );\
305 uint32_t b= AV_RN32(pixels+1);\
306 l1= (a&0x03030303UL)\
307 + (b&0x03030303UL);\
308 h1= ((a&0xFCFCFCFCUL)>>2)\
309 + ((b&0xFCFCFCFCUL)>>2);\
310 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
311 pixels+=line_size;\
312 block +=line_size;\
313 a= AV_RN32(pixels );\
314 b= AV_RN32(pixels+1);\
315 l0= (a&0x03030303UL)\
316 + (b&0x03030303UL)\
317 + 0x02020202UL;\
318 h0= ((a&0xFCFCFCFCUL)>>2)\
319 + ((b&0xFCFCFCFCUL)>>2);\
320 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
321 pixels+=line_size;\
322 block +=line_size;\
323 }\
324 }\
325 \
326 static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
327 {\
328 int j;\
329 for(j=0; j<2; j++){\
330 int i;\
331 const uint32_t a= AV_RN32(pixels );\
332 const uint32_t b= AV_RN32(pixels+1);\
333 uint32_t l0= (a&0x03030303UL)\
334 + (b&0x03030303UL)\
335 + 0x02020202UL;\
336 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
337 + ((b&0xFCFCFCFCUL)>>2);\
338 uint32_t l1,h1;\
339 \
340 pixels+=line_size;\
341 for(i=0; i<h; i+=2){\
342 uint32_t a= AV_RN32(pixels );\
343 uint32_t b= AV_RN32(pixels+1);\
344 l1= (a&0x03030303UL)\
345 + (b&0x03030303UL);\
346 h1= ((a&0xFCFCFCFCUL)>>2)\
347 + ((b&0xFCFCFCFCUL)>>2);\
348 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
349 pixels+=line_size;\
350 block +=line_size;\
351 a= AV_RN32(pixels );\
352 b= AV_RN32(pixels+1);\
353 l0= (a&0x03030303UL)\
354 + (b&0x03030303UL)\
355 + 0x02020202UL;\
356 h0= ((a&0xFCFCFCFCUL)>>2)\
357 + ((b&0xFCFCFCFCUL)>>2);\
358 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
359 pixels+=line_size;\
360 block +=line_size;\
361 }\
362 pixels+=4-line_size*(h+1);\
363 block +=4-line_size*h;\
364 }\
365 }\
366 \
367 static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
368 {\
369 int j;\
370 for(j=0; j<2; j++){\
371 int i;\
372 const uint32_t a= AV_RN32(pixels );\
373 const uint32_t b= AV_RN32(pixels+1);\
374 uint32_t l0= (a&0x03030303UL)\
375 + (b&0x03030303UL)\
376 + 0x01010101UL;\
377 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
378 + ((b&0xFCFCFCFCUL)>>2);\
379 uint32_t l1,h1;\
380 \
381 pixels+=line_size;\
382 for(i=0; i<h; i+=2){\
383 uint32_t a= AV_RN32(pixels );\
384 uint32_t b= AV_RN32(pixels+1);\
385 l1= (a&0x03030303UL)\
386 + (b&0x03030303UL);\
387 h1= ((a&0xFCFCFCFCUL)>>2)\
388 + ((b&0xFCFCFCFCUL)>>2);\
389 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
390 pixels+=line_size;\
391 block +=line_size;\
392 a= AV_RN32(pixels );\
393 b= AV_RN32(pixels+1);\
394 l0= (a&0x03030303UL)\
395 + (b&0x03030303UL)\
396 + 0x01010101UL;\
397 h0= ((a&0xFCFCFCFCUL)>>2)\
398 + ((b&0xFCFCFCFCUL)>>2);\
399 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
400 pixels+=line_size;\
401 block +=line_size;\
402 }\
403 pixels+=4-line_size*(h+1);\
404 block +=4-line_size*h;\
405 }\
406 }\
407 \
408 CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
410 #define op_avg(a, b) a = rnd_avg32(a, b)
412 #define op_put(a, b) a = b
414 PIXOP2(avg, op_avg)
415 PIXOP2(put, op_put)
416 #undef op_avg
417 #undef op_put
420 #define H264_CHROMA_MC(OPNAME, OP)\
421 static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
422 const int A=(8-x)*(8-y);\
423 const int B=( x)*(8-y);\
424 const int C=(8-x)*( y);\
425 const int D=( x)*( y);\
426 int i;\
427 \
428 assert(x<8 && y<8 && x>=0 && y>=0);\
429 \
430 if(D){\
431 for(i=0; i<h; i++){\
432 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
433 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
434 dst+= stride;\
435 src+= stride;\
436 }\
437 }else{\
438 const int E= B+C;\
439 const int step= C ? stride : 1;\
440 for(i=0; i<h; i++){\
441 OP(dst[0], (A*src[0] + E*src[step+0]));\
442 OP(dst[1], (A*src[1] + E*src[step+1]));\
443 dst+= stride;\
444 src+= stride;\
445 }\
446 }\
447 }\
448 \
449 static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
450 const int A=(8-x)*(8-y);\
451 const int B=( x)*(8-y);\
452 const int C=(8-x)*( y);\
453 const int D=( x)*( y);\
454 int i;\
455 \
456 assert(x<8 && y<8 && x>=0 && y>=0);\
457 \
458 if(D){\
459 for(i=0; i<h; i++){\
460 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
461 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
462 OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
463 OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
464 dst+= stride;\
465 src+= stride;\
466 }\
467 }else{\
468 const int E= B+C;\
469 const int step= C ? stride : 1;\
470 for(i=0; i<h; i++){\
471 OP(dst[0], (A*src[0] + E*src[step+0]));\
472 OP(dst[1], (A*src[1] + E*src[step+1]));\
473 OP(dst[2], (A*src[2] + E*src[step+2]));\
474 OP(dst[3], (A*src[3] + E*src[step+3]));\
475 dst+= stride;\
476 src+= stride;\
477 }\
478 }\
479 }\
480 \
481 static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
482 const int A=(8-x)*(8-y);\
483 const int B=( x)*(8-y);\
484 const int C=(8-x)*( y);\
485 const int D=( x)*( y);\
486 int i;\
487 \
488 assert(x<8 && y<8 && x>=0 && y>=0);\
489 \
490 if(D){\
491 for(i=0; i<h; i++){\
492 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
493 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
494 OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
495 OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
496 OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
497 OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
498 OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
499 OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
500 dst+= stride;\
501 src+= stride;\
502 }\
503 }else{\
504 const int E= B+C;\
505 const int step= C ? stride : 1;\
506 for(i=0; i<h; i++){\
507 OP(dst[0], (A*src[0] + E*src[step+0]));\
508 OP(dst[1], (A*src[1] + E*src[step+1]));\
509 OP(dst[2], (A*src[2] + E*src[step+2]));\
510 OP(dst[3], (A*src[3] + E*src[step+3]));\
511 OP(dst[4], (A*src[4] + E*src[step+4]));\
512 OP(dst[5], (A*src[5] + E*src[step+5]));\
513 OP(dst[6], (A*src[6] + E*src[step+6]));\
514 OP(dst[7], (A*src[7] + E*src[step+7]));\
515 dst+= stride;\
516 src+= stride;\
517 }\
518 }\
519 }
521 #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
522 #define op_put(a, b) a = (((b) + 32)>>6)
524 H264_CHROMA_MC(put_ , op_put)
525 H264_CHROMA_MC(avg_ , op_avg)
526 #undef op_avg
527 #undef op_put
530 #define H264_LOWPASS(OPNAME, OP, OP2) \
531 static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
532 const int h=2;\
533 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
534 int i;\
535 for(i=0; i<h; i++)\
536 {\
537 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
538 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
539 dst+=dstStride;\
540 src+=srcStride;\
541 }\
542 }\
543 \
544 static av_unused void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
545 const int w=2;\
546 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
547 int i;\
548 for(i=0; i<w; i++)\
549 {\
550 const int srcB= src[-2*srcStride];\
551 const int srcA= src[-1*srcStride];\
552 const int src0= src[0 *srcStride];\
553 const int src1= src[1 *srcStride];\
554 const int src2= src[2 *srcStride];\
555 const int src3= src[3 *srcStride];\
556 const int src4= src[4 *srcStride];\
557 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
558 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
559 dst++;\
560 src++;\
561 }\
562 }\
563 \
564 static av_unused void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
565 const int h=2;\
566 const int w=2;\
567 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
568 int i;\
569 src -= 2*srcStride;\
570 for(i=0; i<h+5; i++)\
571 {\
572 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
573 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
574 tmp+=tmpStride;\
575 src+=srcStride;\
576 }\
577 tmp -= tmpStride*(h+5-2);\
578 for(i=0; i<w; i++)\
579 {\
580 const int tmpB= tmp[-2*tmpStride];\
581 const int tmpA= tmp[-1*tmpStride];\
582 const int tmp0= tmp[0 *tmpStride];\
583 const int tmp1= tmp[1 *tmpStride];\
584 const int tmp2= tmp[2 *tmpStride];\
585 const int tmp3= tmp[3 *tmpStride];\
586 const int tmp4= tmp[4 *tmpStride];\
587 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
588 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
589 dst++;\
590 tmp++;\
591 }\
592 }\
593 static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
594 const int h=4;\
595 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
596 int i;\
597 for(i=0; i<h; i++)\
598 {\
599 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
600 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
601 OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
602 OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
603 dst+=dstStride;\
604 src+=srcStride;\
605 }\
606 }\
607 \
608 static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
609 const int w=4;\
610 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
611 int i;\
612 for(i=0; i<w; i++)\
613 {\
614 const int srcB= src[-2*srcStride];\
615 const int srcA= src[-1*srcStride];\
616 const int src0= src[0 *srcStride];\
617 const int src1= src[1 *srcStride];\
618 const int src2= src[2 *srcStride];\
619 const int src3= src[3 *srcStride];\
620 const int src4= src[4 *srcStride];\
621 const int src5= src[5 *srcStride];\
622 const int src6= src[6 *srcStride];\
623 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
624 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
625 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
626 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
627 dst++;\
628 src++;\
629 }\
630 }\
631 \
632 static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
633 const int h=4;\
634 const int w=4;\
635 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
636 int i;\
637 src -= 2*srcStride;\
638 for(i=0; i<h+5; i++)\
639 {\
640 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
641 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
642 tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
643 tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
644 tmp+=tmpStride;\
645 src+=srcStride;\
646 }\
647 tmp -= tmpStride*(h+5-2);\
648 for(i=0; i<w; i++)\
649 {\
650 const int tmpB= tmp[-2*tmpStride];\
651 const int tmpA= tmp[-1*tmpStride];\
652 const int tmp0= tmp[0 *tmpStride];\
653 const int tmp1= tmp[1 *tmpStride];\
654 const int tmp2= tmp[2 *tmpStride];\
655 const int tmp3= tmp[3 *tmpStride];\
656 const int tmp4= tmp[4 *tmpStride];\
657 const int tmp5= tmp[5 *tmpStride];\
658 const int tmp6= tmp[6 *tmpStride];\
659 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
660 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
661 OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
662 OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
663 dst++;\
664 tmp++;\
665 }\
666 }\
667 \
668 static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
669 const int h=8;\
670 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
671 int i;\
672 for(i=0; i<h; i++)\
673 {\
674 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
675 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
676 OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
677 OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
678 OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
679 OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
680 OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
681 OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
682 dst+=dstStride;\
683 src+=srcStride;\
684 }\
685 }\
686 \
687 static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
688 const int w=8;\
689 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
690 int i;\
691 for(i=0; i<w; i++)\
692 {\
693 const int srcB= src[-2*srcStride];\
694 const int srcA= src[-1*srcStride];\
695 const int src0= src[0 *srcStride];\
696 const int src1= src[1 *srcStride];\
697 const int src2= src[2 *srcStride];\
698 const int src3= src[3 *srcStride];\
699 const int src4= src[4 *srcStride];\
700 const int src5= src[5 *srcStride];\
701 const int src6= src[6 *srcStride];\
702 const int src7= src[7 *srcStride];\
703 const int src8= src[8 *srcStride];\
704 const int src9= src[9 *srcStride];\
705 const int src10=src[10*srcStride];\
706 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
707 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
708 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
709 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
710 OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
711 OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
712 OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
713 OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
714 dst++;\
715 src++;\
716 }\
717 }\
718 \
719 static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
720 const int h=8;\
721 const int w=8;\
722 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
723 int i;\
724 src -= 2*srcStride;\
725 for(i=0; i<h+5; i++)\
726 {\
727 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
728 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
729 tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
730 tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
731 tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
732 tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
733 tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
734 tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
735 tmp+=tmpStride;\
736 src+=srcStride;\
737 }\
738 tmp -= tmpStride*(h+5-2);\
739 for(i=0; i<w; i++)\
740 {\
741 const int tmpB= tmp[-2*tmpStride];\
742 const int tmpA= tmp[-1*tmpStride];\
743 const int tmp0= tmp[0 *tmpStride];\
744 const int tmp1= tmp[1 *tmpStride];\
745 const int tmp2= tmp[2 *tmpStride];\
746 const int tmp3= tmp[3 *tmpStride];\
747 const int tmp4= tmp[4 *tmpStride];\
748 const int tmp5= tmp[5 *tmpStride];\
749 const int tmp6= tmp[6 *tmpStride];\
750 const int tmp7= tmp[7 *tmpStride];\
751 const int tmp8= tmp[8 *tmpStride];\
752 const int tmp9= tmp[9 *tmpStride];\
753 const int tmp10=tmp[10*tmpStride];\
754 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
755 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
756 OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
757 OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
758 OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
759 OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
760 OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
761 OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
762 dst++;\
763 tmp++;\
764 }\
765 }\
766 \
767 static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
768 OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
769 OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
770 src += 8*srcStride;\
771 dst += 8*dstStride;\
772 OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
773 OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
774 }\
775 \
776 static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
777 OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
778 OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
779 src += 8*srcStride;\
780 dst += 8*dstStride;\
781 OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
782 OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
783 }\
784 \
785 static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
786 OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
787 OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
788 src += 8*srcStride;\
789 dst += 8*dstStride;\
790 OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
791 OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
792 }\
794 #define H264_MC(OPNAME, SIZE) \
795 static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
796 OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
797 }\
798 \
799 static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
800 uint8_t half[SIZE*SIZE];\
801 put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
802 OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
803 }\
804 \
805 static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
806 OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
807 }\
808 \
809 static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
810 uint8_t half[SIZE*SIZE];\
811 put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
812 OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
813 }\
814 \
815 static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
816 uint8_t full[SIZE*(SIZE+5)];\
817 uint8_t * const full_mid= full + SIZE*2;\
818 uint8_t half[SIZE*SIZE];\
819 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
820 put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
821 OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
822 }\
823 \
824 static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
825 uint8_t full[SIZE*(SIZE+5)];\
826 uint8_t * const full_mid= full + SIZE*2;\
827 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
828 OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
829 }\
830 \
831 static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
832 uint8_t full[SIZE*(SIZE+5)];\
833 uint8_t * const full_mid= full + SIZE*2;\
834 uint8_t half[SIZE*SIZE];\
835 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
836 put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
837 OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
838 }\
839 \
840 static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
841 uint8_t full[SIZE*(SIZE+5)];\
842 uint8_t * const full_mid= full + SIZE*2;\
843 uint8_t halfH[SIZE*SIZE];\
844 uint8_t halfV[SIZE*SIZE];\
845 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
846 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
847 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
848 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
849 }\
850 \
851 static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
852 uint8_t full[SIZE*(SIZE+5)];\
853 uint8_t * const full_mid= full + SIZE*2;\
854 uint8_t halfH[SIZE*SIZE];\
855 uint8_t halfV[SIZE*SIZE];\
856 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
857 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
858 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
859 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
860 }\
861 \
862 static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
863 uint8_t full[SIZE*(SIZE+5)];\
864 uint8_t * const full_mid= full + SIZE*2;\
865 uint8_t halfH[SIZE*SIZE];\
866 uint8_t halfV[SIZE*SIZE];\
867 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
868 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
869 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
870 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
871 }\
872 \
873 static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
874 uint8_t full[SIZE*(SIZE+5)];\
875 uint8_t * const full_mid= full + SIZE*2;\
876 uint8_t halfH[SIZE*SIZE];\
877 uint8_t halfV[SIZE*SIZE];\
878 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
879 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
880 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
881 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
882 }\
883 \
884 static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
885 int16_t tmp[SIZE*(SIZE+5)];\
886 OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
887 }\
888 \
889 static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
890 int16_t tmp[SIZE*(SIZE+5)];\
891 uint8_t halfH[SIZE*SIZE];\
892 uint8_t halfHV[SIZE*SIZE];\
893 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
894 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
895 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
896 }\
897 \
898 static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
899 int16_t tmp[SIZE*(SIZE+5)];\
900 uint8_t halfH[SIZE*SIZE];\
901 uint8_t halfHV[SIZE*SIZE];\
902 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
903 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
904 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
905 }\
906 \
907 static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
908 uint8_t full[SIZE*(SIZE+5)];\
909 uint8_t * const full_mid= full + SIZE*2;\
910 int16_t tmp[SIZE*(SIZE+5)];\
911 uint8_t halfV[SIZE*SIZE];\
912 uint8_t halfHV[SIZE*SIZE];\
913 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
914 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
915 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
916 OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
917 }\
918 \
919 static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
920 uint8_t full[SIZE*(SIZE+5)];\
921 uint8_t * const full_mid= full + SIZE*2;\
922 int16_t tmp[SIZE*(SIZE+5)];\
923 uint8_t halfV[SIZE*SIZE];\
924 uint8_t halfHV[SIZE*SIZE];\
925 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
926 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
927 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
928 OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
929 }\
931 #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
932 #define op_put(a, b) a = cm[((b) + 16)>>5]
933 #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
934 #define op2_put(a, b) a = cm[((b) + 512)>>10]
936 H264_LOWPASS(put_ , op_put, op2_put)
937 H264_LOWPASS(avg_ , op_avg, op2_avg)
938 H264_MC(put_, 2)
939 H264_MC(put_, 4)
940 H264_MC(put_, 8)
941 H264_MC(put_, 16)
942 H264_MC(avg_, 4)
943 H264_MC(avg_, 8)
944 H264_MC(avg_, 16)
946 #undef op_avg
947 #undef op_put
948 #undef op2_avg
949 #undef op2_put
951 static void clear_block_c(DCTELEM *block)
952 {
953 memset(block, 0, sizeof(DCTELEM)*64);
954 }
956 /**
957 * memset(blocks, 0, sizeof(DCTELEM)*6*64)
958 */
959 static void clear_blocks_c(DCTELEM *blocks)
960 {
961 memset(blocks, 0, sizeof(DCTELEM)*6*64);
962 }
964 static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
966 /* init static data */
967 av_cold void dsputil_static_init(void)
968 {
969 int i;
971 for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
972 for(i=0;i<MAX_NEG_CROP;i++) {
973 ff_cropTbl[i] = 0;
974 ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
975 }
977 for(i=0;i<512;i++) {
978 ff_squareTbl[i] = (i - 256) * (i - 256);
979 }
980 }
982 int ff_check_alignment(void){
983 static int did_fail=0;
984 DECLARE_ALIGNED(16, int, aligned);
986 if((intptr_t)&aligned & 15){
987 if(!did_fail){
988 #if HAVE_MMX || HAVE_ALTIVEC
989 av_log(AV_LOG_ERROR,
990 "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
991 "and may be very slow or crash. This is not a bug in libavcodec,\n"
992 "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
993 "Do not report crashes to FFmpeg developers.\n");
994 #endif
995 did_fail=1;
996 }
997 return -1;
998 }
999 return 0;
1000 }
1002 av_cold void dsputil_init(DSPContext* c)
1003 {
1004 (void) avg_pixels2_c; // kill a warning, avg_pixels2_c is a macro created function.
1005 ff_check_alignment();
1006 dsputil_static_init();
1008 c->idct_put= ff_simple_idct_put;
1009 c->idct_add= ff_simple_idct_add;
1010 c->idct = ff_simple_idct;
1012 c->clear_block = clear_block_c;
1013 c->clear_blocks = clear_blocks_c;
1015 #define dspfunc(PFX, IDX, NUM) \
1016 c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
1017 c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
1018 c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
1019 c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
1020 c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
1021 c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
1022 c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
1023 c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
1024 c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
1025 c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
1026 c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
1027 c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
1028 c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
1029 c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
1030 c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
1031 c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
1034 dspfunc(put_h264_qpel, 0, 16);
1035 dspfunc(put_h264_qpel, 1, 8);
1036 dspfunc(put_h264_qpel, 2, 4);
1037 dspfunc(put_h264_qpel, 3, 2);
1038 dspfunc(avg_h264_qpel, 0, 16);
1039 dspfunc(avg_h264_qpel, 1, 8);
1040 dspfunc(avg_h264_qpel, 2, 4);
1042 #undef dspfunc
1043 c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
1044 c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
1045 c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
1046 c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
1047 c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
1048 c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
1051 c->prefetch= just_return;
1053 if (HAVE_MMX) dsputil_init_mmx (c);
1054 if (ARCH_ARM) dsputil_init_arm (c);
1055 if (HAVE_ALTIVEC) dsputil_init_ppc (c); //fixme PPC prefetch
1056 }
