3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of FFmpeg.
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.
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.
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
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
30 #ifndef FFMPEG_DSPUTIL_H
31 #define FFMPEG_DSPUTIL_H
38 typedef short DCTELEM
;
40 typedef short IDWTELEM
;
42 void fdct_ifast (DCTELEM
*data
);
43 void fdct_ifast248 (DCTELEM
*data
);
44 void ff_jpeg_fdct_islow (DCTELEM
*data
);
45 void ff_fdct248_islow (DCTELEM
*data
);
47 void j_rev_dct (DCTELEM
*data
);
48 void j_rev_dct4 (DCTELEM
*data
);
49 void j_rev_dct2 (DCTELEM
*data
);
50 void j_rev_dct1 (DCTELEM
*data
);
51 void ff_wmv2_idct_c(DCTELEM
*data
);
53 void ff_fdct_mmx(DCTELEM
*block
);
54 void ff_fdct_mmx2(DCTELEM
*block
);
55 void ff_fdct_sse2(DCTELEM
*block
);
57 void ff_h264_idct8_add_c(uint8_t *dst
, DCTELEM
*block
, int stride
);
58 void ff_h264_idct_add_c(uint8_t *dst
, DCTELEM
*block
, int stride
);
59 void ff_h264_idct8_dc_add_c(uint8_t *dst
, DCTELEM
*block
, int stride
);
60 void ff_h264_idct_dc_add_c(uint8_t *dst
, DCTELEM
*block
, int stride
);
61 void ff_h264_lowres_idct_add_c(uint8_t *dst
, int stride
, DCTELEM
*block
);
62 void ff_h264_lowres_idct_put_c(uint8_t *dst
, int stride
, DCTELEM
*block
);
64 void ff_vector_fmul_add_add_c(float *dst
, const float *src0
, const float *src1
,
65 const float *src2
, int src3
, int blocksize
, int step
);
66 void ff_vector_fmul_window_c(float *dst
, const float *src0
, const float *src1
,
67 const float *win
, float add_bias
, int len
);
68 void ff_float_to_int16_c(int16_t *dst
, const float *src
, long len
);
71 extern const uint8_t ff_alternate_horizontal_scan
[64];
72 extern const uint8_t ff_alternate_vertical_scan
[64];
73 extern const uint8_t ff_zigzag_direct
[64];
74 extern const uint8_t ff_zigzag248_direct
[64];
76 /* pixel operations */
77 #define MAX_NEG_CROP 1024
80 extern uint32_t ff_squareTbl
[512];
81 extern uint8_t ff_cropTbl
[256 + 2 * MAX_NEG_CROP
];
83 /* VP3 DSP functions */
84 void ff_vp3_idct_c(DCTELEM
*block
/* align 16*/);
85 void ff_vp3_idct_put_c(uint8_t *dest
/*align 8*/, int line_size
, DCTELEM
*block
/*align 16*/);
86 void ff_vp3_idct_add_c(uint8_t *dest
/*align 8*/, int line_size
, DCTELEM
*block
/*align 16*/);
88 /* 1/2^n downscaling functions from imgconvert.c */
89 void ff_img_copy_plane(uint8_t *dst
, int dst_wrap
, const uint8_t *src
, int src_wrap
, int width
, int height
);
90 void ff_shrink22(uint8_t *dst
, int dst_wrap
, const uint8_t *src
, int src_wrap
, int width
, int height
);
91 void ff_shrink44(uint8_t *dst
, int dst_wrap
, const uint8_t *src
, int src_wrap
, int width
, int height
);
92 void ff_shrink88(uint8_t *dst
, int dst_wrap
, const uint8_t *src
, int src_wrap
, int width
, int height
);
94 void ff_gmc_c(uint8_t *dst
, uint8_t *src
, int stride
, int h
, int ox
, int oy
,
95 int dxx
, int dxy
, int dyx
, int dyy
, int shift
, int r
, int width
, int height
);
97 /* minimum alignment rules ;)
98 If you notice errors in the align stuff, need more alignment for some ASM code
99 for some CPU or need to use a function with less aligned data then send a mail
100 to the ffmpeg-devel mailing list, ...
102 !warning These alignments might not match reality, (missing attribute((align))
103 stuff somewhere possible).
104 I (Michael) did not check them, these are just the alignments which I think
105 could be reached easily ...
107 !future video codecs might need functions with less strict alignment
111 void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
112 void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
113 void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
114 void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
115 void clear_blocks_c(DCTELEM *blocks);
118 /* add and put pixel (decoding) */
119 // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
120 //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
121 typedef void (*op_pixels_func
)(uint8_t *block
/*align width (8 or 16)*/, const uint8_t *pixels
/*align 1*/, int line_size
, int h
);
122 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
);
123 typedef void (*qpel_mc_func
)(uint8_t *dst
/*align width (8 or 16)*/, uint8_t *src
/*align 1*/, int stride
);
124 typedef void (*h264_chroma_mc_func
)(uint8_t *dst
/*align 8*/, uint8_t *src
/*align 1*/, int srcStride
, int h
, int x
, int y
);
125 typedef void (*h264_weight_func
)(uint8_t *block
, int stride
, int log2_denom
, int weight
, int offset
);
126 typedef void (*h264_biweight_func
)(uint8_t *dst
, uint8_t *src
, int stride
, int log2_denom
, int weightd
, int weights
, int offset
);
128 #define DEF_OLD_QPEL(name)\
129 void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
130 void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
131 void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
133 DEF_OLD_QPEL(qpel16_mc11_old_c
)
134 DEF_OLD_QPEL(qpel16_mc31_old_c
)
135 DEF_OLD_QPEL(qpel16_mc12_old_c
)
136 DEF_OLD_QPEL(qpel16_mc32_old_c
)
137 DEF_OLD_QPEL(qpel16_mc13_old_c
)
138 DEF_OLD_QPEL(qpel16_mc33_old_c
)
139 DEF_OLD_QPEL(qpel8_mc11_old_c
)
140 DEF_OLD_QPEL(qpel8_mc31_old_c
)
141 DEF_OLD_QPEL(qpel8_mc12_old_c
)
142 DEF_OLD_QPEL(qpel8_mc32_old_c
)
143 DEF_OLD_QPEL(qpel8_mc13_old_c
)
144 DEF_OLD_QPEL(qpel8_mc33_old_c
)
146 #define CALL_2X_PIXELS(a, b, n)\
147 static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
148 b(block , pixels , line_size, h);\
149 b(block+n, pixels+n, line_size, h);\
152 /* motion estimation */
153 // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
154 // although currently h<4 is not used as functions with width <8 are neither used nor implemented
155 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))*/;
159 typedef struct slice_buffer_s slice_buffer
;
164 typedef struct ScanTable
{
165 const uint8_t *scantable
;
166 uint8_t permutated
[64];
167 uint8_t raster_end
[64];
169 /** Used by dct_quantize_altivec to find last-non-zero */
170 DECLARE_ALIGNED(16, uint8_t, inverse
[64]);
174 void ff_init_scantable(uint8_t *, ScanTable
*st
, const uint8_t *src_scantable
);
176 void ff_emulated_edge_mc(uint8_t *buf
, uint8_t *src
, int linesize
,
177 int block_w
, int block_h
,
178 int src_x
, int src_y
, int w
, int h
);
183 typedef struct DSPContext
{
184 /* pixel ops : interface with DCT */
185 void (*get_pixels
)(DCTELEM
*block
/*align 16*/, const uint8_t *pixels
/*align 8*/, int line_size
);
186 void (*diff_pixels
)(DCTELEM
*block
/*align 16*/, const uint8_t *s1
/*align 8*/, const uint8_t *s2
/*align 8*/, int stride
);
187 void (*put_pixels_clamped
)(const DCTELEM
*block
/*align 16*/, uint8_t *pixels
/*align 8*/, int line_size
);
188 void (*put_signed_pixels_clamped
)(const DCTELEM
*block
/*align 16*/, uint8_t *pixels
/*align 8*/, int line_size
);
189 void (*add_pixels_clamped
)(const DCTELEM
*block
/*align 16*/, uint8_t *pixels
/*align 8*/, int line_size
);
190 void (*add_pixels8
)(uint8_t *pixels
, DCTELEM
*block
, int line_size
);
191 void (*add_pixels4
)(uint8_t *pixels
, DCTELEM
*block
, int line_size
);
192 int (*sum_abs_dctelem
)(DCTELEM
*block
/*align 16*/);
194 * translational global motion compensation.
196 void (*gmc1
)(uint8_t *dst
/*align 8*/, uint8_t *src
/*align 1*/, int srcStride
, int h
, int x16
, int y16
, int rounder
);
198 * global motion compensation.
200 void (*gmc
)(uint8_t *dst
/*align 8*/, uint8_t *src
/*align 1*/, int stride
, int h
, int ox
, int oy
,
201 int dxx
, int dxy
, int dyx
, int dyy
, int shift
, int r
, int width
, int height
);
202 void (*clear_blocks
)(DCTELEM
*blocks
/*align 16*/);
203 int (*pix_sum
)(uint8_t * pix
, int line_size
);
204 int (*pix_norm1
)(uint8_t * pix
, int line_size
);
205 // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
207 me_cmp_func sad
[5]; /* identical to pix_absAxA except additional void * */
209 me_cmp_func hadamard8_diff
[5];
210 me_cmp_func dct_sad
[5];
211 me_cmp_func quant_psnr
[5];
219 me_cmp_func dct_max
[5];
220 me_cmp_func dct264_sad
[5];
222 me_cmp_func me_pre_cmp
[5];
223 me_cmp_func me_cmp
[5];
224 me_cmp_func me_sub_cmp
[5];
225 me_cmp_func mb_cmp
[5];
226 me_cmp_func ildct_cmp
[5]; //only width 16 used
227 me_cmp_func frame_skip_cmp
[5]; //only width 8 used
229 int (*ssd_int8_vs_int16
)(const int8_t *pix1
, const int16_t *pix2
,
233 * Halfpel motion compensation with rounding (a+b+1)>>1.
234 * this is an array[4][4] of motion compensation functions for 4
235 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
236 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
237 * @param block destination where the result is stored
238 * @param pixels source
239 * @param line_size number of bytes in a horizontal line of block
242 op_pixels_func put_pixels_tab
[4][4];
245 * Halfpel motion compensation with rounding (a+b+1)>>1.
246 * This is an array[4][4] of motion compensation functions for 4
247 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
248 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
249 * @param block destination into which the result is averaged (a+b+1)>>1
250 * @param pixels source
251 * @param line_size number of bytes in a horizontal line of block
254 op_pixels_func avg_pixels_tab
[4][4];
257 * Halfpel motion compensation with no rounding (a+b)>>1.
258 * this is an array[2][4] of motion compensation functions for 2
259 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
260 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
261 * @param block destination where the result is stored
262 * @param pixels source
263 * @param line_size number of bytes in a horizontal line of block
266 op_pixels_func put_no_rnd_pixels_tab
[4][4];
269 * Halfpel motion compensation with no rounding (a+b)>>1.
270 * this is an array[2][4] of motion compensation functions for 2
271 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
272 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
273 * @param block destination into which the result is averaged (a+b)>>1
274 * @param pixels source
275 * @param line_size number of bytes in a horizontal line of block
278 op_pixels_func avg_no_rnd_pixels_tab
[4][4];
280 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
);
283 * Thirdpel motion compensation with rounding (a+b+1)>>1.
284 * this is an array[12] of motion compensation functions for the 9 thirdpe
286 * *pixels_tab[ xthirdpel + 4*ythirdpel ]
287 * @param block destination where the result is stored
288 * @param pixels source
289 * @param line_size number of bytes in a horizontal line of block
292 tpel_mc_func put_tpel_pixels_tab
[11]; //FIXME individual func ptr per width?
293 tpel_mc_func avg_tpel_pixels_tab
[11]; //FIXME individual func ptr per width?
295 qpel_mc_func put_qpel_pixels_tab
[2][16];
296 qpel_mc_func avg_qpel_pixels_tab
[2][16];
297 qpel_mc_func put_no_rnd_qpel_pixels_tab
[2][16];
298 qpel_mc_func avg_no_rnd_qpel_pixels_tab
[2][16];
299 qpel_mc_func put_mspel_pixels_tab
[8];
304 h264_chroma_mc_func put_h264_chroma_pixels_tab
[3];
305 /* This is really one func used in VC-1 decoding */
306 h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab
[3];
307 h264_chroma_mc_func avg_h264_chroma_pixels_tab
[3];
309 qpel_mc_func put_h264_qpel_pixels_tab
[4][16];
310 qpel_mc_func avg_h264_qpel_pixels_tab
[4][16];
312 qpel_mc_func put_2tap_qpel_pixels_tab
[4][16];
313 qpel_mc_func avg_2tap_qpel_pixels_tab
[4][16];
315 h264_weight_func weight_h264_pixels_tab
[10];
316 h264_biweight_func biweight_h264_pixels_tab
[10];
319 qpel_mc_func put_cavs_qpel_pixels_tab
[2][16];
320 qpel_mc_func avg_cavs_qpel_pixels_tab
[2][16];
321 void (*cavs_filter_lv
)(uint8_t *pix
, int stride
, int alpha
, int beta
, int tc
, int bs1
, int bs2
);
322 void (*cavs_filter_lh
)(uint8_t *pix
, int stride
, int alpha
, int beta
, int tc
, int bs1
, int bs2
);
323 void (*cavs_filter_cv
)(uint8_t *pix
, int stride
, int alpha
, int beta
, int tc
, int bs1
, int bs2
);
324 void (*cavs_filter_ch
)(uint8_t *pix
, int stride
, int alpha
, int beta
, int tc
, int bs1
, int bs2
);
325 void (*cavs_idct8_add
)(uint8_t *dst
, DCTELEM
*block
, int stride
);
327 me_cmp_func pix_abs
[2][4];
329 /* huffyuv specific */
330 void (*add_bytes
)(uint8_t *dst
/*align 16*/, uint8_t *src
/*align 16*/, int w
);
331 void (*add_bytes_l2
)(uint8_t *dst
/*align 16*/, uint8_t *src1
/*align 16*/, uint8_t *src2
/*align 16*/, int w
);
332 void (*diff_bytes
)(uint8_t *dst
/*align 16*/, uint8_t *src1
/*align 16*/, uint8_t *src2
/*align 1*/,int w
);
334 * subtract huffyuv's variant of median prediction
335 * note, this might read from src1[-1], src2[-1]
337 void (*sub_hfyu_median_prediction
)(uint8_t *dst
, uint8_t *src1
, uint8_t *src2
, int w
, int *left
, int *left_top
);
338 /* this might write to dst[w] */
339 void (*add_png_paeth_prediction
)(uint8_t *dst
, uint8_t *src
, uint8_t *top
, int w
, int bpp
);
340 void (*bswap_buf
)(uint32_t *dst
, const uint32_t *src
, int w
);
342 void (*h264_v_loop_filter_luma
)(uint8_t *pix
, int stride
, int alpha
, int beta
, int8_t *tc0
);
343 void (*h264_h_loop_filter_luma
)(uint8_t *pix
, int stride
, int alpha
, int beta
, int8_t *tc0
);
344 void (*h264_v_loop_filter_chroma
)(uint8_t *pix
, int stride
, int alpha
, int beta
, int8_t *tc0
);
345 void (*h264_h_loop_filter_chroma
)(uint8_t *pix
, int stride
, int alpha
, int beta
, int8_t *tc0
);
346 void (*h264_v_loop_filter_chroma_intra
)(uint8_t *pix
, int stride
, int alpha
, int beta
);
347 void (*h264_h_loop_filter_chroma_intra
)(uint8_t *pix
, int stride
, int alpha
, int beta
);
348 // h264_loop_filter_strength: simd only. the C version is inlined in h264.c
349 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],
350 int bidir
, int edges
, int step
, int mask_mv0
, int mask_mv1
);
352 void (*h263_v_loop_filter
)(uint8_t *src
, int stride
, int qscale
);
353 void (*h263_h_loop_filter
)(uint8_t *src
, int stride
, int qscale
);
355 void (*h261_loop_filter
)(uint8_t *src
, int stride
);
357 void (*x8_v_loop_filter
)(uint8_t *src
, int stride
, int qscale
);
358 void (*x8_h_loop_filter
)(uint8_t *src
, int stride
, int qscale
);
360 /* assume len is a multiple of 4, and arrays are 16-byte aligned */
361 void (*vorbis_inverse_coupling
)(float *mag
, float *ang
, int blocksize
);
362 /* no alignment needed */
363 void (*flac_compute_autocorr
)(const int32_t *data
, int len
, int lag
, double *autoc
);
364 /* assume len is a multiple of 8, and arrays are 16-byte aligned */
365 void (*vector_fmul
)(float *dst
, const float *src
, int len
);
366 void (*vector_fmul_reverse
)(float *dst
, const float *src0
, const float *src1
, int len
);
367 /* assume len is a multiple of 8, and src arrays are 16-byte aligned */
368 void (*vector_fmul_add_add
)(float *dst
, const float *src0
, const float *src1
, const float *src2
, int src3
, int len
, int step
);
369 /* assume len is a multiple of 4, and arrays are 16-byte aligned */
370 void (*vector_fmul_window
)(float *dst
, const float *src0
, const float *src1
, const float *win
, float add_bias
, int len
);
372 /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
373 * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
374 void (*float_to_int16
)(int16_t *dst
, const float *src
, long len
);
375 void (*float_to_int16_interleave
)(int16_t *dst
, const float **src
, long len
, int channels
);
378 void (*fdct
)(DCTELEM
*block
/* align 16*/);
379 void (*fdct248
)(DCTELEM
*block
/* align 16*/);
382 void (*idct
)(DCTELEM
*block
/* align 16*/);
385 * block -> idct -> clip to unsigned 8 bit -> dest.
386 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
387 * @param line_size size in bytes of a horizontal line of dest
389 void (*idct_put
)(uint8_t *dest
/*align 8*/, int line_size
, DCTELEM
*block
/*align 16*/);
392 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
393 * @param line_size size in bytes of a horizontal line of dest
395 void (*idct_add
)(uint8_t *dest
/*align 8*/, int line_size
, DCTELEM
*block
/*align 16*/);
398 * idct input permutation.
399 * several optimized IDCTs need a permutated input (relative to the normal order of the reference
401 * this permutation must be performed before the idct_put/add, note, normally this can be merged
402 * with the zigzag/alternate scan<br>
403 * an example to avoid confusion:
404 * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
405 * - (x -> referece dct -> reference idct -> x)
406 * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
407 * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
409 uint8_t idct_permutation
[64];
410 int idct_permutation_type
;
411 #define FF_NO_IDCT_PERM 1
412 #define FF_LIBMPEG2_IDCT_PERM 2
413 #define FF_SIMPLE_IDCT_PERM 3
414 #define FF_TRANSPOSE_IDCT_PERM 4
415 #define FF_PARTTRANS_IDCT_PERM 5
416 #define FF_SSE2_IDCT_PERM 6
418 int (*try_8x8basis
)(int16_t rem
[64], int16_t weight
[64], int16_t basis
[64], int scale
);
419 void (*add_8x8basis
)(int16_t rem
[64], int16_t basis
[64], int scale
);
420 #define BASIS_SHIFT 16
421 #define RECON_SHIFT 6
423 void (*draw_edges
)(uint8_t *buf
, int wrap
, int width
, int height
, int w
);
424 #define EDGE_WIDTH 16
427 void (*h264_idct_add
)(uint8_t *dst
, DCTELEM
*block
, int stride
);
428 void (*h264_idct8_add
)(uint8_t *dst
, DCTELEM
*block
, int stride
);
429 void (*h264_idct_dc_add
)(uint8_t *dst
, DCTELEM
*block
, int stride
);
430 void (*h264_idct8_dc_add
)(uint8_t *dst
, DCTELEM
*block
, int stride
);
431 void (*h264_dct
)(DCTELEM block
[4][4]);
434 void (*vertical_compose97i
)(IDWTELEM
*b0
, IDWTELEM
*b1
, IDWTELEM
*b2
, IDWTELEM
*b3
, IDWTELEM
*b4
, IDWTELEM
*b5
, int width
);
435 void (*horizontal_compose97i
)(IDWTELEM
*b
, int width
);
436 void (*inner_add_yblock
)(const 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
);
438 void (*prefetch
)(void *mem
, int stride
, int h
);
440 void (*shrink
[4])(uint8_t *dst
, int dst_wrap
, const uint8_t *src
, int src_wrap
, int width
, int height
);
443 void (*vc1_inv_trans_8x8
)(DCTELEM
*b
);
444 void (*vc1_inv_trans_8x4
)(uint8_t *dest
, int line_size
, DCTELEM
*block
);
445 void (*vc1_inv_trans_4x8
)(uint8_t *dest
, int line_size
, DCTELEM
*block
);
446 void (*vc1_inv_trans_4x4
)(uint8_t *dest
, int line_size
, DCTELEM
*block
);
447 void (*vc1_v_overlap
)(uint8_t* src
, int stride
);
448 void (*vc1_h_overlap
)(uint8_t* src
, int stride
);
449 /* put 8x8 block with bicubic interpolation and quarterpel precision
450 * last argument is actually round value instead of height
452 op_pixels_func put_vc1_mspel_pixels_tab
[16];
454 /* intrax8 functions */
455 void (*x8_spatial_compensation
[12])(uint8_t *src
, uint8_t *dst
, int linesize
);
456 void (*x8_setup_spatial_compensation
)(uint8_t *src
, uint8_t *dst
, int linesize
,
457 int * range
, int * sum
, int edges
);
461 * Add contents of the second vector to the first one.
462 * @param len length of vectors, should be multiple of 16
464 void (*add_int16
)(int16_t *v1
/*align 16*/, int16_t *v2
, int len
);
466 * Add contents of the second vector to the first one.
467 * @param len length of vectors, should be multiple of 16
469 void (*sub_int16
)(int16_t *v1
/*align 16*/, int16_t *v2
, int len
);
471 * Calculate scalar product of two vectors.
472 * @param len length of vectors, should be multiple of 16
473 * @param shift number of bits to discard from product
475 int32_t (*scalarproduct_int16
)(int16_t *v1
, int16_t *v2
/*align 16*/, int len
, int shift
);
478 void dsputil_static_init(void);
479 void dsputil_init(DSPContext
* p
, AVCodecContext
*avctx
);
481 int ff_check_alignment(void);
484 * permute block according to permuatation.
485 * @param last last non zero element in scantable order
487 void ff_block_permute(DCTELEM
*block
, uint8_t *permutation
, const uint8_t *scantable
, int last
);
489 void ff_set_cmp(DSPContext
* c
, me_cmp_func
*cmp
, int type
);
491 #define BYTE_VEC32(c) ((c)*0x01010101UL)
493 static inline uint32_t rnd_avg32(uint32_t a
, uint32_t b
)
495 return (a
| b
) - (((a
^ b
) & ~BYTE_VEC32(0x01)) >> 1);
498 static inline uint32_t no_rnd_avg32(uint32_t a
, uint32_t b
)
500 return (a
& b
) + (((a
^ b
) & ~BYTE_VEC32(0x01)) >> 1);
503 static inline int get_penalty_factor(int lambda
, int lambda2
, int type
){
507 return lambda
>>FF_LAMBDA_SHIFT
;
509 return (3*lambda
)>>(FF_LAMBDA_SHIFT
+1);
511 return (4*lambda
)>>(FF_LAMBDA_SHIFT
);
513 return (2*lambda
)>>(FF_LAMBDA_SHIFT
);
516 return (2*lambda
)>>FF_LAMBDA_SHIFT
;
521 return lambda2
>>FF_LAMBDA_SHIFT
;
529 * this must be called between any dsp function and float/double code.
530 * for example sin(); dsp->idct_put(); emms_c(); cos()
534 /* should be defined by architectures supporting
535 one or more MultiMedia extension */
536 int mm_support(void);
538 void dsputil_init_alpha(DSPContext
* c
, AVCodecContext
*avctx
);
539 void dsputil_init_armv4l(DSPContext
* c
, AVCodecContext
*avctx
);
540 void dsputil_init_bfin(DSPContext
* c
, AVCodecContext
*avctx
);
541 void dsputil_init_mlib(DSPContext
* c
, AVCodecContext
*avctx
);
542 void dsputil_init_mmi(DSPContext
* c
, AVCodecContext
*avctx
);
543 void dsputil_init_mmx(DSPContext
* c
, AVCodecContext
*avctx
);
544 void dsputil_init_ppc(DSPContext
* c
, AVCodecContext
*avctx
);
545 void dsputil_init_sh4(DSPContext
* c
, AVCodecContext
*avctx
);
546 void dsputil_init_vis(DSPContext
* c
, AVCodecContext
*avctx
);
548 #define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v)
550 #if defined(HAVE_MMX)
554 #define MM_MMX 0x0001 /* standard MMX */
555 #define MM_3DNOW 0x0004 /* AMD 3DNOW */
556 #define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
557 #define MM_SSE 0x0008 /* SSE functions */
558 #define MM_SSE2 0x0010 /* PIV SSE2 functions */
559 #define MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
560 #define MM_SSE3 0x0040 /* Prescott SSE3 functions */
561 #define MM_SSSE3 0x0080 /* Conroe SSSE3 functions */
565 void add_pixels_clamped_mmx(const DCTELEM
*block
, uint8_t *pixels
, int line_size
);
566 void put_pixels_clamped_mmx(const DCTELEM
*block
, uint8_t *pixels
, int line_size
);
567 void put_signed_pixels_clamped_mmx(const DCTELEM
*block
, uint8_t *pixels
, int line_size
);
569 static inline void emms(void)
571 asm volatile ("emms;":::"memory");
577 if (mm_flags & MM_MMX)\
581 void dsputil_init_pix_mmx(DSPContext
* c
, AVCodecContext
*avctx
);
583 #elif defined(ARCH_ARMV4L)
585 #define MM_IWMMXT 0x0100 /* XScale IWMMXT */
589 #elif defined(ARCH_POWERPC)
591 #define MM_ALTIVEC 0x0001 /* standard AltiVec */
595 #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
596 #define STRIDE_ALIGN 16
598 #elif defined(HAVE_MMI)
600 #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
601 #define STRIDE_ALIGN 16
606 #define mm_support() 0
610 #ifndef DECLARE_ALIGNED_8
611 # define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v)
615 # define STRIDE_ALIGN 8
619 void get_psnr(uint8_t *orig_image
[3], uint8_t *coded_image
[3],
620 int orig_linesize
[3], int coded_linesize
,
621 AVCodecContext
*avctx
);
623 /* FFT computation */
625 /* NOTE: soon integer code will be added, so you must use the
627 typedef float FFTSample
;
631 typedef struct FFTComplex
{
635 typedef struct FFTContext
{
640 FFTComplex
*exptab1
; /* only used by SSE code */
641 void (*fft_calc
)(struct FFTContext
*s
, FFTComplex
*z
);
642 void (*imdct_calc
)(struct MDCTContext
*s
, FFTSample
*output
,
643 const FFTSample
*input
, FFTSample
*tmp
);
644 void (*imdct_half
)(struct MDCTContext
*s
, FFTSample
*output
,
645 const FFTSample
*input
, FFTSample
*tmp
);
648 int ff_fft_init(FFTContext
*s
, int nbits
, int inverse
);
649 void ff_fft_permute(FFTContext
*s
, FFTComplex
*z
);
650 void ff_fft_calc_c(FFTContext
*s
, FFTComplex
*z
);
651 void ff_fft_calc_sse(FFTContext
*s
, FFTComplex
*z
);
652 void ff_fft_calc_3dn(FFTContext
*s
, FFTComplex
*z
);
653 void ff_fft_calc_3dn2(FFTContext
*s
, FFTComplex
*z
);
654 void ff_fft_calc_altivec(FFTContext
*s
, FFTComplex
*z
);
656 static inline void ff_fft_calc(FFTContext
*s
, FFTComplex
*z
)
660 void ff_fft_end(FFTContext
*s
);
662 /* MDCT computation */
664 typedef struct MDCTContext
{
665 int n
; /* size of MDCT (i.e. number of input data * 2) */
666 int nbits
; /* n = 2^nbits */
667 /* pre/post rotation tables */
674 * Generate a Kaiser-Bessel Derived Window.
675 * @param window pointer to half window
676 * @param alpha determines window shape
677 * @param n size of half window
679 void ff_kbd_window_init(float *window
, float alpha
, int n
);
682 * Generate a sine window.
683 * @param window pointer to half window
684 * @param n size of half window
686 void ff_sine_window_init(float *window
, int n
);
688 int ff_mdct_init(MDCTContext
*s
, int nbits
, int inverse
);
689 void ff_imdct_calc(MDCTContext
*s
, FFTSample
*output
,
690 const FFTSample
*input
, FFTSample
*tmp
);
691 void ff_imdct_half(MDCTContext
*s
, FFTSample
*output
,
692 const FFTSample
*input
, FFTSample
*tmp
);
693 void ff_imdct_calc_3dn2(MDCTContext
*s
, FFTSample
*output
,
694 const FFTSample
*input
, FFTSample
*tmp
);
695 void ff_imdct_half_3dn2(MDCTContext
*s
, FFTSample
*output
,
696 const FFTSample
*input
, FFTSample
*tmp
);
697 void ff_imdct_calc_sse(MDCTContext
*s
, FFTSample
*output
,
698 const FFTSample
*input
, FFTSample
*tmp
);
699 void ff_imdct_half_sse(MDCTContext
*s
, FFTSample
*output
,
700 const FFTSample
*input
, FFTSample
*tmp
);
701 void ff_mdct_calc(MDCTContext
*s
, FFTSample
*out
,
702 const FFTSample
*input
, FFTSample
*tmp
);
703 void ff_mdct_end(MDCTContext
*s
);
705 #define WRAPPER8_16(name8, name16)\
706 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
707 return name8(s, dst , src , stride, h)\
708 +name8(s, dst+8 , src+8 , stride, h);\
711 #define WRAPPER8_16_SQ(name8, name16)\
712 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
714 score +=name8(s, dst , src , stride, 8);\
715 score +=name8(s, dst+8 , src+8 , stride, 8);\
719 score +=name8(s, dst , src , stride, 8);\
720 score +=name8(s, dst+8 , src+8 , stride, 8);\
726 static inline void copy_block2(uint8_t *dst
, uint8_t *src
, int dstStride
, int srcStride
, int h
)
731 AV_WN16(dst
, AV_RN16(src
));
737 static inline void copy_block4(uint8_t *dst
, uint8_t *src
, int dstStride
, int srcStride
, int h
)
742 AV_WN32(dst
, AV_RN32(src
));
748 static inline void copy_block8(uint8_t *dst
, uint8_t *src
, int dstStride
, int srcStride
, int h
)
753 AV_WN32(dst
, AV_RN32(src
));
754 AV_WN32(dst
+4 , AV_RN32(src
+4 ));
760 static inline void copy_block9(uint8_t *dst
, uint8_t *src
, int dstStride
, int srcStride
, int h
)
765 AV_WN32(dst
, AV_RN32(src
));
766 AV_WN32(dst
+4 , AV_RN32(src
+4 ));
773 static inline void copy_block16(uint8_t *dst
, uint8_t *src
, int dstStride
, int srcStride
, int h
)
778 AV_WN32(dst
, AV_RN32(src
));
779 AV_WN32(dst
+4 , AV_RN32(src
+4 ));
780 AV_WN32(dst
+8 , AV_RN32(src
+8 ));
781 AV_WN32(dst
+12, AV_RN32(src
+12));
787 static inline void copy_block17(uint8_t *dst
, uint8_t *src
, int dstStride
, int srcStride
, int h
)
792 AV_WN32(dst
, AV_RN32(src
));
793 AV_WN32(dst
+4 , AV_RN32(src
+4 ));
794 AV_WN32(dst
+8 , AV_RN32(src
+8 ));
795 AV_WN32(dst
+12, AV_RN32(src
+12));
802 #endif /* FFMPEG_DSPUTIL_H */