• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

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 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 
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 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 /* encoding scans */
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 /* pixel operations */
00083 #define MAX_NEG_CROP 1024
00084 
00085 /* temporary */
00086 extern uint32_t ff_squareTbl[512];
00087 extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
00088 
00089 /* VP3 DSP functions */
00090 void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
00091 void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00092 void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
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 /* VP6 DSP functions */
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 /* 1/2^n downscaling functions from imgconvert.c */
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 /* minimum alignment rules ;)
00111 If you notice errors in the align stuff, need more alignment for some ASM code
00112 for some CPU or need to use a function with less aligned data then send a mail
00113 to the ffmpeg-devel mailing list, ...
00114 
00115 !warning These alignments might not match reality, (missing attribute((align))
00116 stuff somewhere possible).
00117 I (Michael) did not check them, these are just the alignments which I think
00118 could be reached easily ...
00119 
00120 !future video codecs might need functions with less strict alignment
00121 */
00122 
00123 /*
00124 void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
00125 void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
00126 void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
00127 void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
00128 void clear_blocks_c(DCTELEM *blocks);
00129 */
00130 
00131 /* add and put pixel (decoding) */
00132 // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
00133 //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
00134 typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
00135 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);
00136 typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
00137 typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, 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/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
00143 void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
00144 void ff_avg_        ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, 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 /* motion estimation */
00166 // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
00167 // although currently h<4 is not used as functions with width <8 are neither used nor implemented
00168 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))*/;
00169 
00170 
00171 // for snow slices
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     /* pixel ops : interface with DCT */
00198     void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
00199     void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
00200     void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00201     void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
00202     void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, 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/*align 16*/);
00209     void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
00213     void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, 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/*align 16*/);
00216     void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
00217     int (*pix_sum)(uint8_t * pix, int line_size);
00218     int (*pix_norm1)(uint8_t * pix, int line_size);
00219 // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
00220 
00221     me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
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]; //only width 16 used
00241     me_cmp_func frame_skip_cmp[6]; //only width 8 used
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/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h);
00295 
00306     tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
00307     tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
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     /* This is really one func used in VC-1 decoding */
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     /* AVS specific */
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     /* huffyuv specific */
00344     void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
00345     void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w);
00346     void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,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     /* this might write to dst[w] */
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/*align 16*/, int stride, int alpha, int beta, int8_t *tc0);
00358     void (*h264_h_loop_filter_luma)(uint8_t *pix/*align 4 */, int stride, int alpha, int beta, int8_t *tc0);
00359     /* v/h_loop_filter_luma_intra: align 16 */
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/*align 8*/, int stride, int alpha, int beta, int8_t *tc0);
00363     void (*h264_h_loop_filter_chroma)(uint8_t *pix/*align 4*/, int stride, int alpha, int beta, int8_t *tc0);
00364     void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta);
00365     void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta);
00366     // h264_loop_filter_strength: simd only. the C version is inlined in h264.c
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     /* assume len is a multiple of 4, and arrays are 16-byte aligned */
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     /* no alignment needed */
00388     void (*flac_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc);
00389     /* assume len is a multiple of 8, and arrays are 16-byte aligned */
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     /* assume len is a multiple of 8, and src arrays are 16-byte aligned */
00393     void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step);
00394     /* assume len is a multiple of 4, and arrays are 16-byte aligned */
00395     void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len);
00396     /* assume len is a multiple of 8, and arrays are 16-byte aligned */
00397     void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len);
00398 
00399     /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
00400      * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
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     /* (I)DCT */
00405     void (*fdct)(DCTELEM *block/* align 16*/);
00406     void (*fdct248)(DCTELEM *block/* align 16*/);
00407 
00408     /* IDCT really*/
00409     void (*idct)(DCTELEM *block/* align 16*/);
00410 
00416     void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
00417 
00422     void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
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     /* h264 functions */
00454     /* NOTE!!! if you implement any of h264_idct8_add, h264_idct8_add4 then you must implement all of them
00455        NOTE!!! if you implement any of h264_idct_add, h264_idct_add16, h264_idct_add16intra, h264_idct_add8 then you must implement all of them
00456         The reason for above, is that no 2 out of one list may use a different permutation.
00457     */
00458     void (*h264_idct_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride);
00459     void (*h264_idct8_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride);
00460     void (*h264_idct_dc_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride);
00461     void (*h264_idct8_dc_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride);
00462     void (*h264_dct)(DCTELEM block[4][4]);
00463     void (*h264_idct_add16)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]);
00464     void (*h264_idct8_add4)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]);
00465     void (*h264_idct_add8)(uint8_t **dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]);
00466     void (*h264_idct_add16intra)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]);
00467 
00468     /* snow wavelet */
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     /* vc1 functions */
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     /* put 8x8 block with bicubic interpolation and quarterpel precision
00485      * last argument is actually round value instead of height
00486      */
00487     op_pixels_func put_vc1_mspel_pixels_tab[16];
00488 
00489     /* intrax8 functions */
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     /* ape functions */
00499     void (*add_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len);
00504     void (*sub_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len);
00510     int32_t (*scalarproduct_int16)(int16_t *v1, int16_t *v2/*align 16*/, int len, int shift);
00511 
00512     /* rv30 functions */
00513     qpel_mc_func put_rv30_tpel_pixels_tab[4][16];
00514     qpel_mc_func avg_rv30_tpel_pixels_tab[4][16];
00515 
00516     /* rv40 functions */
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 /* should be defined by architectures supporting
00580    one or more MultiMedia extension */
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 /* PSNR */
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 /* FFT computation */
00661 
00662 /* NOTE: soon integer code will be added, so you must use the
00663    FFTSample type */
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; /* only used by SSE code */
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     void (*mdct_calc)(struct MDCTContext *s, FFTSample *output, const FFTSample *input);
00684 } FFTContext;
00685 
00686 extern FFTSample* ff_cos_tabs[13];
00687 
00693 int ff_fft_init(FFTContext *s, int nbits, int inverse);
00694 void ff_fft_permute_c(FFTContext *s, FFTComplex *z);
00695 void ff_fft_permute_sse(FFTContext *s, FFTComplex *z);
00696 void ff_fft_permute_neon(FFTContext *s, FFTComplex *z);
00697 void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
00698 void ff_fft_calc_sse(FFTContext *s, FFTComplex *z);
00699 void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z);
00700 void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z);
00701 void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z);
00702 void ff_fft_calc_neon(FFTContext *s, FFTComplex *z);
00703 
00707 static inline void ff_fft_permute(FFTContext *s, FFTComplex *z)
00708 {
00709     s->fft_permute(s, z);
00710 }
00715 static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
00716 {
00717     s->fft_calc(s, z);
00718 }
00719 void ff_fft_end(FFTContext *s);
00720 
00721 /* MDCT computation */
00722 
00723 typedef struct MDCTContext {
00724     int n;  /* size of MDCT (i.e. number of input data * 2) */
00725     int nbits; /* n = 2^nbits */
00726     /* pre/post rotation tables */
00727     FFTSample *tcos;
00728     FFTSample *tsin;
00729     FFTContext fft;
00730 } MDCTContext;
00731 
00732 static inline void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input)
00733 {
00734     s->fft.imdct_calc(s, output, input);
00735 }
00736 static inline void ff_imdct_half(MDCTContext *s, FFTSample *output, const FFTSample *input)
00737 {
00738     s->fft.imdct_half(s, output, input);
00739 }
00740 
00741 static inline void ff_mdct_calc(MDCTContext *s, FFTSample *output,
00742                                 const FFTSample *input)
00743 {
00744     s->fft.mdct_calc(s, output, input);
00745 }
00746 
00753 void ff_kbd_window_init(float *window, float alpha, int n);
00754 
00760 void ff_sine_window_init(float *window, int n);
00761 extern float ff_sine_128 [ 128];
00762 extern float ff_sine_256 [ 256];
00763 extern float ff_sine_512 [ 512];
00764 extern float ff_sine_1024[1024];
00765 extern float ff_sine_2048[2048];
00766 extern float ff_sine_4096[4096];
00767 extern float *ff_sine_windows[6];
00768 
00769 int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
00770 void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input);
00771 void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input);
00772 void ff_mdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input);
00773 void ff_imdct_calc_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input);
00774 void ff_imdct_half_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input);
00775 void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input);
00776 void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input);
00777 void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output, const FFTSample *input);
00778 void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input);
00779 void ff_imdct_calc_neon(MDCTContext *s, FFTSample *output, const FFTSample *input);
00780 void ff_imdct_half_neon(MDCTContext *s, FFTSample *output, const FFTSample *input);
00781 void ff_mdct_calc_neon(MDCTContext *s, FFTSample *output, const FFTSample *input);
00782 void ff_mdct_end(MDCTContext *s);
00783 
00784 /* Real Discrete Fourier Transform */
00785 
00786 enum RDFTransformType {
00787     RDFT,
00788     IRDFT,
00789     RIDFT,
00790     IRIDFT,
00791 };
00792 
00793 typedef struct {
00794     int nbits;
00795     int inverse;
00796     int sign_convention;
00797 
00798     /* pre/post rotation tables */
00799     FFTSample *tcos;
00800     FFTSample *tsin;
00801     FFTContext fft;
00802 } RDFTContext;
00803 
00809 int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans);
00810 void ff_rdft_calc(RDFTContext *s, FFTSample *data);
00811 void ff_rdft_end(RDFTContext *s);
00812 
00813 #define WRAPPER8_16(name8, name16)\
00814 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
00815     return name8(s, dst           , src           , stride, h)\
00816           +name8(s, dst+8         , src+8         , stride, h);\
00817 }
00818 
00819 #define WRAPPER8_16_SQ(name8, name16)\
00820 static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
00821     int score=0;\
00822     score +=name8(s, dst           , src           , stride, 8);\
00823     score +=name8(s, dst+8         , src+8         , stride, 8);\
00824     if(h==16){\
00825         dst += 8*stride;\
00826         src += 8*stride;\
00827         score +=name8(s, dst           , src           , stride, 8);\
00828         score +=name8(s, dst+8         , src+8         , stride, 8);\
00829     }\
00830     return score;\
00831 }
00832 
00833 
00834 static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00835 {
00836     int i;
00837     for(i=0; i<h; i++)
00838     {
00839         AV_WN16(dst   , AV_RN16(src   ));
00840         dst+=dstStride;
00841         src+=srcStride;
00842     }
00843 }
00844 
00845 static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00846 {
00847     int i;
00848     for(i=0; i<h; i++)
00849     {
00850         AV_WN32(dst   , AV_RN32(src   ));
00851         dst+=dstStride;
00852         src+=srcStride;
00853     }
00854 }
00855 
00856 static inline void copy_block8(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+=dstStride;
00864         src+=srcStride;
00865     }
00866 }
00867 
00868 static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00869 {
00870     int i;
00871     for(i=0; i<h; i++)
00872     {
00873         AV_WN32(dst   , AV_RN32(src   ));
00874         AV_WN32(dst+4 , AV_RN32(src+4 ));
00875         dst[8]= src[8];
00876         dst+=dstStride;
00877         src+=srcStride;
00878     }
00879 }
00880 
00881 static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00882 {
00883     int i;
00884     for(i=0; i<h; i++)
00885     {
00886         AV_WN32(dst   , AV_RN32(src   ));
00887         AV_WN32(dst+4 , AV_RN32(src+4 ));
00888         AV_WN32(dst+8 , AV_RN32(src+8 ));
00889         AV_WN32(dst+12, AV_RN32(src+12));
00890         dst+=dstStride;
00891         src+=srcStride;
00892     }
00893 }
00894 
00895 static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
00896 {
00897     int i;
00898     for(i=0; i<h; i++)
00899     {
00900         AV_WN32(dst   , AV_RN32(src   ));
00901         AV_WN32(dst+4 , AV_RN32(src+4 ));
00902         AV_WN32(dst+8 , AV_RN32(src+8 ));
00903         AV_WN32(dst+12, AV_RN32(src+12));
00904         dst[16]= src[16];
00905         dst+=dstStride;
00906         src+=srcStride;
00907     }
00908 }
00909 
00910 #endif /* AVCODEC_DSPUTIL_H */

Generated on Sat Feb 16 2013 09:23:12 for ffmpeg by  doxygen 1.7.1