h263 framerate & aspect ratio fixes
[libav.git] / libavcodec / dsputil.h
CommitLineData
ff4ec49e
FB
1/*
2 * DSP utils
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
8f2ab833 4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
ff4ec49e
FB
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
24641185
MN
20
21/**
22 * @file dsputil.h
983e3246 23 * DSP utils.
5755c27f
MN
24 * note, many functions in here may use MMX which trashes the FPU state, it is
25 * absolutely necessary to call emms_c() between dsp & float/double code
24641185
MN
26 */
27
de6d9b64
FB
28#ifndef DSPUTIL_H
29#define DSPUTIL_H
30
31#include "common.h"
43f1708f 32#include "avcodec.h"
de6d9b64 33
24641185 34
44eb4951 35//#define DEBUG
de6d9b64
FB
36/* dct code */
37typedef short DCTELEM;
38
03c94ede 39void fdct_ifast (DCTELEM *data);
48b1f800 40void fdct_ifast248 (DCTELEM *data);
28db7fce 41void ff_jpeg_fdct_islow (DCTELEM *data);
10acc479 42void ff_fdct248_islow (DCTELEM *data);
de6d9b64
FB
43
44void j_rev_dct (DCTELEM *data);
45
3f09f52a 46void ff_fdct_mmx(DCTELEM *block);
cf3bf5bb 47void ff_fdct_mmx2(DCTELEM *block);
8fd19ab2 48void ff_fdct_sse2(DCTELEM *block);
de6d9b64 49
e0eac44e 50/* encoding scans */
0c1a9eda
ZK
51extern const uint8_t ff_alternate_horizontal_scan[64];
52extern const uint8_t ff_alternate_vertical_scan[64];
53extern const uint8_t ff_zigzag_direct[64];
10acc479 54extern const uint8_t ff_zigzag248_direct[64];
5a240838 55
de6d9b64
FB
56/* pixel operations */
57#define MAX_NEG_CROP 384
58
59/* temporary */
0c1a9eda
ZK
60extern uint32_t squareTbl[512];
61extern uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
de6d9b64 62
de6d9b64 63
b7c27ee6 64/* minimum alignment rules ;)
eb4b3dd3 65if u notice errors in the align stuff, need more alignment for some asm code for some cpu
b7c27ee6
MN
66or need to use a function with less aligned data then send a mail to the ffmpeg-dev list, ...
67
68!warning these alignments might not match reallity, (missing attribute((align)) stuff somewhere possible)
69i (michael) didnt check them, these are just the alignents which i think could be reached easily ...
de6d9b64 70
b7c27ee6
MN
71!future video codecs might need functions with less strict alignment
72*/
73
eb4b3dd3 74/*
0c1a9eda
ZK
75void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
76void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
77void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
78void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
649c00c9 79void clear_blocks_c(DCTELEM *blocks);
eb4b3dd3 80*/
de6d9b64
FB
81
82/* add and put pixel (decoding) */
b7c27ee6 83// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
7d67aa9b 84//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
0c1a9eda 85typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
669ac79c 86typedef 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);
0c1a9eda 87typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
0da71265 88typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
b3184779 89
db794953 90#define DEF_OLD_QPEL(name)\
0c1a9eda
ZK
91void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
92void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
93void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
db794953
MN
94
95DEF_OLD_QPEL(qpel16_mc11_old_c)
96DEF_OLD_QPEL(qpel16_mc31_old_c)
97DEF_OLD_QPEL(qpel16_mc12_old_c)
98DEF_OLD_QPEL(qpel16_mc32_old_c)
99DEF_OLD_QPEL(qpel16_mc13_old_c)
100DEF_OLD_QPEL(qpel16_mc33_old_c)
101DEF_OLD_QPEL(qpel8_mc11_old_c)
102DEF_OLD_QPEL(qpel8_mc31_old_c)
103DEF_OLD_QPEL(qpel8_mc12_old_c)
104DEF_OLD_QPEL(qpel8_mc32_old_c)
105DEF_OLD_QPEL(qpel8_mc13_old_c)
106DEF_OLD_QPEL(qpel8_mc33_old_c)
b3184779
MN
107
108#define CALL_2X_PIXELS(a, b, n)\
109static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
110 b(block , pixels , line_size, h);\
111 b(block+n, pixels+n, line_size, h);\
112}
44eb4951 113
de6d9b64 114/* motion estimation */
7d67aa9b
MN
115// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
116// allthough currently h<4 is not used as functions with width <8 are not used and neither implemented
bb198e19 117typedef 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))*/;
1457ab52 118
0da71265 119
24641185
MN
120/**
121 * DSPContext.
122 */
eb4b3dd3
ZK
123typedef struct DSPContext {
124 /* pixel ops : interface with DCT */
0c1a9eda
ZK
125 void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
126 void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
127 void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
128 void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
d518aebd
MN
129 /**
130 * translational global motion compensation.
131 */
0c1a9eda 132 void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
d518aebd
MN
133 /**
134 * global motion compensation.
135 */
0c1a9eda 136 void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
eb4b3dd3
ZK
137 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
138 void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
0c1a9eda
ZK
139 int (*pix_sum)(uint8_t * pix, int line_size);
140 int (*pix_norm1)(uint8_t * pix, int line_size);
bb198e19
MN
141// 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
142
622348f9
MN
143 me_cmp_func sad[5]; /* identical to pix_absAxA except additional void * */
144 me_cmp_func sse[5];
145 me_cmp_func hadamard8_diff[5];
146 me_cmp_func dct_sad[5];
147 me_cmp_func quant_psnr[5];
148 me_cmp_func bit[5];
149 me_cmp_func rd[5];
150 me_cmp_func vsad[5];
151 me_cmp_func vsse[5];
1457ab52 152
bb198e19
MN
153 me_cmp_func me_pre_cmp[5];
154 me_cmp_func me_cmp[5];
155 me_cmp_func me_sub_cmp[5];
156 me_cmp_func mb_cmp[5];
622348f9 157 me_cmp_func ildct_cmp[5]; //only width 16 used
eb4b3dd3 158
d518aebd
MN
159 /**
160 * Halfpel motion compensation with rounding (a+b+1)>>1.
669ac79c 161 * this is an array[4][4] of motion compensation funcions for 4
e5771f4f 162 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
5755c27f 163 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
d518aebd
MN
164 * @param block destination where the result is stored
165 * @param pixels source
166 * @param line_size number of bytes in a horizontal line of block
167 * @param h height
168 */
669ac79c 169 op_pixels_func put_pixels_tab[4][4];
d518aebd
MN
170
171 /**
172 * Halfpel motion compensation with rounding (a+b+1)>>1.
4e8eed2f 173 * This is an array[4][4] of motion compensation functions for 4
e5771f4f 174 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
5755c27f 175 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
d518aebd
MN
176 * @param block destination into which the result is averaged (a+b+1)>>1
177 * @param pixels source
178 * @param line_size number of bytes in a horizontal line of block
179 * @param h height
180 */
da3b9756 181 op_pixels_func avg_pixels_tab[4][4];
d518aebd
MN
182
183 /**
184 * Halfpel motion compensation with no rounding (a+b)>>1.
eb14c713
MN
185 * this is an array[2][4] of motion compensation funcions for 2
186 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
5755c27f 187 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
d518aebd
MN
188 * @param block destination where the result is stored
189 * @param pixels source
190 * @param line_size number of bytes in a horizontal line of block
191 * @param h height
192 */
eb4b3dd3 193 op_pixels_func put_no_rnd_pixels_tab[2][4];
d518aebd
MN
194
195 /**
196 * Halfpel motion compensation with no rounding (a+b)>>1.
eb14c713
MN
197 * this is an array[2][4] of motion compensation funcions for 2
198 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
5755c27f 199 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
d518aebd
MN
200 * @param block destination into which the result is averaged (a+b)>>1
201 * @param pixels source
202 * @param line_size number of bytes in a horizontal line of block
203 * @param h height
204 */
eb4b3dd3 205 op_pixels_func avg_no_rnd_pixels_tab[2][4];
669ac79c 206
c0a0170c
MN
207 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);
208
669ac79c
MN
209 /**
210 * Thirdpel motion compensation with rounding (a+b+1)>>1.
211 * this is an array[12] of motion compensation funcions for the 9 thirdpel positions<br>
212 * *pixels_tab[ xthirdpel + 4*ythirdpel ]
213 * @param block destination where the result is stored
214 * @param pixels source
215 * @param line_size number of bytes in a horizontal line of block
216 * @param h height
217 */
218 tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
da3b9756
MM
219 tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
220
eb4b3dd3
ZK
221 qpel_mc_func put_qpel_pixels_tab[2][16];
222 qpel_mc_func avg_qpel_pixels_tab[2][16];
223 qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
224 qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
1457ab52 225 qpel_mc_func put_mspel_pixels_tab[8];
0da71265
MN
226
227 /**
228 * h264 Chram MC
229 */
230 h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
231 h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
eb4b3dd3 232
0da71265
MN
233 qpel_mc_func put_h264_qpel_pixels_tab[3][16];
234 qpel_mc_func avg_h264_qpel_pixels_tab[3][16];
235
bb198e19 236 me_cmp_func pix_abs[2][4];
11f18faf
MN
237
238 /* huffyuv specific */
11f18faf 239 void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
1457ab52 240 void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
84705403
MN
241 /**
242 * subtract huffyuv's variant of median prediction
243 * note, this might read from src1[-1], src2[-1]
244 */
245 void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top);
3d2e8cce 246 void (*bswap_buf)(uint32_t *dst, uint32_t *src, int w);
b0368839 247
332f9ac4
MN
248 void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
249 void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
250
b0368839
MN
251 /* (I)DCT */
252 void (*fdct)(DCTELEM *block/* align 16*/);
10acc479 253 void (*fdct248)(DCTELEM *block/* align 16*/);
4fb518c3
MN
254
255 /* IDCT really*/
256 void (*idct)(DCTELEM *block/* align 16*/);
24641185
MN
257
258 /**
77c92c2d 259 * block -> idct -> clip to unsigned 8 bit -> dest.
24641185 260 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
a1adf436 261 * @param line_size size in bytes of a horizotal line of dest
24641185 262 */
b0368839 263 void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
24641185
MN
264
265 /**
266 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
a1adf436 267 * @param line_size size in bytes of a horizotal line of dest
24641185 268 */
b0368839 269 void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
24641185
MN
270
271 /**
77c92c2d 272 * idct input permutation.
05493021
MN
273 * several optimized IDCTs need a permutated input (relative to the normal order of the reference
274 * IDCT)
275 * this permutation must be performed before the idct_put/add, note, normally this can be merged
276 * with the zigzag/alternate scan<br>
24641185
MN
277 * an example to avoid confusion:
278 * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
279 * - (x -> referece dct -> reference idct -> x)
280 * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
281 * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
282 */
b0368839
MN
283 uint8_t idct_permutation[64];
284 int idct_permutation_type;
285#define FF_NO_IDCT_PERM 1
286#define FF_LIBMPEG2_IDCT_PERM 2
287#define FF_SIMPLE_IDCT_PERM 3
288#define FF_TRANSPOSE_IDCT_PERM 4
289
364a1797
MN
290 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
291 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
292#define BASIS_SHIFT 16
293#define RECON_SHIFT 6
294
eb4b3dd3
ZK
295} DSPContext;
296
59cf08ce 297void dsputil_static_init(void);
b0368839 298void dsputil_init(DSPContext* p, AVCodecContext *avctx);
de6d9b64 299
7801d21d
MN
300/**
301 * permute block according to permuatation.
302 * @param last last non zero element in scantable order
303 */
0c1a9eda 304void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
e0eac44e 305
622348f9
MN
306void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
307
d8085ea7
MN
308#define BYTE_VEC32(c) ((c)*0x01010101UL)
309
310static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
311{
312 return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
313}
314
315static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
316{
317 return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
318}
319
24641185 320/**
77c92c2d 321 * Empty mmx state.
24641185
MN
322 * this must be called between any dsp function and float/double code.
323 * for example sin(); dsp->idct_put(); emms_c(); cos()
324 */
eb4b3dd3
ZK
325#define emms_c()
326
e629ab68
RD
327/* should be defined by architectures supporting
328 one or more MultiMedia extension */
329int mm_support(void);
330
3d03c0a2 331#if defined(HAVE_MMX)
de6d9b64 332
18f77016 333#undef emms_c
eb4b3dd3 334
de6d9b64
FB
335#define MM_MMX 0x0001 /* standard MMX */
336#define MM_3DNOW 0x0004 /* AMD 3DNOW */
337#define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
338#define MM_SSE 0x0008 /* SSE functions */
339#define MM_SSE2 0x0010 /* PIV SSE2 functions */
340
341extern int mm_flags;
342
0c1a9eda
ZK
343void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
344void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
de6d9b64
FB
345
346static inline void emms(void)
347{
fb16b7e7
FB
348 __asm __volatile ("emms;":::"memory");
349}
350
1457ab52 351
fb16b7e7
FB
352#define emms_c() \
353{\
354 if (mm_flags & MM_MMX)\
355 emms();\
de6d9b64
FB
356}
357
358#define __align8 __attribute__ ((aligned (8)))
359
b0368839
MN
360void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
361void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
2720569a 362
3d03c0a2
FB
363#elif defined(ARCH_ARMV4L)
364
3d03c0a2
FB
365/* This is to use 4 bytes read to the IDCT pointers for some 'zero'
366 line ptimizations */
367#define __align8 __attribute__ ((aligned (4)))
368
b0368839 369void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx);
3d03c0a2 370
c34270f5 371#elif defined(HAVE_MLIB)
c34270f5
FB
372
373/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
374#define __align8 __attribute__ ((aligned (8)))
375
b0368839 376void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
c34270f5 377
1e98dffb
NK
378#elif defined(ARCH_ALPHA)
379
1e98dffb
NK
380#define __align8 __attribute__ ((aligned (8)))
381
b0368839 382void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
1e98dffb 383
59925ef2
BF
384#elif defined(ARCH_POWERPC)
385
404d2241
BF
386#define MM_ALTIVEC 0x0001 /* standard AltiVec */
387
388extern int mm_flags;
389
3b991c54 390#if defined(HAVE_ALTIVEC) && !defined(CONFIG_DARWIN)
9a197a24 391#define pixel altivec_pixel
3b991c54 392#include <altivec.h>
9a197a24 393#undef pixel
3b991c54
RD
394#endif
395
59925ef2
BF
396#define __align8 __attribute__ ((aligned (16)))
397
b0368839 398void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
59925ef2 399
d46aba26
LS
400#elif defined(HAVE_MMI)
401
d46aba26
LS
402#define __align8 __attribute__ ((aligned (16)))
403
b0368839 404void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
d46aba26 405
0c6bd2ea
B
406#elif defined(ARCH_SH4)
407
408#define __align8 __attribute__ ((aligned (8)))
409
410void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
411
de6d9b64
FB
412#else
413
414#define __align8
415
416#endif
417
6d4985bb
FB
418#ifdef __GNUC__
419
420struct unaligned_64 { uint64_t l; } __attribute__((packed));
421struct unaligned_32 { uint32_t l; } __attribute__((packed));
669ac79c 422struct unaligned_16 { uint16_t l; } __attribute__((packed));
6d4985bb 423
669ac79c 424#define LD16(a) (((const struct unaligned_16 *) (a))->l)
6d4985bb
FB
425#define LD32(a) (((const struct unaligned_32 *) (a))->l)
426#define LD64(a) (((const struct unaligned_64 *) (a))->l)
427
428#define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
429
430#else /* __GNUC__ */
431
669ac79c 432#define LD16(a) (*((uint16_t*)(a)))
6d4985bb
FB
433#define LD32(a) (*((uint32_t*)(a)))
434#define LD64(a) (*((uint64_t*)(a)))
435
436#define ST32(a, b) *((uint32_t*)(a)) = (b)
437
438#endif /* !__GNUC__ */
439
43f1708f 440/* PSNR */
0c1a9eda 441void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
43f1708f
J
442 int orig_linesize[3], int coded_linesize,
443 AVCodecContext *avctx);
bb6f5690
FB
444
445/* FFT computation */
446
447/* NOTE: soon integer code will be added, so you must use the
448 FFTSample type */
449typedef float FFTSample;
450
451typedef struct FFTComplex {
452 FFTSample re, im;
453} FFTComplex;
454
455typedef struct FFTContext {
456 int nbits;
457 int inverse;
458 uint16_t *revtab;
459 FFTComplex *exptab;
460 FFTComplex *exptab1; /* only used by SSE code */
461 void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
462} FFTContext;
463
464int fft_init(FFTContext *s, int nbits, int inverse);
465void fft_permute(FFTContext *s, FFTComplex *z);
466void fft_calc_c(FFTContext *s, FFTComplex *z);
467void fft_calc_sse(FFTContext *s, FFTComplex *z);
8d268a7d
FB
468void fft_calc_altivec(FFTContext *s, FFTComplex *z);
469
bb6f5690
FB
470static inline void fft_calc(FFTContext *s, FFTComplex *z)
471{
472 s->fft_calc(s, z);
473}
474void fft_end(FFTContext *s);
475
476/* MDCT computation */
477
478typedef struct MDCTContext {
479 int n; /* size of MDCT (i.e. number of input data * 2) */
480 int nbits; /* n = 2^nbits */
481 /* pre/post rotation tables */
482 FFTSample *tcos;
483 FFTSample *tsin;
484 FFTContext fft;
485} MDCTContext;
486
82696bee 487int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
eb4b3dd3 488void ff_imdct_calc(MDCTContext *s, FFTSample *output,
bb6f5690 489 const FFTSample *input, FFTSample *tmp);
eb4b3dd3 490void ff_mdct_calc(MDCTContext *s, FFTSample *out,
bb6f5690 491 const FFTSample *input, FFTSample *tmp);
82696bee 492void ff_mdct_end(MDCTContext *s);
bb6f5690 493
bb198e19
MN
494#define WARPER8_16(name8, name16)\
495static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
496 return name8(s, dst , src , stride, h)\
497 +name8(s, dst+8 , src+8 , stride, h);\
498}
499
500#define WARPER8_16_SQ(name8, name16)\
501static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
502 int score=0;\
503 score +=name8(s, dst , src , stride, 8);\
504 score +=name8(s, dst+8 , src+8 , stride, 8);\
505 if(h==16){\
506 dst += 8*stride;\
507 src += 8*stride;\
508 score +=name8(s, dst , src , stride, 8);\
509 score +=name8(s, dst+8 , src+8 , stride, 8);\
510 }\
511 return score;\
1457ab52
MN
512}
513
95e2ce4a 514#ifndef HAVE_LRINTF
9d85cbd9
FB
515/* XXX: add ISOC specific test to avoid specific BSD testing. */
516/* better than nothing implementation. */
6234d753 517/* btw, rintf() is existing on fbsd too -- alex */
9d85cbd9
FB
518static inline long int lrintf(float x)
519{
ea937d01
FB
520#ifdef CONFIG_WIN32
521 /* XXX: incorrect, but make it compile */
522 return (int)(x);
523#else
9d85cbd9 524 return (int)(rint(x));
ea937d01 525#endif
9d85cbd9
FB
526}
527#endif
528
de6d9b64 529#endif