Align the input buffer in ffplay, introduce a public macro for aligned declarations
[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
5509bffa 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ff4ec49e 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;
059715a4 38typedef int DWTELEM;
de6d9b64 39
03c94ede 40void fdct_ifast (DCTELEM *data);
48b1f800 41void fdct_ifast248 (DCTELEM *data);
28db7fce 42void ff_jpeg_fdct_islow (DCTELEM *data);
10acc479 43void ff_fdct248_islow (DCTELEM *data);
de6d9b64
FB
44
45void j_rev_dct (DCTELEM *data);
178fcca8 46void j_rev_dct4 (DCTELEM *data);
9ca358b9 47void j_rev_dct2 (DCTELEM *data);
1aa8c57b 48void j_rev_dct1 (DCTELEM *data);
de6d9b64 49
3f09f52a 50void ff_fdct_mmx(DCTELEM *block);
cf3bf5bb 51void ff_fdct_mmx2(DCTELEM *block);
8fd19ab2 52void ff_fdct_sse2(DCTELEM *block);
de6d9b64 53
43efd19a 54void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
0fa8158d 55void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
ef9d1d15
LM
56void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
57void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
0fa8158d
MN
58void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
59void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
60
eb4825b5
LM
61void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1,
62 const float *src2, int src3, int blocksize, int step);
63void ff_float_to_int16_c(int16_t *dst, const float *src, int len);
64
e0eac44e 65/* encoding scans */
0c1a9eda
ZK
66extern const uint8_t ff_alternate_horizontal_scan[64];
67extern const uint8_t ff_alternate_vertical_scan[64];
68extern const uint8_t ff_zigzag_direct[64];
10acc479 69extern const uint8_t ff_zigzag248_direct[64];
5a240838 70
de6d9b64 71/* pixel operations */
f2e92ef2 72#define MAX_NEG_CROP 1024
de6d9b64
FB
73
74/* temporary */
0c1a9eda
ZK
75extern uint32_t squareTbl[512];
76extern uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
de6d9b64 77
44cb64ee 78/* VP3 DSP functions */
8b6103da
MN
79void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
80void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
81void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
de6d9b64 82
54009d42
MN
83/* 1/2^n downscaling functions from imgconvert.c */
84void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
85void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
86void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
87void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
703c8195
LM
88
89void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
90 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
54009d42 91
b7c27ee6 92/* minimum alignment rules ;)
eb4b3dd3 93if u notice errors in the align stuff, need more alignment for some asm code for some cpu
b7c27ee6
MN
94or need to use a function with less aligned data then send a mail to the ffmpeg-dev list, ...
95
96!warning these alignments might not match reallity, (missing attribute((align)) stuff somewhere possible)
97i (michael) didnt check them, these are just the alignents which i think could be reached easily ...
de6d9b64 98
b7c27ee6
MN
99!future video codecs might need functions with less strict alignment
100*/
101
eb4b3dd3 102/*
0c1a9eda
ZK
103void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
104void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
105void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
106void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
649c00c9 107void clear_blocks_c(DCTELEM *blocks);
eb4b3dd3 108*/
de6d9b64
FB
109
110/* add and put pixel (decoding) */
b7c27ee6 111// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
7d67aa9b 112//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
0c1a9eda 113typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
669ac79c 114typedef 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 115typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
0da71265 116typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
9f2d1b4f 117typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset);
e8b56208 118typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset);
b3184779 119
db794953 120#define DEF_OLD_QPEL(name)\
0c1a9eda
ZK
121void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
122void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
123void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
db794953
MN
124
125DEF_OLD_QPEL(qpel16_mc11_old_c)
126DEF_OLD_QPEL(qpel16_mc31_old_c)
127DEF_OLD_QPEL(qpel16_mc12_old_c)
128DEF_OLD_QPEL(qpel16_mc32_old_c)
129DEF_OLD_QPEL(qpel16_mc13_old_c)
130DEF_OLD_QPEL(qpel16_mc33_old_c)
131DEF_OLD_QPEL(qpel8_mc11_old_c)
132DEF_OLD_QPEL(qpel8_mc31_old_c)
133DEF_OLD_QPEL(qpel8_mc12_old_c)
134DEF_OLD_QPEL(qpel8_mc32_old_c)
135DEF_OLD_QPEL(qpel8_mc13_old_c)
136DEF_OLD_QPEL(qpel8_mc33_old_c)
b3184779
MN
137
138#define CALL_2X_PIXELS(a, b, n)\
139static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
140 b(block , pixels , line_size, h);\
141 b(block+n, pixels+n, line_size, h);\
142}
44eb4951 143
de6d9b64 144/* motion estimation */
7d67aa9b
MN
145// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
146// allthough currently h<4 is not used as functions with width <8 are not used and neither implemented
bb198e19 147typedef 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 148
0da71265 149
059715a4
RE
150// for snow slices
151typedef struct slice_buffer_s slice_buffer;
152
24641185
MN
153/**
154 * DSPContext.
155 */
eb4b3dd3
ZK
156typedef struct DSPContext {
157 /* pixel ops : interface with DCT */
0c1a9eda
ZK
158 void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
159 void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
160 void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
f9ed9d85 161 void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
0c1a9eda 162 void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
36940eca
LM
163 void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
164 void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
d518aebd
MN
165 /**
166 * translational global motion compensation.
167 */
0c1a9eda 168 void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
d518aebd
MN
169 /**
170 * global motion compensation.
171 */
0c1a9eda 172 void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
bb270c08 173 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
eb4b3dd3 174 void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
0c1a9eda
ZK
175 int (*pix_sum)(uint8_t * pix, int line_size);
176 int (*pix_norm1)(uint8_t * pix, int line_size);
bb198e19 177// 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
115329f1 178
622348f9
MN
179 me_cmp_func sad[5]; /* identical to pix_absAxA except additional void * */
180 me_cmp_func sse[5];
181 me_cmp_func hadamard8_diff[5];
182 me_cmp_func dct_sad[5];
183 me_cmp_func quant_psnr[5];
184 me_cmp_func bit[5];
185 me_cmp_func rd[5];
186 me_cmp_func vsad[5];
187 me_cmp_func vsse[5];
e6a2ac34 188 me_cmp_func nsse[5];
26efc54e
MN
189 me_cmp_func w53[5];
190 me_cmp_func w97[5];
0fd6aea1 191 me_cmp_func dct_max[5];
27c61ac5 192 me_cmp_func dct264_sad[5];
1457ab52 193
bb198e19
MN
194 me_cmp_func me_pre_cmp[5];
195 me_cmp_func me_cmp[5];
196 me_cmp_func me_sub_cmp[5];
197 me_cmp_func mb_cmp[5];
622348f9 198 me_cmp_func ildct_cmp[5]; //only width 16 used
0fd6aea1 199 me_cmp_func frame_skip_cmp[5]; //only width 8 used
eb4b3dd3 200
d518aebd
MN
201 /**
202 * Halfpel motion compensation with rounding (a+b+1)>>1.
115329f1 203 * this is an array[4][4] of motion compensation funcions for 4
e5771f4f 204 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
5755c27f 205 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
d518aebd
MN
206 * @param block destination where the result is stored
207 * @param pixels source
208 * @param line_size number of bytes in a horizontal line of block
209 * @param h height
210 */
669ac79c 211 op_pixels_func put_pixels_tab[4][4];
d518aebd
MN
212
213 /**
214 * Halfpel motion compensation with rounding (a+b+1)>>1.
115329f1 215 * This is an array[4][4] of motion compensation functions for 4
e5771f4f 216 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
5755c27f 217 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
d518aebd
MN
218 * @param block destination into which the result is averaged (a+b+1)>>1
219 * @param pixels source
220 * @param line_size number of bytes in a horizontal line of block
221 * @param h height
222 */
da3b9756 223 op_pixels_func avg_pixels_tab[4][4];
d518aebd
MN
224
225 /**
226 * Halfpel motion compensation with no rounding (a+b)>>1.
115329f1 227 * this is an array[2][4] of motion compensation funcions for 2
eb14c713 228 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
5755c27f 229 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
d518aebd
MN
230 * @param block destination where the result is stored
231 * @param pixels source
232 * @param line_size number of bytes in a horizontal line of block
233 * @param h height
234 */
dbc56b39 235 op_pixels_func put_no_rnd_pixels_tab[4][4];
d518aebd
MN
236
237 /**
238 * Halfpel motion compensation with no rounding (a+b)>>1.
115329f1 239 * this is an array[2][4] of motion compensation funcions for 2
eb14c713 240 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
5755c27f 241 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
d518aebd
MN
242 * @param block destination into which the result is averaged (a+b)>>1
243 * @param pixels source
244 * @param line_size number of bytes in a horizontal line of block
245 * @param h height
246 */
dbc56b39 247 op_pixels_func avg_no_rnd_pixels_tab[4][4];
115329f1 248
c0a0170c 249 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);
115329f1 250
669ac79c
MN
251 /**
252 * Thirdpel motion compensation with rounding (a+b+1)>>1.
253 * this is an array[12] of motion compensation funcions for the 9 thirdpel positions<br>
254 * *pixels_tab[ xthirdpel + 4*ythirdpel ]
255 * @param block destination where the result is stored
256 * @param pixels source
257 * @param line_size number of bytes in a horizontal line of block
258 * @param h height
259 */
260 tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
da3b9756
MM
261 tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
262
eb4b3dd3
ZK
263 qpel_mc_func put_qpel_pixels_tab[2][16];
264 qpel_mc_func avg_qpel_pixels_tab[2][16];
265 qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
266 qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
1457ab52 267 qpel_mc_func put_mspel_pixels_tab[8];
115329f1 268
0da71265
MN
269 /**
270 * h264 Chram MC
271 */
272 h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
273 h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
eb4b3dd3 274
80e44bc3
MN
275 qpel_mc_func put_h264_qpel_pixels_tab[4][16];
276 qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
115329f1 277
9f2d1b4f
LM
278 h264_weight_func weight_h264_pixels_tab[10];
279 h264_biweight_func biweight_h264_pixels_tab[10];
115329f1 280
b482e2d1
MN
281 /* AVS specific */
282 qpel_mc_func put_cavs_qpel_pixels_tab[2][16];
283 qpel_mc_func avg_cavs_qpel_pixels_tab[2][16];
284 void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
285 void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
286 void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
287 void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
288 void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
289
bb198e19 290 me_cmp_func pix_abs[2][4];
115329f1 291
11f18faf 292 /* huffyuv specific */
11f18faf 293 void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
1457ab52 294 void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
84705403
MN
295 /**
296 * subtract huffyuv's variant of median prediction
297 * note, this might read from src1[-1], src2[-1]
298 */
299 void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top);
3d2e8cce 300 void (*bswap_buf)(uint32_t *dst, uint32_t *src, int w);
42251a2a 301
5cf08f23
LM
302 void (*h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
303 void (*h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
304 void (*h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
305 void (*h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
306 void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
307 void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
3e20143e
LM
308 // h264_loop_filter_strength: simd only. the C version is inlined in h264.c
309 void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2],
310 int bidir, int edges, int step, int mask_mv0, int mask_mv1);
115329f1 311
332f9ac4
MN
312 void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
313 void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
314
fdbbf2e0 315 void (*h261_loop_filter)(uint8_t *src, int stride);
c6148de2 316
eb4825b5 317 /* assume len is a multiple of 4, and arrays are 16-byte aligned */
2dac4acf 318 void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
eb4825b5 319 /* assume len is a multiple of 8, and arrays are 16-byte aligned */
06972056 320 void (*vector_fmul)(float *dst, const float *src, int len);
eb4825b5
LM
321 void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len);
322 /* assume len is a multiple of 8, and src arrays are 16-byte aligned */
323 void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step);
324
325 /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
98145875 326 * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
eb4825b5 327 void (*float_to_int16)(int16_t *dst, const float *src, int len);
2dac4acf 328
b0368839
MN
329 /* (I)DCT */
330 void (*fdct)(DCTELEM *block/* align 16*/);
10acc479 331 void (*fdct248)(DCTELEM *block/* align 16*/);
115329f1 332
4fb518c3
MN
333 /* IDCT really*/
334 void (*idct)(DCTELEM *block/* align 16*/);
115329f1 335
24641185 336 /**
77c92c2d 337 * block -> idct -> clip to unsigned 8 bit -> dest.
24641185 338 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
a1adf436 339 * @param line_size size in bytes of a horizotal line of dest
24641185 340 */
b0368839 341 void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
115329f1 342
24641185
MN
343 /**
344 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
a1adf436 345 * @param line_size size in bytes of a horizotal line of dest
24641185 346 */
b0368839 347 void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
115329f1 348
24641185 349 /**
77c92c2d 350 * idct input permutation.
05493021
MN
351 * several optimized IDCTs need a permutated input (relative to the normal order of the reference
352 * IDCT)
353 * this permutation must be performed before the idct_put/add, note, normally this can be merged
354 * with the zigzag/alternate scan<br>
24641185
MN
355 * an example to avoid confusion:
356 * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
357 * - (x -> referece dct -> reference idct -> x)
358 * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
359 * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
360 */
b0368839
MN
361 uint8_t idct_permutation[64];
362 int idct_permutation_type;
363#define FF_NO_IDCT_PERM 1
364#define FF_LIBMPEG2_IDCT_PERM 2
365#define FF_SIMPLE_IDCT_PERM 3
366#define FF_TRANSPOSE_IDCT_PERM 4
5773a746 367#define FF_PARTTRANS_IDCT_PERM 5
b0368839 368
364a1797
MN
369 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
370 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
371#define BASIS_SHIFT 16
372#define RECON_SHIFT 6
115329f1 373
0fa8158d 374 void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride);
43efd19a 375 void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
ef9d1d15
LM
376 void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
377 void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
059715a4
RE
378
379 /* snow wavelet */
380 void (*vertical_compose97i)(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
381 void (*horizontal_compose97i)(DWTELEM *b, int width);
382 void (*inner_add_yblock)(uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
513fbd8e
LM
383
384 void (*prefetch)(void *mem, int stride, int h);
54009d42
MN
385
386 void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
64db55ae
KS
387
388 /* vc1 functions */
389 void (*vc1_inv_trans_8x8)(DCTELEM *b);
390 void (*vc1_inv_trans_8x4)(DCTELEM *b, int n);
391 void (*vc1_inv_trans_4x8)(DCTELEM *b, int n);
392 void (*vc1_inv_trans_4x4)(DCTELEM *b, int n);
393 void (*vc1_v_overlap)(uint8_t* src, int stride, int rnd);
394 void (*vc1_h_overlap)(uint8_t* src, int stride, int rnd);
395 /* put 8x8 block with bicubic interpolation and quarterpel precision
396 * last argument is actually round value instead of height
397 */
398 op_pixels_func put_vc1_mspel_pixels_tab[16];
74691b7b 399 op_pixels_func put_vc1_qpel_pixels_tab[16];
eb4b3dd3
ZK
400} DSPContext;
401
59cf08ce 402void dsputil_static_init(void);
b0368839 403void dsputil_init(DSPContext* p, AVCodecContext *avctx);
de6d9b64 404
7801d21d
MN
405/**
406 * permute block according to permuatation.
407 * @param last last non zero element in scantable order
408 */
0c1a9eda 409void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
e0eac44e 410
622348f9
MN
411void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
412
bb270c08 413#define BYTE_VEC32(c) ((c)*0x01010101UL)
d8085ea7
MN
414
415static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
416{
417 return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
418}
419
420static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
421{
422 return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
423}
424
26efc54e
MN
425static inline int get_penalty_factor(int lambda, int lambda2, int type){
426 switch(type&0xFF){
427 default:
428 case FF_CMP_SAD:
429 return lambda>>FF_LAMBDA_SHIFT;
430 case FF_CMP_DCT:
431 return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
432 case FF_CMP_W53:
433 return (4*lambda)>>(FF_LAMBDA_SHIFT);
434 case FF_CMP_W97:
435 return (2*lambda)>>(FF_LAMBDA_SHIFT);
436 case FF_CMP_SATD:
27c61ac5 437 case FF_CMP_DCT264:
26efc54e
MN
438 return (2*lambda)>>FF_LAMBDA_SHIFT;
439 case FF_CMP_RD:
440 case FF_CMP_PSNR:
441 case FF_CMP_SSE:
442 case FF_CMP_NSSE:
443 return lambda2>>FF_LAMBDA_SHIFT;
444 case FF_CMP_BIT:
445 return 1;
446 }
447}
448
24641185 449/**
77c92c2d 450 * Empty mmx state.
24641185
MN
451 * this must be called between any dsp function and float/double code.
452 * for example sin(); dsp->idct_put(); emms_c(); cos()
453 */
eb4b3dd3
ZK
454#define emms_c()
455
e629ab68
RD
456/* should be defined by architectures supporting
457 one or more MultiMedia extension */
458int mm_support(void);
459
68b51e58
SH
460#ifdef __GNUC__
461 #define DECLARE_ALIGNED_16(t,v) t v __attribute__ ((aligned (16)))
462#else
463 #define DECLARE_ALIGNED_16(t,v) __declspec(align(16)) t v
464#endif
92a69cf8 465
3d03c0a2 466#if defined(HAVE_MMX)
de6d9b64 467
18f77016 468#undef emms_c
eb4b3dd3 469
de6d9b64
FB
470#define MM_MMX 0x0001 /* standard MMX */
471#define MM_3DNOW 0x0004 /* AMD 3DNOW */
472#define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
473#define MM_SSE 0x0008 /* SSE functions */
474#define MM_SSE2 0x0010 /* PIV SSE2 functions */
e42a152b 475#define MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
392f6da8 476#define MM_SSE3 0x0040 /* Prescott SSE3 functions */
de6d9b64
FB
477
478extern int mm_flags;
479
0c1a9eda
ZK
480void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
481void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
f9ed9d85 482void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
de6d9b64
FB
483
484static inline void emms(void)
485{
fb16b7e7
FB
486 __asm __volatile ("emms;":::"memory");
487}
488
1457ab52 489
fb16b7e7
FB
490#define emms_c() \
491{\
492 if (mm_flags & MM_MMX)\
493 emms();\
de6d9b64
FB
494}
495
68b51e58
SH
496#ifdef __GNUC__
497 #define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
498#else
499 #define DECLARE_ALIGNED_8(t,v) __declspec(align(8)) t v
500#endif
501
3237f731 502#define STRIDE_ALIGN 8
de6d9b64 503
b0368839
MN
504void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
505void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
2720569a 506
3d03c0a2
FB
507#elif defined(ARCH_ARMV4L)
508
3d03c0a2 509/* This is to use 4 bytes read to the IDCT pointers for some 'zero'
92a69cf8 510 line optimizations */
68b51e58 511#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (4)))
3237f731 512#define STRIDE_ALIGN 4
3d03c0a2 513
eba9ae3c
GB
514#define MM_IWMMXT 0x0100 /* XScale IWMMXT */
515
516extern int mm_flags;
517
b0368839 518void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx);
3d03c0a2 519
c34270f5 520#elif defined(HAVE_MLIB)
c34270f5
FB
521
522/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
68b51e58 523#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
3237f731 524#define STRIDE_ALIGN 8
c34270f5 525
b0368839 526void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
c34270f5 527
44f54ceb
MN
528#elif defined(ARCH_SPARC)
529
530/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
68b51e58 531#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
3237f731 532#define STRIDE_ALIGN 8
44f54ceb
MN
533void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
534
1e98dffb
NK
535#elif defined(ARCH_ALPHA)
536
68b51e58 537#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
3237f731 538#define STRIDE_ALIGN 8
1e98dffb 539
b0368839 540void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
1e98dffb 541
59925ef2
BF
542#elif defined(ARCH_POWERPC)
543
404d2241
BF
544#define MM_ALTIVEC 0x0001 /* standard AltiVec */
545
546extern int mm_flags;
547
3b991c54 548#if defined(HAVE_ALTIVEC) && !defined(CONFIG_DARWIN)
9a197a24 549#define pixel altivec_pixel
3b991c54 550#include <altivec.h>
9a197a24 551#undef pixel
3b991c54
RD
552#endif
553
68b51e58 554#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16)))
3237f731 555#define STRIDE_ALIGN 16
59925ef2 556
b0368839 557void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
59925ef2 558
d46aba26
LS
559#elif defined(HAVE_MMI)
560
68b51e58 561#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16)))
3237f731 562#define STRIDE_ALIGN 16
d46aba26 563
b0368839 564void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
d46aba26 565
0c6bd2ea
B
566#elif defined(ARCH_SH4)
567
68b51e58 568#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
3237f731 569#define STRIDE_ALIGN 8
0c6bd2ea
B
570
571void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
572
de6d9b64
FB
573#else
574
68b51e58 575#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
3237f731 576#define STRIDE_ALIGN 8
de6d9b64
FB
577
578#endif
579
6d4985bb
FB
580#ifdef __GNUC__
581
582struct unaligned_64 { uint64_t l; } __attribute__((packed));
583struct unaligned_32 { uint32_t l; } __attribute__((packed));
669ac79c 584struct unaligned_16 { uint16_t l; } __attribute__((packed));
6d4985bb 585
669ac79c 586#define LD16(a) (((const struct unaligned_16 *) (a))->l)
6d4985bb
FB
587#define LD32(a) (((const struct unaligned_32 *) (a))->l)
588#define LD64(a) (((const struct unaligned_64 *) (a))->l)
589
80e44bc3 590#define ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
6d4985bb
FB
591#define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
592
593#else /* __GNUC__ */
594
669ac79c 595#define LD16(a) (*((uint16_t*)(a)))
6d4985bb
FB
596#define LD32(a) (*((uint32_t*)(a)))
597#define LD64(a) (*((uint64_t*)(a)))
598
dc2bf20e 599#define ST16(a, b) *((uint16_t*)(a)) = (b)
6d4985bb
FB
600#define ST32(a, b) *((uint32_t*)(a)) = (b)
601
602#endif /* !__GNUC__ */
603
43f1708f 604/* PSNR */
0c1a9eda 605void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
43f1708f
J
606 int orig_linesize[3], int coded_linesize,
607 AVCodecContext *avctx);
bb6f5690
FB
608
609/* FFT computation */
610
611/* NOTE: soon integer code will be added, so you must use the
612 FFTSample type */
613typedef float FFTSample;
614
bcfa3e58
LM
615struct MDCTContext;
616
bb6f5690
FB
617typedef struct FFTComplex {
618 FFTSample re, im;
619} FFTComplex;
620
621typedef struct FFTContext {
622 int nbits;
623 int inverse;
624 uint16_t *revtab;
625 FFTComplex *exptab;
626 FFTComplex *exptab1; /* only used by SSE code */
627 void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
bcfa3e58
LM
628 void (*imdct_calc)(struct MDCTContext *s, FFTSample *output,
629 const FFTSample *input, FFTSample *tmp);
bb6f5690
FB
630} FFTContext;
631
68951ecf
GB
632int ff_fft_init(FFTContext *s, int nbits, int inverse);
633void ff_fft_permute(FFTContext *s, FFTComplex *z);
634void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
635void ff_fft_calc_sse(FFTContext *s, FFTComplex *z);
82eb4b0f
ZM
636void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z);
637void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z);
68951ecf 638void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z);
8d268a7d 639
68951ecf 640static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
bb6f5690
FB
641{
642 s->fft_calc(s, z);
643}
68951ecf 644void ff_fft_end(FFTContext *s);
bb6f5690
FB
645
646/* MDCT computation */
647
648typedef struct MDCTContext {
649 int n; /* size of MDCT (i.e. number of input data * 2) */
650 int nbits; /* n = 2^nbits */
651 /* pre/post rotation tables */
652 FFTSample *tcos;
653 FFTSample *tsin;
654 FFTContext fft;
655} MDCTContext;
656
82696bee 657int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
eb4b3dd3 658void ff_imdct_calc(MDCTContext *s, FFTSample *output,
bb6f5690 659 const FFTSample *input, FFTSample *tmp);
bcfa3e58
LM
660void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output,
661 const FFTSample *input, FFTSample *tmp);
eb4b3dd3 662void ff_mdct_calc(MDCTContext *s, FFTSample *out,
bb6f5690 663 const FFTSample *input, FFTSample *tmp);
82696bee 664void ff_mdct_end(MDCTContext *s);
bb6f5690 665
bb198e19
MN
666#define WARPER8_16(name8, name16)\
667static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
668 return name8(s, dst , src , stride, h)\
669 +name8(s, dst+8 , src+8 , stride, h);\
670}
671
672#define WARPER8_16_SQ(name8, name16)\
673static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
674 int score=0;\
675 score +=name8(s, dst , src , stride, 8);\
676 score +=name8(s, dst+8 , src+8 , stride, 8);\
677 if(h==16){\
678 dst += 8*stride;\
679 src += 8*stride;\
680 score +=name8(s, dst , src , stride, 8);\
681 score +=name8(s, dst+8 , src+8 , stride, 8);\
682 }\
683 return score;\
1457ab52
MN
684}
685
de6d9b64 686#endif