comparison libavcodec/dsputil.h @ 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
comparison
equal deleted inserted replaced
-1:000000000000 0:f29c65762b58
1 /*
2 * DSP utils
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * DSP utils.
26 * note, many functions in here may use MMX which trashes the FPU state, it is
27 * absolutely necessary to call emms_c() between dsp & float/double code
28 */
29
30 #ifndef AVCODEC_DSPUTIL_H
31 #define AVCODEC_DSPUTIL_H
32
33 #include "libavutil/intreadwrite.h"
34 #include "avcodec.h"
35 #include "h264_idct.h"
36 //
37 void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1,
38 const float *win, float add_bias, int len);
39 void ff_float_to_int16_c(int16_t *dst, const float *src, long len);
40 void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels);
41
42 /* encoding scans */
43 extern const uint8_t ff_alternate_horizontal_scan[64];
44 extern const uint8_t ff_alternate_vertical_scan[64];
45 extern const uint8_t ff_zigzag_direct[64];
46 extern const uint8_t ff_zigzag248_direct[64];
47
48 /* pixel operations */
49 #define MAX_NEG_CROP 1024
50
51 /* temporary */
52 extern uint32_t ff_squareTbl[512];
53 extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
54
55 /* VP3 DSP functions */
56 void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
57 void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
58 void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
59 void ff_vp3_idct_dc_add_c(uint8_t *dest/*align 8*/, int line_size, const DCTELEM *block/*align 16*/);
60
61 void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
62 void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
63
64 /* VP6 DSP functions */
65 void ff_vp6_filter_diag4_c(uint8_t *dst, uint8_t *src, int stride,
66 const int16_t *h_weights, const int16_t *v_weights);
67
68 /* Bink functions */
69 void ff_bink_idct_c (DCTELEM *block);
70 void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block);
71 void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
72
73 /* CAVS functions */
74 void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride);
75 void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride);
76 void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride);
77 void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride);
78
79 /* VC1 functions */
80 void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
81 void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
82
83 /* EA functions */
84 void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
85
86 /* 1/2^n downscaling functions from imgconvert.c */
87 void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
88 void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
89 void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
90 void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
91
92 void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
93 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
94
95 /* minimum alignment rules ;)
96 If you notice errors in the align stuff, need more alignment for some ASM code
97 for some CPU or need to use a function with less aligned data then send a mail
98 to the ffmpeg-devel mailing list, ...
99
100 !warning These alignments might not match reality, (missing attribute((align))
101 stuff somewhere possible).
102 I (Michael) did not check them, these are just the alignments which I think
103 could be reached easily ...
104
105 !future video codecs might need functions with less strict alignment
106 */
107
108 /*
109 void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
110 void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
111 void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
112 void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
113 void clear_blocks_c(DCTELEM *blocks);
114 */
115
116 /* add and put pixel (decoding) */
117 // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
118 //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
119 typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
120 typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h);
121 typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
122 typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
123
124 typedef void (*op_fill_func)(uint8_t *block/*align width (8 or 16)*/, uint8_t value, int line_size, int h);
125
126 #define DEF_OLD_QPEL(name)\
127 void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
128 void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
129 void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
130
131 DEF_OLD_QPEL(qpel16_mc11_old_c)
132 DEF_OLD_QPEL(qpel16_mc31_old_c)
133 DEF_OLD_QPEL(qpel16_mc12_old_c)
134 DEF_OLD_QPEL(qpel16_mc32_old_c)
135 DEF_OLD_QPEL(qpel16_mc13_old_c)
136 DEF_OLD_QPEL(qpel16_mc33_old_c)
137 DEF_OLD_QPEL(qpel8_mc11_old_c)
138 DEF_OLD_QPEL(qpel8_mc31_old_c)
139 DEF_OLD_QPEL(qpel8_mc12_old_c)
140 DEF_OLD_QPEL(qpel8_mc32_old_c)
141 DEF_OLD_QPEL(qpel8_mc13_old_c)
142 DEF_OLD_QPEL(qpel8_mc33_old_c)
143
144 #define CALL_2X_PIXELS(a, b, n)\
145 static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
146 b(block , pixels , line_size, h);\
147 b(block+n, pixels+n, line_size, h);\
148 }
149
150 /* motion estimation */
151 // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
152 // although currently h<4 is not used as functions with width <8 are neither used nor implemented
153 typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/;
154
155 /**
156 * Scantable.
157 */
158 typedef struct ScanTable{
159 const uint8_t *scantable;
160 uint8_t permutated[64];
161 uint8_t raster_end[64];
162 #if ARCH_PPC
163 /** Used by dct_quantize_altivec to find last-non-zero */
164 DECLARE_ALIGNED(16, uint8_t, inverse)[64];
165 #endif
166 } ScanTable;
167
168 void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
169
170 void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize,
171 int block_w, int block_h,
172 int src_x, int src_y, int w, int h);
173
174
175 /**
176 * DSPContext.
177 */
178 typedef struct DSPContext {
179 /* pixel ops : interface with DCT */
180 void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
181 void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
182 void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
183 void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
184 void (*put_pixels_nonclamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
185 void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
186 void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
187 void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
188
189 void (*clear_block)(DCTELEM *block/*align 16*/);
190 void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
191
192
193 /**
194 * Halfpel motion compensation with rounding (a+b+1)>>1.
195 * this is an array[4][4] of motion compensation functions for 4
196 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
197 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
198 * @param block destination where the result is stored
199 * @param pixels source
200 * @param line_size number of bytes in a horizontal line of block
201 * @param h height
202 */
203 op_pixels_func put_pixels_tab[4][4];
204
205 /**
206 * Halfpel motion compensation with rounding (a+b+1)>>1.
207 * This is an array[4][4] of motion compensation functions for 4
208 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
209 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
210 * @param block destination into which the result is averaged (a+b+1)>>1
211 * @param pixels source
212 * @param line_size number of bytes in a horizontal line of block
213 * @param h height
214 */
215 op_pixels_func avg_pixels_tab[4][4];
216
217 /**
218 * Halfpel motion compensation with no rounding (a+b)>>1.
219 * this is an array[2][4] of motion compensation functions for 2
220 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
221 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
222 * @param block destination where the result is stored
223 * @param pixels source
224 * @param line_size number of bytes in a horizontal line of block
225 * @param h height
226 */
227 op_pixels_func put_no_rnd_pixels_tab[4][4];
228
229 /**
230 * Halfpel motion compensation with no rounding (a+b)>>1.
231 * this is an array[2][4] of motion compensation functions for 2
232 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
233 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
234 * @param block destination into which the result is averaged (a+b)>>1
235 * @param pixels source
236 * @param line_size number of bytes in a horizontal line of block
237 * @param h height
238 */
239 op_pixels_func avg_no_rnd_pixels_tab[4][4];
240
241 void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h);
242
243
244 qpel_mc_func put_qpel_pixels_tab[2][16];
245 qpel_mc_func avg_qpel_pixels_tab[2][16];
246 qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
247 qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
248 qpel_mc_func put_mspel_pixels_tab[8];
249
250 /**
251 * h264 Chroma MC
252 */
253 h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
254 h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
255 /* This is really one func used in VC-1 decoding */
256 h264_chroma_mc_func put_no_rnd_vc1_chroma_pixels_tab[3];
257 h264_chroma_mc_func avg_no_rnd_vc1_chroma_pixels_tab[3];
258
259 qpel_mc_func put_h264_qpel_pixels_tab[4][16];
260 qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
261
262 qpel_mc_func put_2tap_qpel_pixels_tab[4][16];
263 qpel_mc_func avg_2tap_qpel_pixels_tab[4][16];
264
265
266 /* (I)DCT */
267 void (*fdct)(DCTELEM *block/* align 16*/);
268 void (*fdct248)(DCTELEM *block/* align 16*/);
269
270 /* IDCT really*/
271 void (*idct)(DCTELEM *block/* align 16*/);
272
273 /**
274 * block -> idct -> clip to unsigned 8 bit -> dest.
275 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
276 * @param line_size size in bytes of a horizontal line of dest
277 */
278 void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
279
280 /**
281 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
282 * @param line_size size in bytes of a horizontal line of dest
283 */
284 void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
285
286 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
287 #define EDGE_WIDTH 32
288
289 void (*prefetch)(void *mem, int stride, int h);
290
291 } DSPContext;
292
293 void dsputil_static_init(void);
294 void dsputil_init(DSPContext* p);
295
296 int ff_check_alignment(void);
297
298 /**
299 * permute block according to permuatation.
300 * @param last last non zero element in scantable order
301 */
302 void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
303
304 void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
305
306 #define BYTE_VEC32(c) ((c)*0x01010101UL)
307
308 static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
309 {
310 return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
311 }
312
313 static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
314 {
315 return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
316 }
317
318
319 /**
320 * Empty mmx state.
321 * this must be called between any dsp function and float/double code.
322 * for example sin(); dsp->idct_put(); emms_c(); cos()
323 */
324 #define emms_c()
325
326 /* should be defined by architectures supporting
327 one or more MultiMedia extension */
328 int mm_support(void);
329 extern int mm_flags;
330
331 void dsputil_init_arm(DSPContext* c);
332 void dsputil_init_mmx(DSPContext* c);
333 void dsputil_init_ppc(DSPContext* c);
334
335 void ff_dsputil_init_dwt(DSPContext *c);
336
337 #if HAVE_MMX
338
339 #undef emms_c
340
341 static inline void emms(void)
342 {
343 __asm__ volatile ("emms;":::"memory");
344 }
345
346
347 #define emms_c() \
348 {\
349 if (mm_flags & FF_MM_MMX)\
350 emms();\
351 }
352
353 #elif ARCH_ARM
354
355 #if HAVE_NEON
356 # define STRIDE_ALIGN 16
357 #endif
358
359 #elif ARCH_PPC || ARCH_PPC64 || ARCH_CELL
360
361 #define STRIDE_ALIGN 16
362
363 #endif
364
365 #ifndef STRIDE_ALIGN
366 # define STRIDE_ALIGN 8
367 #endif
368
369 #define WRAPPER8_16(name8, name16)\
370 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
371 return name8(s, dst , src , stride, h)\
372 +name8(s, dst+8 , src+8 , stride, h);\
373 }
374
375 #define WRAPPER8_16_SQ(name8, name16)\
376 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
377 int score=0;\
378 score +=name8(s, dst , src , stride, 8);\
379 score +=name8(s, dst+8 , src+8 , stride, 8);\
380 if(h==16){\
381 dst += 8*stride;\
382 src += 8*stride;\
383 score +=name8(s, dst , src , stride, 8);\
384 score +=name8(s, dst+8 , src+8 , stride, 8);\
385 }\
386 return score;\
387 }
388
389 static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
390 {
391 int i;
392 for(i=0; i<h; i++)
393 {
394 AV_WN16(dst , AV_RN16(src ));
395 dst+=dstStride;
396 src+=srcStride;
397 }
398 }
399
400 static inline void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
401 {
402 int i;
403 for(i=0; i<h; i++)
404 {
405 AV_WN32(dst , AV_RN32(src ));
406 dst+=dstStride;
407 src+=srcStride;
408 }
409 }
410
411 static inline void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
412 {
413 int i;
414 for(i=0; i<h; i++)
415 {
416 AV_WN32(dst , AV_RN32(src ));
417 AV_WN32(dst+4 , AV_RN32(src+4 ));
418 dst+=dstStride;
419 src+=srcStride;
420 }
421 }
422
423 static inline void copy_block9(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
424 {
425 int i;
426 for(i=0; i<h; i++)
427 {
428 AV_WN32(dst , AV_RN32(src ));
429 AV_WN32(dst+4 , AV_RN32(src+4 ));
430 dst[8]= src[8];
431 dst+=dstStride;
432 src+=srcStride;
433 }
434 }
435
436 static inline void copy_block16(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
437 {
438 int i;
439 for(i=0; i<h; i++)
440 {
441 AV_WN32(dst , AV_RN32(src ));
442 AV_WN32(dst+4 , AV_RN32(src+4 ));
443 AV_WN32(dst+8 , AV_RN32(src+8 ));
444 AV_WN32(dst+12, AV_RN32(src+12));
445 dst+=dstStride;
446 src+=srcStride;
447 }
448 }
449
450 static inline void copy_block17(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
451 {
452 int i;
453 for(i=0; i<h; i++)
454 {
455 AV_WN32(dst , AV_RN32(src ));
456 AV_WN32(dst+4 , AV_RN32(src+4 ));
457 AV_WN32(dst+8 , AV_RN32(src+8 ));
458 AV_WN32(dst+12, AV_RN32(src+12));
459 dst[16]= src[16];
460 dst+=dstStride;
461 src+=srcStride;
462 }
463 }
464
465 #endif /* AVCODEC_DSPUTIL_H */