Libav 0.7.1
libavcodec/dsputil.h
Go to the documentation of this file.
00001 /*
00002  * DSP utils
00003  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
00004  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * Libav is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 //#define DEBUG
00038 /* dct code */
00039 typedef short DCTELEM;
00040 
00041 void fdct_ifast (DCTELEM *data);
00042 void fdct_ifast248 (DCTELEM *data);
00043 void ff_jpeg_fdct_islow (DCTELEM *data);
00044 void ff_fdct248_islow (DCTELEM *data);
00045 
00046 void j_rev_dct (DCTELEM *data);
00047 void j_rev_dct4 (DCTELEM *data);
00048 void j_rev_dct2 (DCTELEM *data);
00049 void j_rev_dct1 (DCTELEM *data);
00050 void ff_wmv2_idct_c(DCTELEM *data);
00051 
00052 void ff_fdct_mmx(DCTELEM *block);
00053 void ff_fdct_mmx2(DCTELEM *block);
00054 void ff_fdct_sse2(DCTELEM *block);
00055 
00056 #define H264_IDCT(depth) \
00057 void ff_h264_idct8_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
00058 void ff_h264_idct_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
00059 void ff_h264_idct8_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
00060 void ff_h264_idct_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
00061 void ff_h264_lowres_idct_add_ ## depth ## _c(uint8_t *dst, int stride, DCTELEM *block);\
00062 void ff_h264_lowres_idct_put_ ## depth ## _c(uint8_t *dst, int stride, DCTELEM *block);\
00063 void ff_h264_idct_add16_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
00064 void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
00065 void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
00066 void ff_h264_idct_add8_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
00067 void ff_h264_luma_dc_dequant_idct_ ## depth ## _c(DCTELEM *output, DCTELEM *input, int qmul);\
00068 void ff_h264_chroma_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul);
00069 
00070 H264_IDCT( 8)
00071 H264_IDCT( 9)
00072 H264_IDCT(10)
00073 
00074 void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp);
00075 void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc);
00076 
00077 /* encoding scans */
00078 extern const uint8_t ff_alternate_horizontal_scan[64];
00079 extern const uint8_t ff_alternate_vertical_scan[64];
00080 extern const uint8_t ff_zigzag_direct[64];
00081 extern const uint8_t ff_zigzag248_direct[64];
00082 
00083 /* pixel operations */
00084 #define MAX_NEG_CROP 1024
00085 
00086 /* temporary */
00087 extern uint32_t ff_squareTbl[512];
00088 extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
00089 
00090 #define PUTAVG_PIXELS(depth)\
00091 void ff_put_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
00092 void ff_avg_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
00093 void ff_put_pixels16x16_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
00094 void ff_avg_pixels16x16_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);
00095 
00096 PUTAVG_PIXELS( 8)
00097 PUTAVG_PIXELS( 9)
00098 PUTAVG_PIXELS(10)
00099 
00100 #define ff_put_pixels8x8_c ff_put_pixels8x8_8_c
00101 #define ff_avg_pixels8x8_c ff_avg_pixels8x8_8_c
00102 #define ff_put_pixels16x16_c ff_put_pixels16x16_8_c
00103 #define ff_avg_pixels16x16_c ff_avg_pixels16x16_8_c
00104 
00105 /* VP3 DSP functions */
00106 void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
00107 void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00108 void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00109 void ff_vp3_idct_dc_add_c(uint8_t *dest/*align 8*/, int line_size, const DCTELEM *block/*align 16*/);
00110 
00111 void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
00112 void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
00113 
00114 /* Bink functions */
00115 void ff_bink_idct_c    (DCTELEM *block);
00116 void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block);
00117 void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
00118 
00119 /* EA functions */
00120 void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
00121 
00122 /* 1/2^n downscaling functions from imgconvert.c */
00123 void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00124 void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00125 void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00126 
00127 void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
00128               int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
00129 
00130 /* minimum alignment rules ;)
00131 If you notice errors in the align stuff, need more alignment for some ASM code
00132 for some CPU or need to use a function with less aligned data then send a mail
00133 to the libav-devel mailing list, ...
00134 
00135 !warning These alignments might not match reality, (missing attribute((align))
00136 stuff somewhere possible).
00137 I (Michael) did not check them, these are just the alignments which I think
00138 could be reached easily ...
00139 
00140 !future video codecs might need functions with less strict alignment
00141 */
00142 
00143 /*
00144 void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
00145 void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
00146 void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
00147 void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
00148 void clear_blocks_c(DCTELEM *blocks);
00149 */
00150 
00151 /* add and put pixel (decoding) */
00152 // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
00153 //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
00154 typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
00155 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);
00156 typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
00157 typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
00158 
00159 typedef void (*op_fill_func)(uint8_t *block/*align width (8 or 16)*/, uint8_t value, int line_size, int h);
00160 
00161 #define DEF_OLD_QPEL(name)\
00162 void ff_put_        ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
00163 void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
00164 void ff_avg_        ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
00165 
00166 DEF_OLD_QPEL(qpel16_mc11_old_c)
00167 DEF_OLD_QPEL(qpel16_mc31_old_c)
00168 DEF_OLD_QPEL(qpel16_mc12_old_c)
00169 DEF_OLD_QPEL(qpel16_mc32_old_c)
00170 DEF_OLD_QPEL(qpel16_mc13_old_c)
00171 DEF_OLD_QPEL(qpel16_mc33_old_c)
00172 DEF_OLD_QPEL(qpel8_mc11_old_c)
00173 DEF_OLD_QPEL(qpel8_mc31_old_c)
00174 DEF_OLD_QPEL(qpel8_mc12_old_c)
00175 DEF_OLD_QPEL(qpel8_mc32_old_c)
00176 DEF_OLD_QPEL(qpel8_mc13_old_c)
00177 DEF_OLD_QPEL(qpel8_mc33_old_c)
00178 
00179 #define CALL_2X_PIXELS(a, b, n)\
00180 static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
00181     b(block  , pixels  , line_size, h);\
00182     b(block+n, pixels+n, line_size, h);\
00183 }
00184 
00185 /* motion estimation */
00186 // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
00187 // although currently h<4 is not used as functions with width <8 are neither used nor implemented
00188 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))*/;
00189 
00193 typedef struct ScanTable{
00194     const uint8_t *scantable;
00195     uint8_t permutated[64];
00196     uint8_t raster_end[64];
00197 #if ARCH_PPC
00198 
00199     DECLARE_ALIGNED(16, uint8_t, inverse)[64];
00200 #endif
00201 } ScanTable;
00202 
00203 void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
00204 
00205 #define EMULATED_EDGE(depth) \
00206 void ff_emulated_edge_mc_ ## depth (uint8_t *buf, const uint8_t *src, int linesize,\
00207                          int block_w, int block_h,\
00208                          int src_x, int src_y, int w, int h);
00209 
00210 EMULATED_EDGE(8)
00211 EMULATED_EDGE(9)
00212 EMULATED_EDGE(10)
00213 
00214 #define ff_emulated_edge_mc ff_emulated_edge_mc_8
00215 
00216 void ff_add_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize);
00217 void ff_put_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize);
00218 void ff_put_signed_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize);
00219 
00223 typedef struct DSPContext {
00224     /* pixel ops : interface with DCT */
00225     void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
00226     void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
00227     void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00228     void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00229     void (*put_pixels_nonclamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00230     void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00231     void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
00232     void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
00233     int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/);
00246     void (*emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize,
00247                              int block_w, int block_h,
00248                              int src_x, int src_y, int w, int h);
00252     void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
00256     void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
00257                     int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
00258     void (*clear_block)(DCTELEM *block/*align 16*/);
00259     void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
00260     int (*pix_sum)(uint8_t * pix, int line_size);
00261     int (*pix_norm1)(uint8_t * pix, int line_size);
00262 // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
00263 
00264     me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
00265     me_cmp_func sse[6];
00266     me_cmp_func hadamard8_diff[6];
00267     me_cmp_func dct_sad[6];
00268     me_cmp_func quant_psnr[6];
00269     me_cmp_func bit[6];
00270     me_cmp_func rd[6];
00271     me_cmp_func vsad[6];
00272     me_cmp_func vsse[6];
00273     me_cmp_func nsse[6];
00274     me_cmp_func w53[6];
00275     me_cmp_func w97[6];
00276     me_cmp_func dct_max[6];
00277     me_cmp_func dct264_sad[6];
00278 
00279     me_cmp_func me_pre_cmp[6];
00280     me_cmp_func me_cmp[6];
00281     me_cmp_func me_sub_cmp[6];
00282     me_cmp_func mb_cmp[6];
00283     me_cmp_func ildct_cmp[6]; //only width 16 used
00284     me_cmp_func frame_skip_cmp[6]; //only width 8 used
00285 
00286     int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
00287                              int size);
00288 
00299     op_pixels_func put_pixels_tab[4][4];
00300 
00311     op_pixels_func avg_pixels_tab[4][4];
00312 
00323     op_pixels_func put_no_rnd_pixels_tab[4][4];
00324 
00335     op_pixels_func avg_no_rnd_pixels_tab[4][4];
00336 
00337     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);
00338 
00349     tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
00350     tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
00351 
00352     qpel_mc_func put_qpel_pixels_tab[2][16];
00353     qpel_mc_func avg_qpel_pixels_tab[2][16];
00354     qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
00355     qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
00356     qpel_mc_func put_mspel_pixels_tab[8];
00357 
00361     h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
00362     h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
00363 
00364     qpel_mc_func put_h264_qpel_pixels_tab[4][16];
00365     qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
00366 
00367     qpel_mc_func put_2tap_qpel_pixels_tab[4][16];
00368     qpel_mc_func avg_2tap_qpel_pixels_tab[4][16];
00369 
00370     me_cmp_func pix_abs[2][4];
00371 
00372     /* huffyuv specific */
00373     void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
00374     void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w);
00375     void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
00380     void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top);
00381     void (*add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top);
00382     int  (*add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left);
00383     void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha);
00384     /* this might write to dst[w] */
00385     void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
00386     void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
00387     void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
00388 
00389     void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
00390     void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
00391 
00392     void (*h261_loop_filter)(uint8_t *src, int stride);
00393 
00394     void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale);
00395     void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale);
00396 
00397     void (*vp3_idct_dc_add)(uint8_t *dest/*align 8*/, int line_size, const DCTELEM *block/*align 16*/);
00398     void (*vp3_v_loop_filter)(uint8_t *src, int stride, int *bounding_values);
00399     void (*vp3_h_loop_filter)(uint8_t *src, int stride, int *bounding_values);
00400 
00401     /* assume len is a multiple of 4, and arrays are 16-byte aligned */
00402     void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
00403     void (*ac3_downmix)(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len);
00404     /* assume len is a multiple of 8, and arrays are 16-byte aligned */
00405     void (*vector_fmul)(float *dst, const float *src0, const float *src1, int len);
00406     void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len);
00407     /* assume len is a multiple of 8, and src arrays are 16-byte aligned */
00408     void (*vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len);
00409     /* assume len is a multiple of 4, and arrays are 16-byte aligned */
00410     void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len);
00411     /* assume len is a multiple of 8, and arrays are 16-byte aligned */
00412     void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */);
00421     void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
00422                                int len);
00435     void (*vector_fmul_sv_scalar[2])(float *dst, const float *src,
00436                                      const float **sv, float mul, int len);
00447     void (*sv_fmul_scalar[2])(float *dst, const float **sv,
00448                               float mul, int len);
00455     float (*scalarproduct_float)(const float *v1, const float *v2, int len);
00462     void (*butterflies_float)(float *restrict v1, float *restrict v2, int len);
00463 
00464     /* (I)DCT */
00465     void (*fdct)(DCTELEM *block/* align 16*/);
00466     void (*fdct248)(DCTELEM *block/* align 16*/);
00467 
00468     /* IDCT really*/
00469     void (*idct)(DCTELEM *block/* align 16*/);
00470 
00476     void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00477 
00482     void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00483 
00496     uint8_t idct_permutation[64];
00497     int idct_permutation_type;
00498 #define FF_NO_IDCT_PERM 1
00499 #define FF_LIBMPEG2_IDCT_PERM 2
00500 #define FF_SIMPLE_IDCT_PERM 3
00501 #define FF_TRANSPOSE_IDCT_PERM 4
00502 #define FF_PARTTRANS_IDCT_PERM 5
00503 #define FF_SSE2_IDCT_PERM 6
00504 
00505     int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
00506     void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
00507 #define BASIS_SHIFT 16
00508 #define RECON_SHIFT 6
00509 
00510     void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w, int h, int sides);
00511 #define EDGE_WIDTH 16
00512 #define EDGE_TOP    1
00513 #define EDGE_BOTTOM 2
00514 
00515     void (*prefetch)(void *mem, int stride, int h);
00516 
00517     void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00518 
00519     /* mlp/truehd functions */
00520     void (*mlp_filter_channel)(int32_t *state, const int32_t *coeff,
00521                                int firorder, int iirorder,
00522                                unsigned int filter_shift, int32_t mask, int blocksize,
00523                                int32_t *sample_buffer);
00524 
00525     /* intrax8 functions */
00526     void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize);
00527     void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize,
00528            int * range, int * sum,  int edges);
00529 
00535     int32_t (*scalarproduct_int16)(const int16_t *v1, const int16_t *v2/*align 16*/, int len, int shift);
00536     /* ape functions */
00542     int32_t (*scalarproduct_and_madd_int16)(int16_t *v1/*align 16*/, const int16_t *v2, const int16_t *v3, int len, int mul);
00543 
00555     void (*apply_window_int16)(int16_t *output, const int16_t *input,
00556                                const int16_t *window, unsigned int len);
00557 
00558     /* rv30 functions */
00559     qpel_mc_func put_rv30_tpel_pixels_tab[4][16];
00560     qpel_mc_func avg_rv30_tpel_pixels_tab[4][16];
00561 
00562     /* rv40 functions */
00563     qpel_mc_func put_rv40_qpel_pixels_tab[4][16];
00564     qpel_mc_func avg_rv40_qpel_pixels_tab[4][16];
00565     h264_chroma_mc_func put_rv40_chroma_pixels_tab[3];
00566     h264_chroma_mc_func avg_rv40_chroma_pixels_tab[3];
00567 
00568     /* bink functions */
00569     op_fill_func fill_block_tab[2];
00570     void (*scale_block)(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize);
00571 } DSPContext;
00572 
00573 void dsputil_static_init(void);
00574 void dsputil_init(DSPContext* p, AVCodecContext *avctx);
00575 
00576 int ff_check_alignment(void);
00577 
00582 void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
00583 
00584 void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
00585 
00586 #define         BYTE_VEC32(c)   ((c)*0x01010101UL)
00587 #define         BYTE_VEC64(c)   ((c)*0x0001000100010001UL)
00588 
00589 static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
00590 {
00591     return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
00592 }
00593 
00594 static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
00595 {
00596     return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
00597 }
00598 
00599 static inline uint64_t rnd_avg64(uint64_t a, uint64_t b)
00600 {
00601     return (a | b) - (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1);
00602 }
00603 
00604 static inline uint64_t no_rnd_avg64(uint64_t a, uint64_t b)
00605 {
00606     return (a & b) + (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1);
00607 }
00608 
00609 static inline int get_penalty_factor(int lambda, int lambda2, int type){
00610     switch(type&0xFF){
00611     default:
00612     case FF_CMP_SAD:
00613         return lambda>>FF_LAMBDA_SHIFT;
00614     case FF_CMP_DCT:
00615         return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
00616     case FF_CMP_W53:
00617         return (4*lambda)>>(FF_LAMBDA_SHIFT);
00618     case FF_CMP_W97:
00619         return (2*lambda)>>(FF_LAMBDA_SHIFT);
00620     case FF_CMP_SATD:
00621     case FF_CMP_DCT264:
00622         return (2*lambda)>>FF_LAMBDA_SHIFT;
00623     case FF_CMP_RD:
00624     case FF_CMP_PSNR:
00625     case FF_CMP_SSE:
00626     case FF_CMP_NSSE:
00627         return lambda2>>FF_LAMBDA_SHIFT;
00628     case FF_CMP_BIT:
00629         return 1;
00630     }
00631 }
00632 
00633 void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
00634 void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx);
00635 void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
00636 void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
00637 void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
00638 void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
00639 void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
00640 void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
00641 void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
00642 
00643 void ff_dsputil_init_dwt(DSPContext *c);
00644 void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx);
00645 void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx);
00646 void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx);
00647 void ff_mlp_init(DSPContext* c, AVCodecContext *avctx);
00648 void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx);
00649 
00650 #if ARCH_ARM
00651 
00652 #if HAVE_NEON
00653 #   define STRIDE_ALIGN 16
00654 #endif
00655 
00656 #elif ARCH_PPC
00657 
00658 #define STRIDE_ALIGN 16
00659 
00660 #elif HAVE_MMI
00661 
00662 #define STRIDE_ALIGN 16
00663 
00664 #endif
00665 
00666 #ifndef STRIDE_ALIGN
00667 #   define STRIDE_ALIGN 8
00668 #endif
00669 
00670 #define LOCAL_ALIGNED_A(a, t, v, s, o, ...)             \
00671     uint8_t la_##v[sizeof(t s o) + (a)];                \
00672     t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
00673 
00674 #define LOCAL_ALIGNED_D(a, t, v, s, o, ...) DECLARE_ALIGNED(a, t, v) s o
00675 
00676 #define LOCAL_ALIGNED(a, t, v, ...) LOCAL_ALIGNED_A(a, t, v, __VA_ARGS__,,)
00677 
00678 #if HAVE_LOCAL_ALIGNED_8
00679 #   define LOCAL_ALIGNED_8(t, v, ...) LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,)
00680 #else
00681 #   define LOCAL_ALIGNED_8(t, v, ...) LOCAL_ALIGNED(8, t, v, __VA_ARGS__)
00682 #endif
00683 
00684 #if HAVE_LOCAL_ALIGNED_16
00685 #   define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,)
00686 #else
00687 #   define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED(16, t, v, __VA_ARGS__)
00688 #endif
00689 
00690 #define WRAPPER8_16(name8, name16)\
00691 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
00692     return name8(s, dst           , src           , stride, h)\
00693           +name8(s, dst+8         , src+8         , stride, h);\
00694 }
00695 
00696 #define WRAPPER8_16_SQ(name8, name16)\
00697 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
00698     int score=0;\
00699     score +=name8(s, dst           , src           , stride, 8);\
00700     score +=name8(s, dst+8         , src+8         , stride, 8);\
00701     if(h==16){\
00702         dst += 8*stride;\
00703         src += 8*stride;\
00704         score +=name8(s, dst           , src           , stride, 8);\
00705         score +=name8(s, dst+8         , src+8         , stride, 8);\
00706     }\
00707     return score;\
00708 }
00709 
00710 
00711 static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
00712 {
00713     int i;
00714     for(i=0; i<h; i++)
00715     {
00716         AV_WN16(dst   , AV_RN16(src   ));
00717         dst+=dstStride;
00718         src+=srcStride;
00719     }
00720 }
00721 
00722 static inline void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
00723 {
00724     int i;
00725     for(i=0; i<h; i++)
00726     {
00727         AV_WN32(dst   , AV_RN32(src   ));
00728         dst+=dstStride;
00729         src+=srcStride;
00730     }
00731 }
00732 
00733 static inline void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
00734 {
00735     int i;
00736     for(i=0; i<h; i++)
00737     {
00738         AV_WN32(dst   , AV_RN32(src   ));
00739         AV_WN32(dst+4 , AV_RN32(src+4 ));
00740         dst+=dstStride;
00741         src+=srcStride;
00742     }
00743 }
00744 
00745 static inline void copy_block9(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
00746 {
00747     int i;
00748     for(i=0; i<h; i++)
00749     {
00750         AV_WN32(dst   , AV_RN32(src   ));
00751         AV_WN32(dst+4 , AV_RN32(src+4 ));
00752         dst[8]= src[8];
00753         dst+=dstStride;
00754         src+=srcStride;
00755     }
00756 }
00757 
00758 static inline void copy_block16(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
00759 {
00760     int i;
00761     for(i=0; i<h; i++)
00762     {
00763         AV_WN32(dst   , AV_RN32(src   ));
00764         AV_WN32(dst+4 , AV_RN32(src+4 ));
00765         AV_WN32(dst+8 , AV_RN32(src+8 ));
00766         AV_WN32(dst+12, AV_RN32(src+12));
00767         dst+=dstStride;
00768         src+=srcStride;
00769     }
00770 }
00771 
00772 static inline void copy_block17(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
00773 {
00774     int i;
00775     for(i=0; i<h; i++)
00776     {
00777         AV_WN32(dst   , AV_RN32(src   ));
00778         AV_WN32(dst+4 , AV_RN32(src+4 ));
00779         AV_WN32(dst+8 , AV_RN32(src+8 ));
00780         AV_WN32(dst+12, AV_RN32(src+12));
00781         dst[16]= src[16];
00782         dst+=dstStride;
00783         src+=srcStride;
00784     }
00785 }
00786 
00787 #endif /* AVCODEC_DSPUTIL_H */