2 * Half-pel DSP functions.
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
8 * This file is part of FFmpeg.
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.
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.
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
27 * Half-pel DSP functions.
30 #include "bit_depth_template.c"
32 #include "hpel_template.c"
34 #define PIXOP2(OPNAME, OP) \
35 static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
36 int src_stride1, int src_stride2, int h){\
40 a= AV_RN4P(&src1[i*src_stride1 ]);\
41 b= AV_RN4P(&src2[i*src_stride2 ]);\
42 OP(*((pixel4*)&dst[i*dst_stride ]), no_rnd_avg_pixel4(a, b));\
43 a= AV_RN4P(&src1[i*src_stride1+4*sizeof(pixel)]);\
44 b= AV_RN4P(&src2[i*src_stride2+4*sizeof(pixel)]);\
45 OP(*((pixel4*)&dst[i*dst_stride+4*sizeof(pixel)]), no_rnd_avg_pixel4(a, b));\
49 static inline void FUNCC(OPNAME ## _no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\
50 FUNC(OPNAME ## _no_rnd_pixels8_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\
53 static inline void FUNCC(OPNAME ## _pixels8_x2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\
54 FUNC(OPNAME ## _pixels8_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\
57 static inline void FUNCC(OPNAME ## _no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\
58 FUNC(OPNAME ## _no_rnd_pixels8_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
61 static inline void FUNCC(OPNAME ## _pixels8_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\
62 FUNC(OPNAME ## _pixels8_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
65 static inline void FUNCC(OPNAME ## _pixels4_x2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\
66 FUNC(OPNAME ## _pixels4_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\
69 static inline void FUNCC(OPNAME ## _pixels4_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\
70 FUNC(OPNAME ## _pixels4_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
73 static inline void FUNCC(OPNAME ## _pixels2_x2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\
74 FUNC(OPNAME ## _pixels2_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\
77 static inline void FUNCC(OPNAME ## _pixels2_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){\
78 FUNC(OPNAME ## _pixels2_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
81 static inline void FUNCC(OPNAME ## _pixels2_xy2)(uint8_t *_block, const uint8_t *_pixels, ptrdiff_t line_size, int h)\
83 int i, a0, b0, a1, b1;\
84 pixel *block = (pixel*)_block;\
85 const pixel *pixels = (const pixel*)_pixels;\
86 line_size >>= sizeof(pixel)-1;\
99 block[0]= (a1+a0)>>2; /* FIXME non put */\
100 block[1]= (b1+b0)>>2;\
110 block[0]= (a1+a0)>>2;\
111 block[1]= (b1+b0)>>2;\
117 static inline void FUNCC(OPNAME ## _pixels4_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\
119 /* FIXME HIGH BIT DEPTH */\
121 const uint32_t a= AV_RN32(pixels );\
122 const uint32_t b= AV_RN32(pixels+1);\
123 uint32_t l0= (a&0x03030303UL)\
126 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
127 + ((b&0xFCFCFCFCUL)>>2);\
131 for(i=0; i<h; i+=2){\
132 uint32_t a= AV_RN32(pixels );\
133 uint32_t b= AV_RN32(pixels+1);\
134 l1= (a&0x03030303UL)\
136 h1= ((a&0xFCFCFCFCUL)>>2)\
137 + ((b&0xFCFCFCFCUL)>>2);\
138 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
141 a= AV_RN32(pixels );\
142 b= AV_RN32(pixels+1);\
143 l0= (a&0x03030303UL)\
146 h0= ((a&0xFCFCFCFCUL)>>2)\
147 + ((b&0xFCFCFCFCUL)>>2);\
148 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
154 static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\
156 /* FIXME HIGH BIT DEPTH */\
160 const uint32_t a= AV_RN32(pixels );\
161 const uint32_t b= AV_RN32(pixels+1);\
162 uint32_t l0= (a&0x03030303UL)\
165 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
166 + ((b&0xFCFCFCFCUL)>>2);\
170 for(i=0; i<h; i+=2){\
171 uint32_t a= AV_RN32(pixels );\
172 uint32_t b= AV_RN32(pixels+1);\
173 l1= (a&0x03030303UL)\
175 h1= ((a&0xFCFCFCFCUL)>>2)\
176 + ((b&0xFCFCFCFCUL)>>2);\
177 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
180 a= AV_RN32(pixels );\
181 b= AV_RN32(pixels+1);\
182 l0= (a&0x03030303UL)\
185 h0= ((a&0xFCFCFCFCUL)>>2)\
186 + ((b&0xFCFCFCFCUL)>>2);\
187 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
191 pixels+=4-line_size*(h+1);\
192 block +=4-line_size*h;\
196 static inline void FUNCC(OPNAME ## _no_rnd_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\
198 /* FIXME HIGH BIT DEPTH */\
202 const uint32_t a= AV_RN32(pixels );\
203 const uint32_t b= AV_RN32(pixels+1);\
204 uint32_t l0= (a&0x03030303UL)\
207 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
208 + ((b&0xFCFCFCFCUL)>>2);\
212 for(i=0; i<h; i+=2){\
213 uint32_t a= AV_RN32(pixels );\
214 uint32_t b= AV_RN32(pixels+1);\
215 l1= (a&0x03030303UL)\
217 h1= ((a&0xFCFCFCFCUL)>>2)\
218 + ((b&0xFCFCFCFCUL)>>2);\
219 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
222 a= AV_RN32(pixels );\
223 b= AV_RN32(pixels+1);\
224 l0= (a&0x03030303UL)\
227 h0= ((a&0xFCFCFCFCUL)>>2)\
228 + ((b&0xFCFCFCFCUL)>>2);\
229 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
233 pixels+=4-line_size*(h+1);\
234 block +=4-line_size*h;\
238 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_x2) , FUNCC(OPNAME ## _pixels8_x2) , 8*sizeof(pixel))\
239 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_y2) , FUNCC(OPNAME ## _pixels8_y2) , 8*sizeof(pixel))\
240 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\
241 av_unused CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16) , FUNCC(OPNAME ## _pixels8) , 8*sizeof(pixel))\
242 CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_x2) , FUNCC(OPNAME ## _no_rnd_pixels8_x2) , 8*sizeof(pixel))\
243 CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_y2) , FUNCC(OPNAME ## _no_rnd_pixels8_y2) , 8*sizeof(pixel))\
244 CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_xy2), FUNCC(OPNAME ## _no_rnd_pixels8_xy2), 8*sizeof(pixel))\
246 #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
247 #define op_put(a, b) a = b
249 #define put_no_rnd_pixels8_8_c put_pixels8_8_c