reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
[libav.git] / libavcodec / dsputil.h
CommitLineData
ff4ec49e
FB
1/*
2 * DSP utils
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
de6d9b64
FB
19#ifndef DSPUTIL_H
20#define DSPUTIL_H
21
22#include "common.h"
43f1708f 23#include "avcodec.h"
de6d9b64 24
44eb4951 25//#define DEBUG
de6d9b64
FB
26/* dct code */
27typedef short DCTELEM;
28
03c94ede 29void fdct_ifast (DCTELEM *data);
28db7fce 30void ff_jpeg_fdct_islow (DCTELEM *data);
de6d9b64
FB
31
32void j_rev_dct (DCTELEM *data);
33
34void fdct_mmx(DCTELEM *block);
35
e0eac44e
FB
36/* encoding scans */
37extern UINT8 ff_alternate_horizontal_scan[64];
38extern UINT8 ff_alternate_vertical_scan[64];
39extern UINT8 zigzag_direct[64];
40
5a240838
MN
41/* permutation table */
42extern UINT8 permutation[64];
43
de6d9b64
FB
44/* pixel operations */
45#define MAX_NEG_CROP 384
46
47/* temporary */
48extern UINT32 squareTbl[512];
0cfa9713 49extern UINT8 cropTbl[256 + 2 * MAX_NEG_CROP];
de6d9b64
FB
50
51void dsputil_init(void);
52
53/* pixel ops : interface with DCT */
54
4af7bcc1 55extern void (*ff_idct)(DCTELEM *block);
8ee14970
FB
56extern void (*ff_idct_put)(UINT8 *dest, int line_size, DCTELEM *block);
57extern void (*ff_idct_add)(UINT8 *dest, int line_size, DCTELEM *block);
de6d9b64 58extern void (*get_pixels)(DCTELEM *block, const UINT8 *pixels, int line_size);
9dbcbd92 59extern void (*diff_pixels)(DCTELEM *block, const UINT8 *s1, const UINT8 *s2, int stride);
de6d9b64
FB
60extern void (*put_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size);
61extern void (*add_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size);
44eb4951 62extern void (*gmc1)(UINT8 *dst, UINT8 *src, int srcStride, int h, int x16, int y16, int rounder);
649c00c9 63extern void (*clear_blocks)(DCTELEM *blocks);
3aa102be
MN
64extern int (*pix_sum)(UINT8 * pix, int line_size);
65extern int (*pix_norm1)(UINT8 * pix, int line_size);
66
44eb4951 67
de6d9b64
FB
68
69void get_pixels_c(DCTELEM *block, const UINT8 *pixels, int line_size);
9dbcbd92 70void diff_pixels_c(DCTELEM *block, const UINT8 *s1, const UINT8 *s2, int stride);
de6d9b64
FB
71void put_pixels_clamped_c(const DCTELEM *block, UINT8 *pixels, int line_size);
72void add_pixels_clamped_c(const DCTELEM *block, UINT8 *pixels, int line_size);
649c00c9 73void clear_blocks_c(DCTELEM *blocks);
de6d9b64
FB
74
75/* add and put pixel (decoding) */
76typedef void (*op_pixels_func)(UINT8 *block, const UINT8 *pixels, int line_size, int h);
44eb4951 77typedef void (*qpel_mc_func)(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int mx, int my);
de6d9b64
FB
78
79extern op_pixels_func put_pixels_tab[4];
80extern op_pixels_func avg_pixels_tab[4];
81extern op_pixels_func put_no_rnd_pixels_tab[4];
82extern op_pixels_func avg_no_rnd_pixels_tab[4];
44eb4951
MN
83extern qpel_mc_func qpel_mc_rnd_tab[16];
84extern qpel_mc_func qpel_mc_no_rnd_tab[16];
85
de6d9b64
FB
86/* motion estimation */
87
ba6802de 88typedef int (*op_pixels_abs_func)(UINT8 *blk1, UINT8 *blk2, int line_size);
de6d9b64
FB
89
90extern op_pixels_abs_func pix_abs16x16;
91extern op_pixels_abs_func pix_abs16x16_x2;
92extern op_pixels_abs_func pix_abs16x16_y2;
93extern op_pixels_abs_func pix_abs16x16_xy2;
ba6802de
MN
94extern op_pixels_abs_func pix_abs8x8;
95extern op_pixels_abs_func pix_abs8x8_x2;
96extern op_pixels_abs_func pix_abs8x8_y2;
97extern op_pixels_abs_func pix_abs8x8_xy2;
98
99int pix_abs16x16_c(UINT8 *blk1, UINT8 *blk2, int lx);
100int pix_abs16x16_x2_c(UINT8 *blk1, UINT8 *blk2, int lx);
101int pix_abs16x16_y2_c(UINT8 *blk1, UINT8 *blk2, int lx);
102int pix_abs16x16_xy2_c(UINT8 *blk1, UINT8 *blk2, int lx);
de6d9b64 103
e0eac44e
FB
104static inline int block_permute_op(int j)
105{
5a240838 106 return permutation[j];
e0eac44e
FB
107}
108
109void block_permute(INT16 *block);
110
3d03c0a2 111#if defined(HAVE_MMX)
de6d9b64
FB
112
113#define MM_MMX 0x0001 /* standard MMX */
114#define MM_3DNOW 0x0004 /* AMD 3DNOW */
115#define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
116#define MM_SSE 0x0008 /* SSE functions */
117#define MM_SSE2 0x0010 /* PIV SSE2 functions */
118
119extern int mm_flags;
120
121int mm_support(void);
122
123static inline void emms(void)
124{
fb16b7e7
FB
125 __asm __volatile ("emms;":::"memory");
126}
127
128#define emms_c() \
129{\
130 if (mm_flags & MM_MMX)\
131 emms();\
de6d9b64
FB
132}
133
134#define __align8 __attribute__ ((aligned (8)))
135
136void dsputil_init_mmx(void);
57060b1e 137void dsputil_set_bit_exact_mmx(void);
de6d9b64 138
3d03c0a2
FB
139#elif defined(ARCH_ARMV4L)
140
141#define emms_c()
142
143/* This is to use 4 bytes read to the IDCT pointers for some 'zero'
144 line ptimizations */
145#define __align8 __attribute__ ((aligned (4)))
146
147void dsputil_init_armv4l(void);
148
c34270f5
FB
149#elif defined(HAVE_MLIB)
150
151#define emms_c()
152
153/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
154#define __align8 __attribute__ ((aligned (8)))
155
156void dsputil_init_mlib(void);
157
1e98dffb
NK
158#elif defined(ARCH_ALPHA)
159
160#define emms_c()
161#define __align8 __attribute__ ((aligned (8)))
162
163void dsputil_init_alpha(void);
164
59925ef2
BF
165#elif defined(ARCH_POWERPC)
166
167#define emms_c()
168#define __align8 __attribute__ ((aligned (16)))
169
ab6c65f6 170void dsputil_init_ppc(void);
59925ef2 171
de6d9b64
FB
172#else
173
fb16b7e7
FB
174#define emms_c()
175
de6d9b64
FB
176#define __align8
177
178#endif
179
6d4985bb
FB
180#ifdef __GNUC__
181
182struct unaligned_64 { uint64_t l; } __attribute__((packed));
183struct unaligned_32 { uint32_t l; } __attribute__((packed));
184
185#define LD32(a) (((const struct unaligned_32 *) (a))->l)
186#define LD64(a) (((const struct unaligned_64 *) (a))->l)
187
188#define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
189
190#else /* __GNUC__ */
191
192#define LD32(a) (*((uint32_t*)(a)))
193#define LD64(a) (*((uint64_t*)(a)))
194
195#define ST32(a, b) *((uint32_t*)(a)) = (b)
196
197#endif /* !__GNUC__ */
198
43f1708f
J
199/* PSNR */
200void get_psnr(UINT8 *orig_image[3], UINT8 *coded_image[3],
201 int orig_linesize[3], int coded_linesize,
202 AVCodecContext *avctx);
203
de6d9b64 204#endif