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 FFmpeg.
00007  *
00008  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 /**
00024  * @file dsputil.h
00025  * DSP utils.
00026  * note, many functions in here may use MMX which trashes the FPU state, it is
00027  * absolutely necessary to call emms_c() between dsp & float/double code
00028  */
00029 
00030 #ifndef FFMPEG_DSPUTIL_H
00031 #define FFMPEG_DSPUTIL_H
00032 
00033 #include "avcodec.h"
00034 
00035 
00036 //#define DEBUG
00037 /* dct code */
00038 typedef short DCTELEM;
00039 typedef int DWTELEM;
00040 typedef short IDWTELEM;
00041 
00042 void fdct_ifast (DCTELEM *data);
00043 void fdct_ifast248 (DCTELEM *data);
00044 void ff_jpeg_fdct_islow (DCTELEM *data);
00045 void ff_fdct248_islow (DCTELEM *data);
00046 
00047 void j_rev_dct (DCTELEM *data);
00048 void j_rev_dct4 (DCTELEM *data);
00049 void j_rev_dct2 (DCTELEM *data);
00050 void j_rev_dct1 (DCTELEM *data);
00051 void ff_wmv2_idct_c(DCTELEM *data);
00052 
00053 void ff_fdct_mmx(DCTELEM *block);
00054 void ff_fdct_mmx2(DCTELEM *block);
00055 void ff_fdct_sse2(DCTELEM *block);
00056 
00057 void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
00058 void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
00059 void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
00060 void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
00061 void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
00062 void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
00063 
00064 void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1,
00065                               const float *src2, int src3, int blocksize, int step);
00066 void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1,
00067                              const float *win, float add_bias, int len);
00068 void ff_float_to_int16_c(int16_t *dst, const float *src, long len);
00069 
00070 /* encoding scans */
00071 extern const uint8_t ff_alternate_horizontal_scan[64];
00072 extern const uint8_t ff_alternate_vertical_scan[64];
00073 extern const uint8_t ff_zigzag_direct[64];
00074 extern const uint8_t ff_zigzag248_direct[64];
00075 
00076 /* pixel operations */
00077 #define MAX_NEG_CROP 1024
00078 
00079 /* temporary */
00080 extern uint32_t ff_squareTbl[512];
00081 extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
00082 
00083 /* VP3 DSP functions */
00084 void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
00085 void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00086 void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00087 
00088 /* 1/2^n downscaling functions from imgconvert.c */
00089 void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00090 void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00091 void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00092 void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00093 
00094 void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
00095               int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
00096 
00097 /* minimum alignment rules ;)
00098 If you notice errors in the align stuff, need more alignment for some ASM code
00099 for some CPU or need to use a function with less aligned data then send a mail
00100 to the ffmpeg-devel mailing list, ...
00101 
00102 !warning These alignments might not match reality, (missing attribute((align))
00103 stuff somewhere possible).
00104 I (Michael) did not check them, these are just the alignments which I think
00105 could be reached easily ...
00106 
00107 !future video codecs might need functions with less strict alignment
00108 */
00109 
00110 /*
00111 void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
00112 void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
00113 void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
00114 void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
00115 void clear_blocks_c(DCTELEM *blocks);
00116 */
00117 
00118 /* add and put pixel (decoding) */
00119 // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
00120 //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
00121 typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
00122 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);
00123 typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
00124 typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
00125 typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset);
00126 typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset);
00127 
00128 #define DEF_OLD_QPEL(name)\
00129 void ff_put_        ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
00130 void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
00131 void ff_avg_        ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
00132 
00133 DEF_OLD_QPEL(qpel16_mc11_old_c)
00134 DEF_OLD_QPEL(qpel16_mc31_old_c)
00135 DEF_OLD_QPEL(qpel16_mc12_old_c)
00136 DEF_OLD_QPEL(qpel16_mc32_old_c)
00137 DEF_OLD_QPEL(qpel16_mc13_old_c)
00138 DEF_OLD_QPEL(qpel16_mc33_old_c)
00139 DEF_OLD_QPEL(qpel8_mc11_old_c)
00140 DEF_OLD_QPEL(qpel8_mc31_old_c)
00141 DEF_OLD_QPEL(qpel8_mc12_old_c)
00142 DEF_OLD_QPEL(qpel8_mc32_old_c)
00143 DEF_OLD_QPEL(qpel8_mc13_old_c)
00144 DEF_OLD_QPEL(qpel8_mc33_old_c)
00145 
00146 #define CALL_2X_PIXELS(a, b, n)\
00147 static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
00148     b(block  , pixels  , line_size, h);\
00149     b(block+n, pixels+n, line_size, h);\
00150 }
00151 
00152 /* motion estimation */
00153 // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
00154 // although currently h<4 is not used as functions with width <8 are neither used nor implemented
00155 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))*/;
00156 
00157 
00158 // for snow slices
00159 typedef struct slice_buffer_s slice_buffer;
00160 
00161 /**
00162  * Scantable.
00163  */
00164 typedef struct ScanTable{
00165     const uint8_t *scantable;
00166     uint8_t permutated[64];
00167     uint8_t raster_end[64];
00168 #ifdef ARCH_POWERPC
00169                 /** Used by dct_quantize_altivec to find last-non-zero */
00170     DECLARE_ALIGNED(16, uint8_t, inverse[64]);
00171 #endif
00172 } ScanTable;
00173 
00174 void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
00175 
00176 void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize,
00177                          int block_w, int block_h,
00178                          int src_x, int src_y, int w, int h);
00179 
00180 /**
00181  * DSPContext.
00182  */
00183 typedef struct DSPContext {
00184     /* pixel ops : interface with DCT */
00185     void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
00186     void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
00187     void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00188     void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00189     void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00190     void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
00191     void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
00192     int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/);
00193     /**
00194      * translational global motion compensation.
00195      */
00196     void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
00197     /**
00198      * global motion compensation.
00199      */
00200     void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
00201                     int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
00202     void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
00203     int (*pix_sum)(uint8_t * pix, int line_size);
00204     int (*pix_norm1)(uint8_t * pix, int line_size);
00205 // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
00206 
00207     me_cmp_func sad[5]; /* identical to pix_absAxA except additional void * */
00208     me_cmp_func sse[5];
00209     me_cmp_func hadamard8_diff[5];
00210     me_cmp_func dct_sad[5];
00211     me_cmp_func quant_psnr[5];
00212     me_cmp_func bit[5];
00213     me_cmp_func rd[5];
00214     me_cmp_func vsad[5];
00215     me_cmp_func vsse[5];
00216     me_cmp_func nsse[5];
00217     me_cmp_func w53[5];
00218     me_cmp_func w97[5];
00219     me_cmp_func dct_max[5];
00220     me_cmp_func dct264_sad[5];
00221 
00222     me_cmp_func me_pre_cmp[5];
00223     me_cmp_func me_cmp[5];
00224     me_cmp_func me_sub_cmp[5];
00225     me_cmp_func mb_cmp[5];
00226     me_cmp_func ildct_cmp[5]; //only width 16 used
00227     me_cmp_func frame_skip_cmp[5]; //only width 8 used
00228 
00229     int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
00230                              int size);
00231 
00232     /**
00233      * Halfpel motion compensation with rounding (a+b+1)>>1.
00234      * this is an array[4][4] of motion compensation functions for 4
00235      * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
00236      * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
00237      * @param block destination where the result is stored
00238      * @param pixels source
00239      * @param line_size number of bytes in a horizontal line of block
00240      * @param h height
00241      */
00242     op_pixels_func put_pixels_tab[4][4];
00243 
00244     /**
00245      * Halfpel motion compensation with rounding (a+b+1)>>1.
00246      * This is an array[4][4] of motion compensation functions for 4
00247      * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
00248      * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
00249      * @param block destination into which the result is averaged (a+b+1)>>1
00250      * @param pixels source
00251      * @param line_size number of bytes in a horizontal line of block
00252      * @param h height
00253      */
00254     op_pixels_func avg_pixels_tab[4][4];
00255 
00256     /**
00257      * Halfpel motion compensation with no rounding (a+b)>>1.
00258      * this is an array[2][4] of motion compensation functions for 2
00259      * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
00260      * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
00261      * @param block destination where the result is stored
00262      * @param pixels source
00263      * @param line_size number of bytes in a horizontal line of block
00264      * @param h height
00265      */
00266     op_pixels_func put_no_rnd_pixels_tab[4][4];
00267 
00268     /**
00269      * Halfpel motion compensation with no rounding (a+b)>>1.
00270      * this is an array[2][4] of motion compensation functions for 2
00271      * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
00272      * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
00273      * @param block destination into which the result is averaged (a+b)>>1
00274      * @param pixels source
00275      * @param line_size number of bytes in a horizontal line of block
00276      * @param h height
00277      */
00278     op_pixels_func avg_no_rnd_pixels_tab[4][4];
00279 
00280     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);
00281 
00282     /**
00283      * Thirdpel motion compensation with rounding (a+b+1)>>1.
00284      * this is an array[12] of motion compensation functions for the 9 thirdpe
00285      * positions<br>
00286      * *pixels_tab[ xthirdpel + 4*ythirdpel ]
00287      * @param block destination where the result is stored
00288      * @param pixels source
00289      * @param line_size number of bytes in a horizontal line of block
00290      * @param h height
00291      */
00292     tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
00293     tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
00294 
00295     qpel_mc_func put_qpel_pixels_tab[2][16];
00296     qpel_mc_func avg_qpel_pixels_tab[2][16];
00297     qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
00298     qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
00299     qpel_mc_func put_mspel_pixels_tab[8];
00300 
00301     /**
00302      * h264 Chroma MC
00303      */
00304     h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
00305     /* This is really one func used in VC-1 decoding */
00306     h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab[3];
00307     h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
00308 
00309     qpel_mc_func put_h264_qpel_pixels_tab[4][16];
00310     qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
00311 
00312     qpel_mc_func put_2tap_qpel_pixels_tab[4][16];
00313     qpel_mc_func avg_2tap_qpel_pixels_tab[4][16];
00314 
00315     h264_weight_func weight_h264_pixels_tab[10];
00316     h264_biweight_func biweight_h264_pixels_tab[10];
00317 
00318     /* AVS specific */
00319     qpel_mc_func put_cavs_qpel_pixels_tab[2][16];
00320     qpel_mc_func avg_cavs_qpel_pixels_tab[2][16];
00321     void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
00322     void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
00323     void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
00324     void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
00325     void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
00326 
00327     me_cmp_func pix_abs[2][4];
00328 
00329     /* huffyuv specific */
00330     void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
00331     void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w);
00332     void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
00333     /**
00334      * subtract huffyuv's variant of median prediction
00335      * note, this might read from src1[-1], src2[-1]
00336      */
00337     void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top);
00338     /* this might write to dst[w] */
00339     void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
00340     void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
00341 
00342     void (*h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
00343     void (*h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
00344     void (*h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
00345     void (*h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
00346     void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
00347     void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
00348     // h264_loop_filter_strength: simd only. the C version is inlined in h264.c
00349     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],
00350                                       int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field);
00351 
00352     void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
00353     void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
00354 
00355     void (*h261_loop_filter)(uint8_t *src, int stride);
00356 
00357     void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale);
00358     void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale);
00359 
00360     /* assume len is a multiple of 4, and arrays are 16-byte aligned */
00361     void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
00362     /* no alignment needed */
00363     void (*flac_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc);
00364     /* assume len is a multiple of 8, and arrays are 16-byte aligned */
00365     void (*vector_fmul)(float *dst, const float *src, int len);
00366     void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len);
00367     /* assume len is a multiple of 8, and src arrays are 16-byte aligned */
00368     void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step);
00369     /* assume len is a multiple of 4, and arrays are 16-byte aligned */
00370     void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len);
00371 
00372     /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
00373      * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
00374     void (*float_to_int16)(int16_t *dst, const float *src, long len);
00375     void (*float_to_int16_interleave)(int16_t *dst, const float **src, long len, int channels);
00376 
00377     /* (I)DCT */
00378     void (*fdct)(DCTELEM *block/* align 16*/);
00379     void (*fdct248)(DCTELEM *block/* align 16*/);
00380 
00381     /* IDCT really*/
00382     void (*idct)(DCTELEM *block/* align 16*/);
00383 
00384     /**
00385      * block -> idct -> clip to unsigned 8 bit -> dest.
00386      * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
00387      * @param line_size size in bytes of a horizontal line of dest
00388      */
00389     void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00390 
00391     /**
00392      * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
00393      * @param line_size size in bytes of a horizontal line of dest
00394      */
00395     void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00396 
00397     /**
00398      * idct input permutation.
00399      * several optimized IDCTs need a permutated input (relative to the normal order of the reference
00400      * IDCT)
00401      * this permutation must be performed before the idct_put/add, note, normally this can be merged
00402      * with the zigzag/alternate scan<br>
00403      * an example to avoid confusion:
00404      * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
00405      * - (x -> referece dct -> reference idct -> x)
00406      * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
00407      * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
00408      */
00409     uint8_t idct_permutation[64];
00410     int idct_permutation_type;
00411 #define FF_NO_IDCT_PERM 1
00412 #define FF_LIBMPEG2_IDCT_PERM 2
00413 #define FF_SIMPLE_IDCT_PERM 3
00414 #define FF_TRANSPOSE_IDCT_PERM 4
00415 #define FF_PARTTRANS_IDCT_PERM 5
00416 #define FF_SSE2_IDCT_PERM 6
00417 
00418     int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
00419     void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
00420 #define BASIS_SHIFT 16
00421 #define RECON_SHIFT 6
00422 
00423     void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
00424 #define EDGE_WIDTH 16
00425 
00426     /* h264 functions */
00427     void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride);
00428     void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
00429     void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
00430     void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
00431     void (*h264_dct)(DCTELEM block[4][4]);
00432 
00433     /* snow wavelet */
00434     void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
00435     void (*horizontal_compose97i)(IDWTELEM *b, int width);
00436     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);
00437 
00438     void (*prefetch)(void *mem, int stride, int h);
00439 
00440     void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
00441 
00442     /* vc1 functions */
00443     void (*vc1_inv_trans_8x8)(DCTELEM *b);
00444     void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block);
00445     void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block);
00446     void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block);
00447     void (*vc1_v_overlap)(uint8_t* src, int stride);
00448     void (*vc1_h_overlap)(uint8_t* src, int stride);
00449     /* put 8x8 block with bicubic interpolation and quarterpel precision
00450      * last argument is actually round value instead of height
00451      */
00452     op_pixels_func put_vc1_mspel_pixels_tab[16];
00453 
00454     /* intrax8 functions */
00455     void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize);
00456     void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize,
00457            int * range, int * sum,  int edges);
00458 
00459     /* ape functions */
00460     /**
00461      * Add contents of the second vector to the first one.
00462      * @param len length of vectors, should be multiple of 16
00463      */
00464     void (*add_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len);
00465     /**
00466      * Add contents of the second vector to the first one.
00467      * @param len length of vectors, should be multiple of 16
00468      */
00469     void (*sub_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len);
00470     /**
00471      * Calculate scalar product of two vectors.
00472      * @param len length of vectors, should be multiple of 16
00473      * @param shift number of bits to discard from product
00474      */
00475     int32_t (*scalarproduct_int16)(int16_t *v1, int16_t *v2/*align 16*/, int len, int shift);
00476 } DSPContext;
00477 
00478 void dsputil_static_init(void);
00479 void dsputil_init(DSPContext* p, AVCodecContext *avctx);
00480 
00481 int ff_check_alignment(void);
00482 
00483 /**
00484  * permute block according to permuatation.
00485  * @param last last non zero element in scantable order
00486  */
00487 void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
00488 
00489 void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
00490 
00491 #define         BYTE_VEC32(c)   ((c)*0x01010101UL)
00492 
00493 static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
00494 {
00495     return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
00496 }
00497 
00498 static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
00499 {
00500     return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
00501 }
00502 
00503 static inline int get_penalty_factor(int lambda, int lambda2, int type){
00504     switch(type&0xFF){
00505     default:
00506     case FF_CMP_SAD:
00507         return lambda>>FF_LAMBDA_SHIFT;
00508     case FF_CMP_DCT:
00509         return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
00510     case FF_CMP_W53:
00511         return (4*lambda)>>(FF_LAMBDA_SHIFT);
00512     case FF_CMP_W97:
00513         return (2*lambda)>>(FF_LAMBDA_SHIFT);
00514     case FF_CMP_SATD:
00515     case FF_CMP_DCT264:
00516         return (2*lambda)>>FF_LAMBDA_SHIFT;
00517     case FF_CMP_RD:
00518     case FF_CMP_PSNR:
00519     case FF_CMP_SSE:
00520     case FF_CMP_NSSE:
00521         return lambda2>>FF_LAMBDA_SHIFT;
00522     case FF_CMP_BIT:
00523         return 1;
00524     }
00525 }
00526 
00527 /**
00528  * Empty mmx state.
00529  * this must be called between any dsp function and float/double code.
00530  * for example sin(); dsp->idct_put(); emms_c(); cos()
00531  */
00532 #define emms_c()
00533 
00534 /* should be defined by architectures supporting
00535    one or more MultiMedia extension */
00536 int mm_support(void);
00537 
00538 void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
00539 void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx);
00540 void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
00541 void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
00542 void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
00543 void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
00544 void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
00545 void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
00546 void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
00547 
00548 #define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v)
00549 
00550 #if defined(HAVE_MMX)
00551 
00552 #undef emms_c
00553 
00554 #define MM_MMX    0x0001 /* standard MMX */
00555 #define MM_3DNOW  0x0004 /* AMD 3DNOW */
00556 #define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
00557 #define MM_SSE    0x0008 /* SSE functions */
00558 #define MM_SSE2   0x0010 /* PIV SSE2 functions */
00559 #define MM_3DNOWEXT  0x0020 /* AMD 3DNowExt */
00560 #define MM_SSE3   0x0040 /* Prescott SSE3 functions */
00561 #define MM_SSSE3  0x0080 /* Conroe SSSE3 functions */
00562 
00563 extern int mm_flags;
00564 
00565 void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
00566 void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
00567 void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
00568 
00569 static inline void emms(void)
00570 {
00571     asm volatile ("emms;":::"memory");
00572 }
00573 
00574 
00575 #define emms_c() \
00576 {\
00577     if (mm_flags & MM_MMX)\
00578         emms();\
00579 }
00580 
00581 void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
00582 
00583 #elif defined(ARCH_ARMV4L)
00584 
00585 #define MM_IWMMXT    0x0100 /* XScale IWMMXT */
00586 
00587 extern int mm_flags;
00588 
00589 #elif defined(ARCH_POWERPC)
00590 
00591 #define MM_ALTIVEC    0x0001 /* standard AltiVec */
00592 
00593 extern int mm_flags;
00594 
00595 #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
00596 #define STRIDE_ALIGN 16
00597 
00598 #elif defined(HAVE_MMI)
00599 
00600 #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
00601 #define STRIDE_ALIGN 16
00602 
00603 #else
00604 
00605 #define mm_flags 0
00606 #define mm_support() 0
00607 
00608 #endif
00609 
00610 #ifndef DECLARE_ALIGNED_8
00611 #   define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v)
00612 #endif
00613 
00614 #ifndef STRIDE_ALIGN
00615 #   define STRIDE_ALIGN 8
00616 #endif
00617 
00618 /* PSNR */
00619 void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
00620               int orig_linesize[3], int coded_linesize,
00621               AVCodecContext *avctx);
00622 
00623 /* FFT computation */
00624 
00625 /* NOTE: soon integer code will be added, so you must use the
00626    FFTSample type */
00627 typedef float FFTSample;
00628 
00629 struct MDCTContext;
00630 
00631 typedef struct FFTComplex {
00632     FFTSample re, im;
00633 } FFTComplex;
00634 
00635 typedef struct FFTContext {
00636     int nbits;
00637     int inverse;
00638     uint16_t *revtab;
00639     FFTComplex *exptab;
00640     FFTComplex *exptab1; /* only used by SSE code */
00641     void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
00642     void (*imdct_calc)(struct MDCTContext *s, FFTSample *output,
00643                        const FFTSample *input, FFTSample *tmp);
00644     void (*imdct_half)(struct MDCTContext *s, FFTSample *output,
00645                        const FFTSample *input, FFTSample *tmp);
00646 } FFTContext;
00647 
00648 int ff_fft_init(FFTContext *s, int nbits, int inverse);
00649 void ff_fft_permute(FFTContext *s, FFTComplex *z);
00650 void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
00651 void ff_fft_calc_sse(FFTContext *s, FFTComplex *z);
00652 void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z);
00653 void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z);
00654 void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z);
00655 
00656 static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
00657 {
00658     s->fft_calc(s, z);
00659 }
00660 void ff_fft_end(FFTContext *s);
00661 
00662 /* MDCT computation */
00663 
00664 typedef struct MDCTContext {
00665     int n;  /* size of MDCT (i.e. number of input data * 2) */
00666     int nbits; /* n = 2^nbits */
00667     /* pre/post rotation tables */
00668     FFTSample *tcos;
00669     FFTSample *tsin;
00670     FFTContext fft;
00671 } MDCTContext;
00672 
00673 /**
00674  * Generate a Kaiser-Bessel Derived Window.
00675  * @param   window  pointer to half window
00676  * @param   alpha   determines window shape
00677  * @param   n       size of half window
00678  */
00679 void ff_kbd_window_init(float *window, float alpha, int n);
00680 
00681 /**
00682  * Generate a sine window.
00683  * @param   window  pointer to half window
00684  * @param   n       size of half window
00685  */
00686 void ff_sine_window_init(float *window, int n);
00687 
00688 int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
00689 void ff_imdct_calc(MDCTContext *s, FFTSample *output,
00690                 const FFTSample *input, FFTSample *tmp);
00691 void ff_imdct_half(MDCTContext *s, FFTSample *output,
00692                    const FFTSample *input, FFTSample *tmp);
00693 void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output,
00694                         const FFTSample *input, FFTSample *tmp);
00695 void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output,
00696                         const FFTSample *input, FFTSample *tmp);
00697 void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output,
00698                        const FFTSample *input, FFTSample *tmp);
00699 void ff_imdct_half_sse(MDCTContext *s, FFTSample *output,
00700                        const FFTSample *input, FFTSample *tmp);
00701 void ff_mdct_calc(MDCTContext *s, FFTSample *out,
00702                const FFTSample *input, FFTSample *tmp);
00703 void ff_mdct_end(MDCTContext *s);
00704 
00705 #define WRAPPER8_16(name8, name16)\
00706 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
00707     return name8(s, dst           , src           , stride, h)\
00708           +name8(s, dst+8         , src+8         , stride, h);\
00709 }
00710 
00711 #define WRAPPER8_16_SQ(name8, name16)\
00712 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
00713     int score=0;\
00714     score +=name8(s, dst           , src           , stride, 8);\
00715     score +=name8(s, dst+8         , src+8         , stride, 8);\
00716     if(h==16){\
00717         dst += 8*stride;\
00718         src += 8*stride;\
00719         score +=name8(s, dst           , src           , stride, 8);\
00720         score +=name8(s, dst+8         , src+8         , stride, 8);\
00721     }\
00722     return score;\
00723 }
00724 
00725 
00726 static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00727 {
00728     int i;
0072