00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00030 #ifndef AVCODEC_DSPUTIL_H
00031 #define AVCODEC_DSPUTIL_H
00032
00033 #include "libavutil/intreadwrite.h"
00034 #include "avcodec.h"
00035
00036
00037
00038
00039 typedef short DCTELEM;
00040 typedef int DWTELEM;
00041 typedef short IDWTELEM;
00042
00043 void fdct_ifast (DCTELEM *data);
00044 void fdct_ifast248 (DCTELEM *data);
00045 void ff_jpeg_fdct_islow (DCTELEM *data);
00046 void ff_fdct248_islow (DCTELEM *data);
00047
00048 void j_rev_dct (DCTELEM *data);
00049 void j_rev_dct4 (DCTELEM *data);
00050 void j_rev_dct2 (DCTELEM *data);
00051 void j_rev_dct1 (DCTELEM *data);
00052 void ff_wmv2_idct_c(DCTELEM *data);
00053
00054 void ff_fdct_mmx(DCTELEM *block);
00055 void ff_fdct_mmx2(DCTELEM *block);
00056 void ff_fdct_sse2(DCTELEM *block);
00057
00058 void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
00059 void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
00060 void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
00061 void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
00062 void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
00063 void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
00064 void ff_h264_idct_add16_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
00065 void ff_h264_idct_add16intra_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
00066 void ff_h264_idct8_add4_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
00067 void ff_h264_idct_add8_c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
00068
00069 void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1,
00070 const float *src2, int src3, int blocksize, int step);
00071 void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1,
00072 const float *win, float add_bias, int len);
00073 void ff_float_to_int16_c(int16_t *dst, const float *src, long len);
00074 void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels);
00075
00076
00077 extern const uint8_t ff_alternate_horizontal_scan[64];
00078 extern const uint8_t ff_alternate_vertical_scan[64];
00079 extern const uint8_t ff_zigzag_direct[64];
00080 extern const uint8_t ff_zigzag248_direct[64];
00081
00082
00083 #define MAX_NEG_CROP 1024
00084
00085
00086 extern uint32_t ff_squareTbl[512];
00087 extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
00088
00089
00090 void ff_vp3_idct_c(DCTELEM *block);
00091 void ff_vp3_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block);
00092 void ff_vp3_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block);
00093
00094 void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
00095 void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
00096
00097
00098 void ff_vp6_filter_diag4_c(uint8_t *dst, uint8_t *src, int stride,
00099 const int16_t *h_weights, const int16_t *v_weights);
00100
00101
00102 void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00103 void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00104 void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00105 void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00106
00107 void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
00108 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 typedef void (*op_pixels_func)(uint8_t *block, const uint8_t *pixels, int line_size, int h);
00135 typedef void (*tpel_mc_func)(uint8_t *block, const uint8_t *pixels, int line_size, int w, int h);
00136 typedef void (*qpel_mc_func)(uint8_t *dst, uint8_t *src, int stride);
00137 typedef void (*h264_chroma_mc_func)(uint8_t *dst, uint8_t *src, int srcStride, int h, int x, int y);
00138 typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset);
00139 typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset);
00140
00141 #define DEF_OLD_QPEL(name)\
00142 void ff_put_ ## name (uint8_t *dst, uint8_t *src, int stride);\
00143 void ff_put_no_rnd_ ## name (uint8_t *dst, uint8_t *src, int stride);\
00144 void ff_avg_ ## name (uint8_t *dst, uint8_t *src, int stride);
00145
00146 DEF_OLD_QPEL(qpel16_mc11_old_c)
00147 DEF_OLD_QPEL(qpel16_mc31_old_c)
00148 DEF_OLD_QPEL(qpel16_mc12_old_c)
00149 DEF_OLD_QPEL(qpel16_mc32_old_c)
00150 DEF_OLD_QPEL(qpel16_mc13_old_c)
00151 DEF_OLD_QPEL(qpel16_mc33_old_c)
00152 DEF_OLD_QPEL(qpel8_mc11_old_c)
00153 DEF_OLD_QPEL(qpel8_mc31_old_c)
00154 DEF_OLD_QPEL(qpel8_mc12_old_c)
00155 DEF_OLD_QPEL(qpel8_mc32_old_c)
00156 DEF_OLD_QPEL(qpel8_mc13_old_c)
00157 DEF_OLD_QPEL(qpel8_mc33_old_c)
00158
00159 #define CALL_2X_PIXELS(a, b, n)\
00160 static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
00161 b(block , pixels , line_size, h);\
00162 b(block+n, pixels+n, line_size, h);\
00163 }
00164
00165
00166
00167
00168 typedef int (*me_cmp_func)(void *s, uint8_t *blk1, uint8_t *blk2, int line_size, int h);
00169
00170
00171
00172 typedef struct slice_buffer_s slice_buffer;
00173
00177 typedef struct ScanTable{
00178 const uint8_t *scantable;
00179 uint8_t permutated[64];
00180 uint8_t raster_end[64];
00181 #if ARCH_PPC
00182
00183 DECLARE_ALIGNED(16, uint8_t, inverse[64]);
00184 #endif
00185 } ScanTable;
00186
00187 void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
00188
00189 void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize,
00190 int block_w, int block_h,
00191 int src_x, int src_y, int w, int h);
00192
00196 typedef struct DSPContext {
00197
00198 void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size);
00199 void (*diff_pixels)(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
00200 void (*put_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
00201 void (*put_signed_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
00202 void (*add_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
00203 void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
00204 void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
00205 int (*sum_abs_dctelem)(DCTELEM *block);
00209 void (*gmc1)(uint8_t *dst, uint8_t *src, int srcStride, int h, int x16, int y16, int rounder);
00213 void (*gmc )(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
00214 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
00215 void (*clear_block)(DCTELEM *block);
00216 void (*clear_blocks)(DCTELEM *blocks);
00217 int (*pix_sum)(uint8_t * pix, int line_size);
00218 int (*pix_norm1)(uint8_t * pix, int line_size);
00219
00220
00221 me_cmp_func sad[6];
00222 me_cmp_func sse[6];
00223 me_cmp_func hadamard8_diff[6];
00224 me_cmp_func dct_sad[6];
00225 me_cmp_func quant_psnr[6];
00226 me_cmp_func bit[6];
00227 me_cmp_func rd[6];
00228 me_cmp_func vsad[6];
00229 me_cmp_func vsse[6];
00230 me_cmp_func nsse[6];
00231 me_cmp_func w53[6];
00232 me_cmp_func w97[6];
00233 me_cmp_func dct_max[6];
00234 me_cmp_func dct264_sad[6];
00235
00236 me_cmp_func me_pre_cmp[6];
00237 me_cmp_func me_cmp[6];
00238 me_cmp_func me_sub_cmp[6];
00239 me_cmp_func mb_cmp[6];
00240 me_cmp_func ildct_cmp[6];
00241 me_cmp_func frame_skip_cmp[6];
00242
00243 int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
00244 int size);
00245
00256 op_pixels_func put_pixels_tab[4][4];
00257
00268 op_pixels_func avg_pixels_tab[4][4];
00269
00280 op_pixels_func put_no_rnd_pixels_tab[4][4];
00281
00292 op_pixels_func avg_no_rnd_pixels_tab[4][4];
00293
00294 void (*put_no_rnd_pixels_l2[2])(uint8_t *block, const uint8_t *a, const uint8_t *b, int line_size, int h);
00295
00306 tpel_mc_func put_tpel_pixels_tab[11];
00307 tpel_mc_func avg_tpel_pixels_tab[11];
00308
00309 qpel_mc_func put_qpel_pixels_tab[2][16];
00310 qpel_mc_func avg_qpel_pixels_tab[2][16];
00311 qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
00312 qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
00313 qpel_mc_func put_mspel_pixels_tab[8];
00314
00318 h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
00319
00320 h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab[3];
00321 h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
00322
00323 qpel_mc_func put_h264_qpel_pixels_tab[4][16];
00324 qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
00325
00326 qpel_mc_func put_2tap_qpel_pixels_tab[4][16];
00327 qpel_mc_func avg_2tap_qpel_pixels_tab[4][16];
00328
00329 h264_weight_func weight_h264_pixels_tab[10];
00330 h264_biweight_func biweight_h264_pixels_tab[10];
00331
00332
00333 qpel_mc_func put_cavs_qpel_pixels_tab[2][16];
00334 qpel_mc_func avg_cavs_qpel_pixels_tab[2][16];
00335 void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
00336 void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
00337 void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
00338 void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
00339 void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
00340
00341 me_cmp_func pix_abs[2][4];
00342
00343
00344 void (*add_bytes)(uint8_t *dst, uint8_t *src, int w);
00345 void (*add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w);
00346 void (*diff_bytes)(uint8_t *dst, uint8_t *src1, uint8_t *src2,int w);
00351 void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top);
00352 void (*add_hfyu_median_prediction)(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top);
00353
00354 void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
00355 void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
00356
00357 void (*h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
00358 void (*h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
00359
00360 void (*h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta);
00361 void (*h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta);
00362 void (*h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
00363 void (*h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
00364 void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
00365 void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
00366
00367 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],
00368 int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field);
00369
00370 void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
00371 void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
00372
00373 void (*h261_loop_filter)(uint8_t *src, int stride);
00374
00375 void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale);
00376 void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale);
00377
00378 void (*vp3_v_loop_filter)(uint8_t *src, int stride, int *bounding_values);
00379 void (*vp3_h_loop_filter)(uint8_t *src, int stride, int *bounding_values);
00380
00381 void (*vp6_filter_diag4)(uint8_t *dst, uint8_t *src, int stride,
00382 const int16_t *h_weights,const int16_t *v_weights);
00383
00384
00385 void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
00386 void (*ac3_downmix)(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len);
00387
00388 void (*flac_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc);
00389
00390 void (*vector_fmul)(float *dst, const float *src, int len);
00391 void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len);
00392
00393 void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step);
00394
00395 void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len);
00396
00397 void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len);
00398
00399
00400
00401 void (*float_to_int16)(int16_t *dst, const float *src, long len);
00402 void (*float_to_int16_interleave)(int16_t *dst, const float **src, long len, int channels);
00403
00404
00405 void (*fdct)(DCTELEM *block);
00406 void (*fdct248)(DCTELEM *block);
00407
00408
00409 void (*idct)(DCTELEM *block);
00410
00416 void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
00417
00422 void (*idct_add)(uint8_t *dest, int line_size, DCTELEM *block);
00423
00436 uint8_t idct_permutation[64];
00437 int idct_permutation_type;
00438 #define FF_NO_IDCT_PERM 1
00439 #define FF_LIBMPEG2_IDCT_PERM 2
00440 #define FF_SIMPLE_IDCT_PERM 3
00441 #define FF_TRANSPOSE_IDCT_PERM 4
00442 #define FF_PARTTRANS_IDCT_PERM 5
00443 #define FF_SSE2_IDCT_PERM 6
00444
00445 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
00446 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
00447 #define BASIS_SHIFT 16
00448 #define RECON_SHIFT 6
00449
00450 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
00451 #define EDGE_WIDTH 16
00452
00453
00454
00455
00456
00457
00458 void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride);
00459 void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
00460 void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
00461 void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
00462 void (*h264_dct)(DCTELEM block[4][4]);
00463 void (*h264_idct_add16)(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
00464 void (*h264_idct8_add4)(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
00465 void (*h264_idct_add8)(uint8_t **dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
00466 void (*h264_idct_add16intra)(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
00467
00468
00469 void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
00470 void (*horizontal_compose97i)(IDWTELEM *b, int width);
00471 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);
00472
00473 void (*prefetch)(void *mem, int stride, int h);
00474
00475 void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00476
00477
00478 void (*vc1_inv_trans_8x8)(DCTELEM *b);
00479 void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block);
00480 void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block);
00481 void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block);
00482 void (*vc1_v_overlap)(uint8_t* src, int stride);
00483 void (*vc1_h_overlap)(uint8_t* src, int stride);
00484
00485
00486
00487 op_pixels_func put_vc1_mspel_pixels_tab[16];
00488
00489
00490 void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize);
00491 void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize,
00492 int * range, int * sum, int edges);
00493
00494
00499 void (*add_int16)(int16_t *v1, int16_t *v2, int len);
00504 void (*sub_int16)(int16_t *v1, int16_t *v2, int len);
00510 int32_t (*scalarproduct_int16)(int16_t *v1, int16_t *v2, int len, int shift);
00511
00512
00513 qpel_mc_func put_rv30_tpel_pixels_tab[4][16];
00514 qpel_mc_func avg_rv30_tpel_pixels_tab[4][16];
00515
00516
00517 qpel_mc_func put_rv40_qpel_pixels_tab[4][16];
00518 qpel_mc_func avg_rv40_qpel_pixels_tab[4][16];
00519 h264_chroma_mc_func put_rv40_chroma_pixels_tab[3];
00520 h264_chroma_mc_func avg_rv40_chroma_pixels_tab[3];
00521 } DSPContext;
00522
00523 void dsputil_static_init(void);
00524 void dsputil_init(DSPContext* p, AVCodecContext *avctx);
00525
00526 int ff_check_alignment(void);
00527
00532 void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
00533
00534 void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
00535
00536 #define BYTE_VEC32(c) ((c)*0x01010101UL)
00537
00538 static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
00539 {
00540 return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
00541 }
00542
00543 static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
00544 {
00545 return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
00546 }
00547
00548 static inline int get_penalty_factor(int lambda, int lambda2, int type){
00549 switch(type&0xFF){
00550 default:
00551 case FF_CMP_SAD:
00552 return lambda>>FF_LAMBDA_SHIFT;
00553 case FF_CMP_DCT:
00554 return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
00555 case FF_CMP_W53:
00556 return (4*lambda)>>(FF_LAMBDA_SHIFT);
00557 case FF_CMP_W97:
00558 return (2*lambda)>>(FF_LAMBDA_SHIFT);
00559 case FF_CMP_SATD:
00560 case FF_CMP_DCT264:
00561 return (2*lambda)>>FF_LAMBDA_SHIFT;
00562 case FF_CMP_RD:
00563 case FF_CMP_PSNR:
00564 case FF_CMP_SSE:
00565 case FF_CMP_NSSE:
00566 return lambda2>>FF_LAMBDA_SHIFT;
00567 case FF_CMP_BIT:
00568 return 1;
00569 }
00570 }
00571
00577 #define emms_c()
00578
00579
00580
00581 int mm_support(void);
00582
00583 void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
00584 void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx);
00585 void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
00586 void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
00587 void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
00588 void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
00589 void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
00590 void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
00591 void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
00592
00593 #define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v)
00594
00595 #if HAVE_MMX
00596
00597 #undef emms_c
00598
00599 extern int mm_flags;
00600
00601 void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
00602 void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
00603 void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
00604
00605 static inline void emms(void)
00606 {
00607 __asm__ volatile ("emms;":::"memory");
00608 }
00609
00610
00611 #define emms_c() \
00612 {\
00613 if (mm_flags & FF_MM_MMX)\
00614 emms();\
00615 }
00616
00617 void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
00618
00619 #elif ARCH_ARM
00620
00621 extern int mm_flags;
00622
00623 #if HAVE_NEON
00624 # define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
00625 # define STRIDE_ALIGN 16
00626 #endif
00627
00628 #elif ARCH_PPC
00629
00630 extern int mm_flags;
00631
00632 #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
00633 #define STRIDE_ALIGN 16
00634
00635 #elif HAVE_MMI
00636
00637 #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
00638 #define STRIDE_ALIGN 16
00639
00640 #else
00641
00642 #define mm_flags 0
00643 #define mm_support() 0
00644
00645 #endif
00646
00647 #ifndef DECLARE_ALIGNED_8
00648 # define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v)
00649 #endif
00650
00651 #ifndef STRIDE_ALIGN
00652 # define STRIDE_ALIGN 8
00653 #endif
00654
00655
00656 void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
00657 int orig_linesize[3], int coded_linesize,
00658 AVCodecContext *avctx);
00659
00660
00661
00662
00663
00664 typedef float FFTSample;
00665
00666 struct MDCTContext;
00667
00668 typedef struct FFTComplex {
00669 FFTSample re, im;
00670 } FFTComplex;
00671
00672 typedef struct FFTContext {
00673 int nbits;
00674 int inverse;
00675 uint16_t *revtab;
00676 FFTComplex *exptab;
00677 FFTComplex *exptab1;
00678 FFTComplex *tmp_buf;
00679 void (*fft_permute)(struct FFTContext *s, FFTComplex *z);
00680 void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
00681 void (*imdct_calc)(struct MDCTContext *s, FFTSample *output, const FFTSample *input);
00682 void (*imdct_half)(struct MDCTContext *s, FFTSample *output, const FFTSample *input);
00683 } FFTContext;
00684
00685 extern FFTSample* ff_cos_tabs[13];
00686
00692 int ff_fft_init(FFTContext *s, int nbits, int inverse);
00693 void ff_fft_permute_c(FFTContext *s, FFTComplex *z);
00694 void ff_fft_permute_sse(FFTContext *s, FFTComplex *z);
00695 void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
00696 void ff_fft_calc_sse(FFTContext *s, FFTComplex *z);
00697 void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z);
00698 void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z);
00699 void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z);
00700
00704 static inline void ff_fft_permute(FFTContext *s, FFTComplex *z)
00705 {
00706 s->fft_permute(s, z);
00707 }
00712 static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
00713 {
00714 s->fft_calc(s, z);
00715 }
00716 void ff_fft_end(FFTContext *s);
00717
00718
00719
00720 typedef struct MDCTContext {
00721 int n;
00722 int nbits;
00723
00724 FFTSample *tcos;
00725 FFTSample *tsin;
00726 FFTContext fft;
00727 } MDCTContext;
00728
00729 static inline void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input)
00730 {
00731 s->fft.imdct_calc(s, output, input);
00732 }
00733 static inline void ff_imdct_half(MDCTContext *s, FFTSample *output, const FFTSample *input)
00734 {
00735 s->fft.imdct_half(s, output, input);
00736 }
00737
00744 void ff_kbd_window_init(float *window, float alpha, int n);
00745
00751 void ff_sine_window_init(float *window, int n);
00752 extern float ff_sine_128 [ 128];
00753 extern float ff_sine_256 [ 256];
00754 extern float ff_sine_512 [ 512];
00755 extern float ff_sine_1024[1024];
00756 extern float ff_sine_2048[2048];
00757 extern float ff_sine_4096[4096];
00758 extern float *ff_sine_windows[6];
00759
00760 int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
00761 void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input);
00762 void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input);
00763 void ff_imdct_calc_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input);
00764 void ff_imdct_half_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input);
00765 void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input);
00766 void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input);
00767 void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output, const FFTSample *input);
00768 void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input);
00769 void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input);
00770 void ff_mdct_end(MDCTContext *s);
00771
00772
00773
00774 enum RDFTransformType {
00775 RDFT,
00776 IRDFT,
00777 RIDFT,
00778 IRIDFT,
00779 };
00780
00781 typedef struct {
00782 int nbits;
00783 int inverse;
00784 int sign_convention;
00785
00786
00787 FFTSample *tcos;
00788 FFTSample *tsin;
00789 FFTContext fft;
00790 } RDFTContext;
00791
00797 int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans);
00798 void ff_rdft_calc(RDFTContext *s, FFTSample *data);
00799 void ff_rdft_end(RDFTContext *s);
00800
00801 #define WRAPPER8_16(name8, name16)\
00802 static int name16(void *s, uint8_t *dst, uint8_t *src, int stride, int h){\
00803 return name8(s, dst , src , stride, h)\
00804 +name8(s, dst+8 , src+8 , stride, h);\
00805 }
00806
00807 #define WRAPPER8_16_SQ(name8, name16)\
00808 static int name16(void *s, uint8_t *dst, uint8_t *src, int stride, int h){\
00809 int score=0;\
00810 score +=name8(s, dst , src , stride, 8);\
00811 score +=name8(s, dst+8 , src+8 , stride, 8);\
00812 if(h==16){\
00813 dst += 8*stride;\
00814 src += 8*stride;\
00815 score +=name8(s, dst , src , stride, 8);\
00816 score +=name8(s, dst+8 , src+8 , stride, 8);\
00817 }\
00818 return score;\
00819 }
00820
00821
00822 static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00823 {
00824 int i;
00825 for(i=0; i<h; i++)
00826 {
00827 AV_WN16(dst , AV_RN16(src ));
00828 dst+=dstStride;
00829 src+=srcStride;
00830 }
00831 }
00832
00833 static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00834 {
00835 int i;
00836 for(i=0; i<h; i++)
00837 {
00838 AV_WN32(dst , AV_RN32(src ));
00839 dst+=dstStride;
00840 src+=srcStride;
00841 }
00842 }
00843
00844 static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00845 {
00846 int i;
00847 for(i=0; i<h; i++)
00848 {
00849 AV_WN32(dst , AV_RN32(src ));
00850 AV_WN32(dst+4 , AV_RN32(src+4 ));
00851 dst+=dstStride;
00852 src+=srcStride;
00853 }
00854 }
00855
00856 static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00857 {
00858 int i;
00859 for(i=0; i<h; i++)
00860 {
00861 AV_WN32(dst , AV_RN32(src ));
00862 AV_WN32(dst+4 , AV_RN32(src+4 ));
00863 dst[8]= src[8];
00864 dst+=dstStride;
00865 src+=srcStride;
00866 }
00867 }
00868
00869 static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00870 {
00871 int i;
00872 for(i=0; i<h; i++)
00873 {
00874 AV_WN32(dst , AV_RN32(src ));
00875 AV_WN32(dst+4 , AV_RN32(src+4 ));
00876 AV_WN32(dst+8 , AV_RN32(src+8 ));
00877 AV_WN32(dst+12, AV_RN32(src+12));
00878 dst+=dstStride;
00879 src+=srcStride;
00880 }
00881 }
00882
00883 static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00884 {
00885 int i;
00886 for(i=0; i<h; i++)
00887 {
00888 AV_WN32(dst , AV_RN32(src ));
00889 AV_WN32(dst+4 , AV_RN32(src+4 ));
00890 AV_WN32(dst+8 , AV_RN32(src+8 ));
00891 AV_WN32(dst+12, AV_RN32(src+12));
00892 dst[16]= src[16];
00893 dst+=dstStride;
00894 src+=srcStride;
00895 }
00896 }
00897
00898 #endif