]> git.sesse.net Git - ffmpeg/blob - libavcodec/h264qpel_template.c
Merge commit '75af13a'
[ffmpeg] / libavcodec / h264qpel_template.c
1 /*
2  * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
3  * Copyright (c) 2003-2010 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "libavutil/common.h"
23 #include "libavutil/intreadwrite.h"
24
25 #include "bit_depth_template.c"
26 #include "hpel_template.c"
27
28 static inline void FUNC(copy_block2)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
29 {
30     int i;
31     for(i=0; i<h; i++)
32     {
33         AV_WN2P(dst   , AV_RN2P(src   ));
34         dst+=dstStride;
35         src+=srcStride;
36     }
37 }
38
39 static inline void FUNC(copy_block4)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
40 {
41     int i;
42     for(i=0; i<h; i++)
43     {
44         AV_WN4P(dst   , AV_RN4P(src   ));
45         dst+=dstStride;
46         src+=srcStride;
47     }
48 }
49
50 static inline void FUNC(copy_block8)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
51 {
52     int i;
53     for(i=0; i<h; i++)
54     {
55         AV_WN4P(dst                , AV_RN4P(src                ));
56         AV_WN4P(dst+4*sizeof(pixel), AV_RN4P(src+4*sizeof(pixel)));
57         dst+=dstStride;
58         src+=srcStride;
59     }
60 }
61
62 static inline void FUNC(copy_block16)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
63 {
64     int i;
65     for(i=0; i<h; i++)
66     {
67         AV_WN4P(dst                 , AV_RN4P(src                 ));
68         AV_WN4P(dst+ 4*sizeof(pixel), AV_RN4P(src+ 4*sizeof(pixel)));
69         AV_WN4P(dst+ 8*sizeof(pixel), AV_RN4P(src+ 8*sizeof(pixel)));
70         AV_WN4P(dst+12*sizeof(pixel), AV_RN4P(src+12*sizeof(pixel)));
71         dst+=dstStride;
72         src+=srcStride;
73     }
74 }
75
76 #define H264_LOWPASS(OPNAME, OP, OP2) \
77 static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
78     const int h=2;\
79     INIT_CLIP\
80     int i;\
81     pixel *dst = (pixel*)p_dst;\
82     pixel *src = (pixel*)p_src;\
83     dstStride >>= sizeof(pixel)-1;\
84     srcStride >>= sizeof(pixel)-1;\
85     for(i=0; i<h; i++)\
86     {\
87         OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
88         OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
89         dst+=dstStride;\
90         src+=srcStride;\
91     }\
92 }\
93 \
94 static av_unused void FUNC(OPNAME ## h264_qpel2_v_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
95     const int w=2;\
96     INIT_CLIP\
97     int i;\
98     pixel *dst = (pixel*)p_dst;\
99     pixel *src = (pixel*)p_src;\
100     dstStride >>= sizeof(pixel)-1;\
101     srcStride >>= sizeof(pixel)-1;\
102     for(i=0; i<w; i++)\
103     {\
104         const int srcB= src[-2*srcStride];\
105         const int srcA= src[-1*srcStride];\
106         const int src0= src[0 *srcStride];\
107         const int src1= src[1 *srcStride];\
108         const int src2= src[2 *srcStride];\
109         const int src3= src[3 *srcStride];\
110         const int src4= src[4 *srcStride];\
111         OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
112         OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
113         dst++;\
114         src++;\
115     }\
116 }\
117 \
118 static av_unused void FUNC(OPNAME ## h264_qpel2_hv_lowpass)(uint8_t *p_dst, pixeltmp *tmp, uint8_t *p_src, int dstStride, int tmpStride, int srcStride){\
119     const int h=2;\
120     const int w=2;\
121     const int pad = (BIT_DEPTH == 10) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
122     INIT_CLIP\
123     int i;\
124     pixel *dst = (pixel*)p_dst;\
125     pixel *src = (pixel*)p_src;\
126     dstStride >>= sizeof(pixel)-1;\
127     srcStride >>= sizeof(pixel)-1;\
128     src -= 2*srcStride;\
129     for(i=0; i<h+5; i++)\
130     {\
131         tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]) + pad;\
132         tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]) + pad;\
133         tmp+=tmpStride;\
134         src+=srcStride;\
135     }\
136     tmp -= tmpStride*(h+5-2);\
137     for(i=0; i<w; i++)\
138     {\
139         const int tmpB= tmp[-2*tmpStride] - pad;\
140         const int tmpA= tmp[-1*tmpStride] - pad;\
141         const int tmp0= tmp[0 *tmpStride] - pad;\
142         const int tmp1= tmp[1 *tmpStride] - pad;\
143         const int tmp2= tmp[2 *tmpStride] - pad;\
144         const int tmp3= tmp[3 *tmpStride] - pad;\
145         const int tmp4= tmp[4 *tmpStride] - pad;\
146         OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
147         OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
148         dst++;\
149         tmp++;\
150     }\
151 }\
152 static void FUNC(OPNAME ## h264_qpel4_h_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
153     const int h=4;\
154     INIT_CLIP\
155     int i;\
156     pixel *dst = (pixel*)p_dst;\
157     pixel *src = (pixel*)p_src;\
158     dstStride >>= sizeof(pixel)-1;\
159     srcStride >>= sizeof(pixel)-1;\
160     for(i=0; i<h; i++)\
161     {\
162         OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
163         OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
164         OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
165         OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
166         dst+=dstStride;\
167         src+=srcStride;\
168     }\
169 }\
170 \
171 static void FUNC(OPNAME ## h264_qpel4_v_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
172     const int w=4;\
173     INIT_CLIP\
174     int i;\
175     pixel *dst = (pixel*)p_dst;\
176     pixel *src = (pixel*)p_src;\
177     dstStride >>= sizeof(pixel)-1;\
178     srcStride >>= sizeof(pixel)-1;\
179     for(i=0; i<w; i++)\
180     {\
181         const int srcB= src[-2*srcStride];\
182         const int srcA= src[-1*srcStride];\
183         const int src0= src[0 *srcStride];\
184         const int src1= src[1 *srcStride];\
185         const int src2= src[2 *srcStride];\
186         const int src3= src[3 *srcStride];\
187         const int src4= src[4 *srcStride];\
188         const int src5= src[5 *srcStride];\
189         const int src6= src[6 *srcStride];\
190         OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
191         OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
192         OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
193         OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
194         dst++;\
195         src++;\
196     }\
197 }\
198 \
199 static void FUNC(OPNAME ## h264_qpel4_hv_lowpass)(uint8_t *p_dst, pixeltmp *tmp, uint8_t *p_src, int dstStride, int tmpStride, int srcStride){\
200     const int h=4;\
201     const int w=4;\
202     const int pad = (BIT_DEPTH == 10) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
203     INIT_CLIP\
204     int i;\
205     pixel *dst = (pixel*)p_dst;\
206     pixel *src = (pixel*)p_src;\
207     dstStride >>= sizeof(pixel)-1;\
208     srcStride >>= sizeof(pixel)-1;\
209     src -= 2*srcStride;\
210     for(i=0; i<h+5; i++)\
211     {\
212         tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]) + pad;\
213         tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]) + pad;\
214         tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]) + pad;\
215         tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]) + pad;\
216         tmp+=tmpStride;\
217         src+=srcStride;\
218     }\
219     tmp -= tmpStride*(h+5-2);\
220     for(i=0; i<w; i++)\
221     {\
222         const int tmpB= tmp[-2*tmpStride] - pad;\
223         const int tmpA= tmp[-1*tmpStride] - pad;\
224         const int tmp0= tmp[0 *tmpStride] - pad;\
225         const int tmp1= tmp[1 *tmpStride] - pad;\
226         const int tmp2= tmp[2 *tmpStride] - pad;\
227         const int tmp3= tmp[3 *tmpStride] - pad;\
228         const int tmp4= tmp[4 *tmpStride] - pad;\
229         const int tmp5= tmp[5 *tmpStride] - pad;\
230         const int tmp6= tmp[6 *tmpStride] - pad;\
231         OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
232         OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
233         OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
234         OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
235         dst++;\
236         tmp++;\
237     }\
238 }\
239 \
240 static void FUNC(OPNAME ## h264_qpel8_h_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
241     const int h=8;\
242     INIT_CLIP\
243     int i;\
244     pixel *dst = (pixel*)p_dst;\
245     pixel *src = (pixel*)p_src;\
246     dstStride >>= sizeof(pixel)-1;\
247     srcStride >>= sizeof(pixel)-1;\
248     for(i=0; i<h; i++)\
249     {\
250         OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
251         OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
252         OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
253         OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
254         OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
255         OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
256         OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
257         OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
258         dst+=dstStride;\
259         src+=srcStride;\
260     }\
261 }\
262 \
263 static void FUNC(OPNAME ## h264_qpel8_v_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
264     const int w=8;\
265     INIT_CLIP\
266     int i;\
267     pixel *dst = (pixel*)p_dst;\
268     pixel *src = (pixel*)p_src;\
269     dstStride >>= sizeof(pixel)-1;\
270     srcStride >>= sizeof(pixel)-1;\
271     for(i=0; i<w; i++)\
272     {\
273         const int srcB= src[-2*srcStride];\
274         const int srcA= src[-1*srcStride];\
275         const int src0= src[0 *srcStride];\
276         const int src1= src[1 *srcStride];\
277         const int src2= src[2 *srcStride];\
278         const int src3= src[3 *srcStride];\
279         const int src4= src[4 *srcStride];\
280         const int src5= src[5 *srcStride];\
281         const int src6= src[6 *srcStride];\
282         const int src7= src[7 *srcStride];\
283         const int src8= src[8 *srcStride];\
284         const int src9= src[9 *srcStride];\
285         const int src10=src[10*srcStride];\
286         OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
287         OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
288         OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
289         OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
290         OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
291         OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
292         OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
293         OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
294         dst++;\
295         src++;\
296     }\
297 }\
298 \
299 static void FUNC(OPNAME ## h264_qpel8_hv_lowpass)(uint8_t *p_dst, pixeltmp *tmp, uint8_t *p_src, int dstStride, int tmpStride, int srcStride){\
300     const int h=8;\
301     const int w=8;\
302     const int pad = (BIT_DEPTH == 10) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
303     INIT_CLIP\
304     int i;\
305     pixel *dst = (pixel*)p_dst;\
306     pixel *src = (pixel*)p_src;\
307     dstStride >>= sizeof(pixel)-1;\
308     srcStride >>= sizeof(pixel)-1;\
309     src -= 2*srcStride;\
310     for(i=0; i<h+5; i++)\
311     {\
312         tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]) + pad;\
313         tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]) + pad;\
314         tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]) + pad;\
315         tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]) + pad;\
316         tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]) + pad;\
317         tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]) + pad;\
318         tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]) + pad;\
319         tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]) + pad;\
320         tmp+=tmpStride;\
321         src+=srcStride;\
322     }\
323     tmp -= tmpStride*(h+5-2);\
324     for(i=0; i<w; i++)\
325     {\
326         const int tmpB= tmp[-2*tmpStride] - pad;\
327         const int tmpA= tmp[-1*tmpStride] - pad;\
328         const int tmp0= tmp[0 *tmpStride] - pad;\
329         const int tmp1= tmp[1 *tmpStride] - pad;\
330         const int tmp2= tmp[2 *tmpStride] - pad;\
331         const int tmp3= tmp[3 *tmpStride] - pad;\
332         const int tmp4= tmp[4 *tmpStride] - pad;\
333         const int tmp5= tmp[5 *tmpStride] - pad;\
334         const int tmp6= tmp[6 *tmpStride] - pad;\
335         const int tmp7= tmp[7 *tmpStride] - pad;\
336         const int tmp8= tmp[8 *tmpStride] - pad;\
337         const int tmp9= tmp[9 *tmpStride] - pad;\
338         const int tmp10=tmp[10*tmpStride] - pad;\
339         OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
340         OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
341         OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
342         OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
343         OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
344         OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
345         OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
346         OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
347         dst++;\
348         tmp++;\
349     }\
350 }\
351 \
352 static void FUNC(OPNAME ## h264_qpel16_v_lowpass)(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
353     FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst                , src                , dstStride, srcStride);\
354     FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
355     src += 8*srcStride;\
356     dst += 8*dstStride;\
357     FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst                , src                , dstStride, srcStride);\
358     FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
359 }\
360 \
361 static void FUNC(OPNAME ## h264_qpel16_h_lowpass)(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
362     FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst                , src                , dstStride, srcStride);\
363     FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
364     src += 8*srcStride;\
365     dst += 8*dstStride;\
366     FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst                , src                , dstStride, srcStride);\
367     FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
368 }\
369 \
370 static void FUNC(OPNAME ## h264_qpel16_hv_lowpass)(uint8_t *dst, pixeltmp *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
371     FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst                , tmp  , src                , dstStride, tmpStride, srcStride);\
372     FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst+8*sizeof(pixel), tmp+8, src+8*sizeof(pixel), dstStride, tmpStride, srcStride);\
373     src += 8*srcStride;\
374     dst += 8*dstStride;\
375     FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst                , tmp  , src                , dstStride, tmpStride, srcStride);\
376     FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst+8*sizeof(pixel), tmp+8, src+8*sizeof(pixel), dstStride, tmpStride, srcStride);\
377 }\
378
379 #define H264_MC(OPNAME, SIZE) \
380 static av_unused void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc00)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
381 {\
382     FUNCC(OPNAME ## pixels ## SIZE)(dst, src, stride, SIZE);\
383 }\
384 \
385 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc10)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
386 {\
387     uint8_t half[SIZE*SIZE*sizeof(pixel)];\
388     FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(half, src, SIZE*sizeof(pixel), stride);\
389     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, src, half, stride, stride, SIZE*sizeof(pixel), SIZE);\
390 }\
391 \
392 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc20)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
393 {\
394     FUNC(OPNAME ## h264_qpel ## SIZE ## _h_lowpass)(dst, src, stride, stride);\
395 }\
396 \
397 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc30)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
398 {\
399     uint8_t half[SIZE*SIZE*sizeof(pixel)];\
400     FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(half, src, SIZE*sizeof(pixel), stride);\
401     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, src+sizeof(pixel), half, stride, stride, SIZE*sizeof(pixel), SIZE);\
402 }\
403 \
404 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc01)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
405 {\
406     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
407     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
408     uint8_t half[SIZE*SIZE*sizeof(pixel)];\
409     FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel),  stride, SIZE + 5);\
410     FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(half, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
411     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, full_mid, half, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
412 }\
413 \
414 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc02)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
415 {\
416     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
417     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
418     FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel),  stride, SIZE + 5);\
419     FUNC(OPNAME ## h264_qpel ## SIZE ## _v_lowpass)(dst, full_mid, stride, SIZE*sizeof(pixel));\
420 }\
421 \
422 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc03)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
423 {\
424     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
425     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
426     uint8_t half[SIZE*SIZE*sizeof(pixel)];\
427     FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel),  stride, SIZE + 5);\
428     FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(half, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
429     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, full_mid+SIZE*sizeof(pixel), half, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
430 }\
431 \
432 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc11)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
433 {\
434     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
435     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
436     uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
437     uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
438     FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
439     FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel),  stride, SIZE + 5);\
440     FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
441     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
442 }\
443 \
444 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc31)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
445 {\
446     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
447     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
448     uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
449     uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
450     FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
451     FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel),  stride, SIZE + 5);\
452     FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
453     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
454 }\
455 \
456 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc13)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
457 {\
458     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
459     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
460     uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
461     uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
462     FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
463     FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel),  stride, SIZE + 5);\
464     FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
465     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
466 }\
467 \
468 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc33)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
469 {\
470     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
471     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
472     uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
473     uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
474     FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
475     FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel),  stride, SIZE + 5);\
476     FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
477     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
478 }\
479 \
480 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc22)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
481 {\
482     pixeltmp tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
483     FUNC(OPNAME ## h264_qpel ## SIZE ## _hv_lowpass)(dst, tmp, src, stride, SIZE*sizeof(pixel), stride);\
484 }\
485 \
486 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc21)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
487 {\
488     pixeltmp tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
489     uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
490     uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
491     FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
492     FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
493     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
494 }\
495 \
496 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc23)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
497 {\
498     pixeltmp tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
499     uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
500     uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
501     FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
502     FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
503     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
504 }\
505 \
506 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc12)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
507 {\
508     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
509     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
510     pixeltmp tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
511     uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
512     uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
513     FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel),  stride, SIZE + 5);\
514     FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
515     FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
516     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfV, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
517 }\
518 \
519 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc32)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
520 {\
521     uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
522     uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
523     pixeltmp tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
524     uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
525     uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
526     FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel),  stride, SIZE + 5);\
527     FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
528     FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
529     FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfV, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
530 }\
531
532 #define op_avg(a, b)  a = (((a)+CLIP(((b) + 16)>>5)+1)>>1)
533 //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
534 #define op_put(a, b)  a = CLIP(((b) + 16)>>5)
535 #define op2_avg(a, b)  a = (((a)+CLIP(((b) + 512)>>10)+1)>>1)
536 #define op2_put(a, b)  a = CLIP(((b) + 512)>>10)
537
538 H264_LOWPASS(put_       , op_put, op2_put)
539 H264_LOWPASS(avg_       , op_avg, op2_avg)
540 H264_MC(put_, 2)
541 H264_MC(put_, 4)
542 H264_MC(put_, 8)
543 H264_MC(put_, 16)
544 H264_MC(avg_, 4)
545 H264_MC(avg_, 8)
546 H264_MC(avg_, 16)
547
548 #undef op_avg
549 #undef op_put
550 #undef op2_avg
551 #undef op2_put