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 Libav.
10 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 #include "bit_depth_template.c"
33 /* draw the edges of width 'w' of an image of size width, height */
34 // FIXME: Check that this is OK for MPEG-4 interlaced.
35 static void FUNCC(draw_edges)(uint8_t *_buf, int _wrap, int width, int height,
36 int w, int h, int sides)
38 pixel *buf = (pixel *) _buf;
39 int wrap = _wrap / sizeof(pixel);
40 pixel *ptr = buf, *last_line;
44 for (i = 0; i < height; i++) {
45 memset(ptr - w, ptr[0], w);
46 memset(ptr + width, ptr[width - 1], w);
50 /* top and bottom + corners */
52 last_line = buf + (height - 1) * wrap;
54 for (i = 0; i < h; i++)
56 memcpy(buf - (i + 1) * wrap, buf, (width + w + w) * sizeof(pixel));
57 if (sides & EDGE_BOTTOM)
58 for (i = 0; i < h; i++)
60 memcpy(last_line + (i + 1) * wrap, last_line,
61 (width + w + w) * sizeof(pixel));
65 static void FUNCC(get_pixels)(int16_t *restrict block, const uint8_t *_pixels,
68 const pixel *pixels = (const pixel *) _pixels;
72 for (i = 0; i < 8; i++) {
81 pixels += line_size / sizeof(pixel);
87 static void FUNCC(clear_block)(int16_t *block)
89 memset(block, 0, sizeof(int16_t) * 64);
92 static void FUNCC(clear_blocks)(int16_t *blocks)
94 memset(blocks, 0, sizeof(int16_t) * 6 * 64);
99 #include "hpel_template.c"
102 #define PIXOP2(OPNAME, OP) \
103 static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, \
104 const uint8_t *src1, \
105 const uint8_t *src2, \
113 for (i = 0; i < h; i++) { \
115 a = AV_RN4P(&src1[i * src_stride1]); \
116 b = AV_RN4P(&src2[i * src_stride2]); \
117 OP(*((pixel4 *) &dst[i * dst_stride]), \
118 no_rnd_avg_pixel4(a, b)); \
119 a = AV_RN4P(&src1[i * src_stride1 + 4 * sizeof(pixel)]); \
120 b = AV_RN4P(&src2[i * src_stride2 + 4 * sizeof(pixel)]); \
121 OP(*((pixel4 *) &dst[i * dst_stride + 4 * sizeof(pixel)]), \
122 no_rnd_avg_pixel4(a, b)); \
126 static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst, \
127 const uint8_t *src1, \
128 const uint8_t *src2, \
134 FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst, src1, src2, dst_stride, \
135 src_stride1, src_stride2, h); \
136 FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst + 8 * sizeof(pixel), \
137 src1 + 8 * sizeof(pixel), \
138 src2 + 8 * sizeof(pixel), \
139 dst_stride, src_stride1, \
143 static inline void FUNC(OPNAME ## _pixels8_l4)(uint8_t *dst, \
144 const uint8_t *src1, \
145 const uint8_t *src2, \
146 const uint8_t *src3, \
147 const uint8_t *src4, \
155 /* FIXME HIGH BIT DEPTH */ \
158 for (i = 0; i < h; i++) { \
159 uint32_t a, b, c, d, l0, l1, h0, h1; \
160 a = AV_RN32(&src1[i * src_stride1]); \
161 b = AV_RN32(&src2[i * src_stride2]); \
162 c = AV_RN32(&src3[i * src_stride3]); \
163 d = AV_RN32(&src4[i * src_stride4]); \
164 l0 = (a & 0x03030303UL) + \
165 (b & 0x03030303UL) + \
167 h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
168 ((b & 0xFCFCFCFCUL) >> 2); \
169 l1 = (c & 0x03030303UL) + \
170 (d & 0x03030303UL); \
171 h1 = ((c & 0xFCFCFCFCUL) >> 2) + \
172 ((d & 0xFCFCFCFCUL) >> 2); \
173 OP(*((uint32_t *) &dst[i * dst_stride]), \
174 h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
175 a = AV_RN32(&src1[i * src_stride1 + 4]); \
176 b = AV_RN32(&src2[i * src_stride2 + 4]); \
177 c = AV_RN32(&src3[i * src_stride3 + 4]); \
178 d = AV_RN32(&src4[i * src_stride4 + 4]); \
179 l0 = (a & 0x03030303UL) + \
180 (b & 0x03030303UL) + \
182 h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
183 ((b & 0xFCFCFCFCUL) >> 2); \
184 l1 = (c & 0x03030303UL) + \
185 (d & 0x03030303UL); \
186 h1 = ((c & 0xFCFCFCFCUL) >> 2) + \
187 ((d & 0xFCFCFCFCUL) >> 2); \
188 OP(*((uint32_t *) &dst[i * dst_stride + 4]), \
189 h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
193 static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst, \
194 const uint8_t *src1, \
195 const uint8_t *src2, \
196 const uint8_t *src3, \
197 const uint8_t *src4, \
205 /* FIXME HIGH BIT DEPTH */ \
208 for (i = 0; i < h; i++) { \
209 uint32_t a, b, c, d, l0, l1, h0, h1; \
210 a = AV_RN32(&src1[i * src_stride1]); \
211 b = AV_RN32(&src2[i * src_stride2]); \
212 c = AV_RN32(&src3[i * src_stride3]); \
213 d = AV_RN32(&src4[i * src_stride4]); \
214 l0 = (a & 0x03030303UL) + \
215 (b & 0x03030303UL) + \
217 h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
218 ((b & 0xFCFCFCFCUL) >> 2); \
219 l1 = (c & 0x03030303UL) + \
220 (d & 0x03030303UL); \
221 h1 = ((c & 0xFCFCFCFCUL) >> 2) + \
222 ((d & 0xFCFCFCFCUL) >> 2); \
223 OP(*((uint32_t *) &dst[i * dst_stride]), \
224 h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
225 a = AV_RN32(&src1[i * src_stride1 + 4]); \
226 b = AV_RN32(&src2[i * src_stride2 + 4]); \
227 c = AV_RN32(&src3[i * src_stride3 + 4]); \
228 d = AV_RN32(&src4[i * src_stride4 + 4]); \
229 l0 = (a & 0x03030303UL) + \
230 (b & 0x03030303UL) + \
232 h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
233 ((b & 0xFCFCFCFCUL) >> 2); \
234 l1 = (c & 0x03030303UL) + \
235 (d & 0x03030303UL); \
236 h1 = ((c & 0xFCFCFCFCUL) >> 2) + \
237 ((d & 0xFCFCFCFCUL) >> 2); \
238 OP(*((uint32_t *) &dst[i * dst_stride + 4]), \
239 h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
242 static inline void FUNC(OPNAME ## _pixels16_l4)(uint8_t *dst, \
243 const uint8_t *src1, \
244 const uint8_t *src2, \
245 const uint8_t *src3, \
246 const uint8_t *src4, \
254 FUNC(OPNAME ## _pixels8_l4)(dst, src1, src2, src3, src4, dst_stride, \
255 src_stride1, src_stride2, src_stride3, \
257 FUNC(OPNAME ## _pixels8_l4)(dst + 8 * sizeof(pixel), \
258 src1 + 8 * sizeof(pixel), \
259 src2 + 8 * sizeof(pixel), \
260 src3 + 8 * sizeof(pixel), \
261 src4 + 8 * sizeof(pixel), \
262 dst_stride, src_stride1, src_stride2, \
263 src_stride3, src_stride4, h); \
265 static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst, \
266 const uint8_t *src1, \
267 const uint8_t *src2, \
268 const uint8_t *src3, \
269 const uint8_t *src4, \
277 FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst, src1, src2, src3, src4, \
278 dst_stride, src_stride1, src_stride2, \
279 src_stride3, src_stride4, h); \
280 FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst + 8 * sizeof(pixel), \
281 src1 + 8 * sizeof(pixel), \
282 src2 + 8 * sizeof(pixel), \
283 src3 + 8 * sizeof(pixel), \
284 src4 + 8 * sizeof(pixel), \
285 dst_stride, src_stride1, src_stride2, \
286 src_stride3, src_stride4, h); \
289 static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, \
290 const uint8_t *pixels, \
291 ptrdiff_t line_size, \
294 /* FIXME HIGH BIT DEPTH */ \
297 for (j = 0; j < 2; j++) { \
299 const uint32_t a = AV_RN32(pixels); \
300 const uint32_t b = AV_RN32(pixels + 1); \
301 uint32_t l0 = (a & 0x03030303UL) + \
302 (b & 0x03030303UL) + \
304 uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
305 ((b & 0xFCFCFCFCUL) >> 2); \
308 pixels += line_size; \
309 for (i = 0; i < h; i += 2) { \
310 uint32_t a = AV_RN32(pixels); \
311 uint32_t b = AV_RN32(pixels + 1); \
312 l1 = (a & 0x03030303UL) + \
313 (b & 0x03030303UL); \
314 h1 = ((a & 0xFCFCFCFCUL) >> 2) + \
315 ((b & 0xFCFCFCFCUL) >> 2); \
316 OP(*((uint32_t *) block), \
317 h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
318 pixels += line_size; \
319 block += line_size; \
320 a = AV_RN32(pixels); \
321 b = AV_RN32(pixels + 1); \
322 l0 = (a & 0x03030303UL) + \
323 (b & 0x03030303UL) + \
325 h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
326 ((b & 0xFCFCFCFCUL) >> 2); \
327 OP(*((uint32_t *) block), \
328 h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
329 pixels += line_size; \
330 block += line_size; \
332 pixels += 4 - line_size * (h + 1); \
333 block += 4 - line_size * h; \
337 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), \
338 FUNCC(OPNAME ## _pixels8_xy2), \
341 #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
342 #define op_put(a, b) a = b
344 #define put_no_rnd_pixels8_8_c put_pixels8_8_c