00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00028 #include "libavutil/intreadwrite.h"
00029 #include "internal.h"
00030 #include "dsputil.h"
00031 #include "avcodec.h"
00032 #include "mpegvideo.h"
00033 #include "h264.h"
00034 #include "mathops.h"
00035 #include "rectangle.h"
00036 
00037 
00038 static const uint8_t alpha_table[52*3] = {
00039      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00040      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00041      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00042      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00043      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00044      0,  0,  0,  0,  0,  0,  4,  4,  5,  6,
00045      7,  8,  9, 10, 12, 13, 15, 17, 20, 22,
00046     25, 28, 32, 36, 40, 45, 50, 56, 63, 71,
00047     80, 90,101,113,127,144,162,182,203,226,
00048    255,255,
00049    255,255,255,255,255,255,255,255,255,255,255,255,255,
00050    255,255,255,255,255,255,255,255,255,255,255,255,255,
00051    255,255,255,255,255,255,255,255,255,255,255,255,255,
00052    255,255,255,255,255,255,255,255,255,255,255,255,255,
00053 };
00054 static const uint8_t beta_table[52*3] = {
00055      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00056      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00057      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00058      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00059      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
00060      0,  0,  0,  0,  0,  0,  2,  2,  2,  3,
00061      3,  3,  3,  4,  4,  4,  6,  6,  7,  7,
00062      8,  8,  9,  9, 10, 10, 11, 11, 12, 12,
00063     13, 13, 14, 14, 15, 15, 16, 16, 17, 17,
00064     18, 18,
00065     18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
00066     18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
00067     18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
00068     18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
00069 };
00070 static const uint8_t tc0_table[52*3][4] = {
00071     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00072     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00073     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00074     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00075     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00076     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00077     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00078     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00079     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00080     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00081     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
00082     {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 1 },
00083     {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 1, 1 }, {-1, 0, 1, 1 }, {-1, 1, 1, 1 },
00084     {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 },
00085     {-1, 1, 1, 2 }, {-1, 1, 2, 3 }, {-1, 1, 2, 3 }, {-1, 2, 2, 3 }, {-1, 2, 2, 4 }, {-1, 2, 3, 4 },
00086     {-1, 2, 3, 4 }, {-1, 3, 3, 5 }, {-1, 3, 4, 6 }, {-1, 3, 4, 6 }, {-1, 4, 5, 7 }, {-1, 4, 5, 8 },
00087     {-1, 4, 6, 9 }, {-1, 5, 7,10 }, {-1, 6, 8,11 }, {-1, 6, 8,13 }, {-1, 7,10,14 }, {-1, 8,11,16 },
00088     {-1, 9,12,18 }, {-1,10,13,20 }, {-1,11,15,23 }, {-1,13,17,25 },
00089     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00090     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00091     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00092     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00093     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00094     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00095     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00096     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00097     {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
00098 };
00099 
00100 
00101 static av_always_inline void filter_mb_edgev(uint8_t *pix, int stride,
00102                                              const int16_t bS[4],
00103                                              unsigned int qp, int a, int b,
00104                                              H264Context *h, int intra)
00105 {
00106     const unsigned int index_a = qp + a;
00107     const int alpha = alpha_table[index_a];
00108     const int beta  = beta_table[qp + b];
00109     if (alpha ==0 || beta == 0) return;
00110 
00111     if( bS[0] < 4 || !intra ) {
00112         int8_t tc[4];
00113         tc[0] = tc0_table[index_a][bS[0]];
00114         tc[1] = tc0_table[index_a][bS[1]];
00115         tc[2] = tc0_table[index_a][bS[2]];
00116         tc[3] = tc0_table[index_a][bS[3]];
00117         h->h264dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc);
00118     } else {
00119         h->h264dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta);
00120     }
00121 }
00122 
00123 static av_always_inline void filter_mb_edgecv(uint8_t *pix, int stride,
00124                                               const int16_t bS[4],
00125                                               unsigned int qp, int a, int b,
00126                                               H264Context *h, int intra)
00127 {
00128     const unsigned int index_a = qp + a;
00129     const int alpha = alpha_table[index_a];
00130     const int beta  = beta_table[qp + b];
00131     if (alpha ==0 || beta == 0) return;
00132 
00133     if( bS[0] < 4 || !intra ) {
00134         int8_t tc[4];
00135         tc[0] = tc0_table[index_a][bS[0]]+1;
00136         tc[1] = tc0_table[index_a][bS[1]]+1;
00137         tc[2] = tc0_table[index_a][bS[2]]+1;
00138         tc[3] = tc0_table[index_a][bS[3]]+1;
00139         h->h264dsp.h264_h_loop_filter_chroma(pix, stride, alpha, beta, tc);
00140     } else {
00141         h->h264dsp.h264_h_loop_filter_chroma_intra(pix, stride, alpha, beta);
00142     }
00143 }
00144 
00145 static av_always_inline void filter_mb_mbaff_edgev(H264Context *h, uint8_t *pix,
00146                                                    int stride,
00147                                                    const int16_t bS[7], int bsi,
00148                                                    int qp, int a, int b,
00149                                                    int intra)
00150 {
00151     const unsigned int index_a = qp + a;
00152     const int alpha = alpha_table[index_a];
00153     const int beta  = beta_table[qp + b];
00154     if (alpha ==0 || beta == 0) return;
00155 
00156     if( bS[0] < 4 || !intra ) {
00157         int8_t tc[4];
00158         tc[0] = tc0_table[index_a][bS[0*bsi]];
00159         tc[1] = tc0_table[index_a][bS[1*bsi]];
00160         tc[2] = tc0_table[index_a][bS[2*bsi]];
00161         tc[3] = tc0_table[index_a][bS[3*bsi]];
00162         h->h264dsp.h264_h_loop_filter_luma_mbaff(pix, stride, alpha, beta, tc);
00163     } else {
00164         h->h264dsp.h264_h_loop_filter_luma_mbaff_intra(pix, stride, alpha, beta);
00165     }
00166 }
00167 
00168 static av_always_inline void filter_mb_mbaff_edgecv(H264Context *h,
00169                                                     uint8_t *pix, int stride,
00170                                                     const int16_t bS[7],
00171                                                     int bsi, int qp, int a,
00172                                                     int b, int intra)
00173 {
00174     const unsigned int index_a = qp + a;
00175     const int alpha = alpha_table[index_a];
00176     const int beta  = beta_table[qp + b];
00177     if (alpha ==0 || beta == 0) return;
00178 
00179     if( bS[0] < 4 || !intra ) {
00180         int8_t tc[4];
00181         tc[0] = tc0_table[index_a][bS[0*bsi]] + 1;
00182         tc[1] = tc0_table[index_a][bS[1*bsi]] + 1;
00183         tc[2] = tc0_table[index_a][bS[2*bsi]] + 1;
00184         tc[3] = tc0_table[index_a][bS[3*bsi]] + 1;
00185         h->h264dsp.h264_h_loop_filter_chroma_mbaff(pix, stride, alpha, beta, tc);
00186     } else {
00187         h->h264dsp.h264_h_loop_filter_chroma_mbaff_intra(pix, stride, alpha, beta);
00188     }
00189 }
00190 
00191 static av_always_inline void filter_mb_edgeh(uint8_t *pix, int stride,
00192                                              const int16_t bS[4],
00193                                              unsigned int qp, int a, int b,
00194                                              H264Context *h, int intra)
00195 {
00196     const unsigned int index_a = qp + a;
00197     const int alpha = alpha_table[index_a];
00198     const int beta  = beta_table[qp + b];
00199     if (alpha ==0 || beta == 0) return;
00200 
00201     if( bS[0] < 4 || !intra ) {
00202         int8_t tc[4];
00203         tc[0] = tc0_table[index_a][bS[0]];
00204         tc[1] = tc0_table[index_a][bS[1]];
00205         tc[2] = tc0_table[index_a][bS[2]];
00206         tc[3] = tc0_table[index_a][bS[3]];
00207         h->h264dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc);
00208     } else {
00209         h->h264dsp.h264_v_loop_filter_luma_intra(pix, stride, alpha, beta);
00210     }
00211 }
00212 
00213 static av_always_inline void filter_mb_edgech(uint8_t *pix, int stride,
00214                                               const int16_t bS[4],
00215                                               unsigned int qp, int a, int b,
00216                                               H264Context *h, int intra)
00217 {
00218     const unsigned int index_a = qp + a;
00219     const int alpha = alpha_table[index_a];
00220     const int beta  = beta_table[qp + b];
00221     if (alpha ==0 || beta == 0) return;
00222 
00223     if( bS[0] < 4 || !intra ) {
00224         int8_t tc[4];
00225         tc[0] = tc0_table[index_a][bS[0]]+1;
00226         tc[1] = tc0_table[index_a][bS[1]]+1;
00227         tc[2] = tc0_table[index_a][bS[2]]+1;
00228         tc[3] = tc0_table[index_a][bS[3]]+1;
00229         h->h264dsp.h264_v_loop_filter_chroma(pix, stride, alpha, beta, tc);
00230     } else {
00231         h->h264dsp.h264_v_loop_filter_chroma_intra(pix, stride, alpha, beta);
00232     }
00233 }
00234 
00235 static av_always_inline void h264_filter_mb_fast_internal(H264Context *h,
00236                                                           int mb_x, int mb_y,
00237                                                           uint8_t *img_y,
00238                                                           uint8_t *img_cb,
00239                                                           uint8_t *img_cr,
00240                                                           unsigned int linesize,
00241                                                           unsigned int uvlinesize,
00242                                                           int pixel_shift)
00243 {
00244     MpegEncContext * const s = &h->s;
00245     int chroma = CHROMA && !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));
00246     int chroma444 = CHROMA444;
00247     int chroma422 = CHROMA422;
00248 
00249     int mb_xy = h->mb_xy;
00250     int left_type= h->left_type[LTOP];
00251     int top_type= h->top_type;
00252 
00253     int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
00254     int a = h->slice_alpha_c0_offset - qp_bd_offset;
00255     int b = h->slice_beta_offset - qp_bd_offset;
00256 
00257     int mb_type = s->current_picture.f.mb_type[mb_xy];
00258     int qp      = s->current_picture.f.qscale_table[mb_xy];
00259     int qp0     = s->current_picture.f.qscale_table[mb_xy - 1];
00260     int qp1     = s->current_picture.f.qscale_table[h->top_mb_xy];
00261     int qpc = get_chroma_qp( h, 0, qp );
00262     int qpc0 = get_chroma_qp( h, 0, qp0 );
00263     int qpc1 = get_chroma_qp( h, 0, qp1 );
00264     qp0 = (qp + qp0 + 1) >> 1;
00265     qp1 = (qp + qp1 + 1) >> 1;
00266     qpc0 = (qpc + qpc0 + 1) >> 1;
00267     qpc1 = (qpc + qpc1 + 1) >> 1;
00268 
00269     if( IS_INTRA(mb_type) ) {
00270         static const int16_t bS4[4] = {4,4,4,4};
00271         static const int16_t bS3[4] = {3,3,3,3};
00272         const int16_t *bSH = FIELD_PICTURE ? bS3 : bS4;
00273         if(left_type)
00274             filter_mb_edgev( &img_y[4*0<<pixel_shift], linesize, bS4, qp0, a, b, h, 1);
00275         if( IS_8x8DCT(mb_type) ) {
00276             filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0);
00277             if(top_type){
00278                 filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1);
00279             }
00280             filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0);
00281         } else {
00282             filter_mb_edgev( &img_y[4*1<<pixel_shift], linesize, bS3, qp, a, b, h, 0);
00283             filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0);
00284             filter_mb_edgev( &img_y[4*3<<pixel_shift], linesize, bS3, qp, a, b, h, 0);
00285             if(top_type){
00286                 filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1);
00287             }
00288             filter_mb_edgeh( &img_y[4*1*linesize], linesize, bS3, qp, a, b, h, 0);
00289             filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0);
00290             filter_mb_edgeh( &img_y[4*3*linesize], linesize, bS3, qp, a, b, h, 0);
00291         }
00292         if(chroma){
00293             if(chroma444){
00294                 if(left_type){
00295                     filter_mb_edgev( &img_cb[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1);
00296                     filter_mb_edgev( &img_cr[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1);
00297                 }
00298                 if( IS_8x8DCT(mb_type) ) {
00299                     filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
00300                     filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
00301                     if(top_type){
00302                         filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 );
00303                         filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 );
00304                     }
00305                     filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);
00306                     filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);
00307                 } else {
00308                     filter_mb_edgev( &img_cb[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
00309                     filter_mb_edgev( &img_cr[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
00310                     filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
00311                     filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
00312                     filter_mb_edgev( &img_cb[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
00313                     filter_mb_edgev( &img_cr[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
00314                     if(top_type){
00315                         filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1);
00316                         filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1);
00317                     }
00318                     filter_mb_edgeh( &img_cb[4*1*linesize], linesize, bS3, qpc, a, b, h, 0);
00319                     filter_mb_edgeh( &img_cr[4*1*linesize], linesize, bS3, qpc, a, b, h, 0);
00320                     filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);
00321                     filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);
00322                     filter_mb_edgeh( &img_cb[4*3*linesize], linesize, bS3, qpc, a, b, h, 0);
00323                     filter_mb_edgeh( &img_cr[4*3*linesize], linesize, bS3, qpc, a, b, h, 0);
00324                 }
00325             }else if(chroma422){
00326                 if(left_type){
00327                     filter_mb_edgecv(&img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);
00328                     filter_mb_edgecv(&img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);
00329                 }
00330                 filter_mb_edgecv(&img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);
00331                 filter_mb_edgecv(&img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);
00332                 if(top_type){
00333                     filter_mb_edgech(&img_cb[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);
00334                     filter_mb_edgech(&img_cr[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);
00335                 }
00336                 filter_mb_edgech(&img_cb[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
00337                 filter_mb_edgech(&img_cr[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
00338                 filter_mb_edgech(&img_cb[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
00339                 filter_mb_edgech(&img_cr[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
00340                 filter_mb_edgech(&img_cb[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
00341                 filter_mb_edgech(&img_cr[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
00342             }else{
00343                 if(left_type){
00344                     filter_mb_edgecv( &img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);
00345                     filter_mb_edgecv( &img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);
00346                 }
00347                 filter_mb_edgecv( &img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);
00348                 filter_mb_edgecv( &img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);
00349                 if(top_type){
00350                     filter_mb_edgech( &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);
00351                     filter_mb_edgech( &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);
00352                 }
00353                 filter_mb_edgech( &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
00354                 filter_mb_edgech( &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
00355             }
00356         }
00357         return;
00358     } else {
00359         LOCAL_ALIGNED_8(int16_t, bS, [2], [4][4]);
00360         int edges;
00361         if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 && !chroma444 ) {
00362             edges = 4;
00363             AV_WN64A(bS[0][0], 0x0002000200020002ULL);
00364             AV_WN64A(bS[0][2], 0x0002000200020002ULL);
00365             AV_WN64A(bS[1][0], 0x0002000200020002ULL);
00366             AV_WN64A(bS[1][2], 0x0002000200020002ULL);
00367         } else {
00368             int mask_edge1 = (3*(((5*mb_type)>>5)&1)) | (mb_type>>4); 
00369             int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1); 
00370             int step =  1+(mb_type>>24); 
00371             edges = 4 - 3*((mb_type>>3) & !(h->cbp & 15)); 
00372             h->h264dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache,
00373                                               h->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE);
00374         }
00375         if( IS_INTRA(left_type) )
00376             AV_WN64A(bS[0][0], 0x0004000400040004ULL);
00377         if( IS_INTRA(top_type) )
00378             AV_WN64A(bS[1][0], FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL);
00379 
00380 #define FILTER(hv,dir,edge,intra)\
00381         if(AV_RN64A(bS[dir][edge])) {                                   \
00382             filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qp : qp##dir, a, b, h, intra );\
00383             if(chroma){\
00384                 if(chroma444){\
00385                     filter_mb_edge##hv( &img_cb[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\
00386                     filter_mb_edge##hv( &img_cr[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\
00387                 } else if(!(edge&1)) {\
00388                     filter_mb_edgec##hv( &img_cb[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\
00389                     filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\
00390                 }\
00391             }\
00392         }
00393         if(left_type)
00394             FILTER(v,0,0,1);
00395         if( edges == 1 ) {
00396             if(top_type)
00397                 FILTER(h,1,0,1);
00398         } else if( IS_8x8DCT(mb_type) ) {
00399             FILTER(v,0,2,0);
00400             if(top_type)
00401                 FILTER(h,1,0,1);
00402             FILTER(h,1,2,0);
00403         } else {
00404             FILTER(v,0,1,0);
00405             FILTER(v,0,2,0);
00406             FILTER(v,0,3,0);
00407             if(top_type)
00408                 FILTER(h,1,0,1);
00409             FILTER(h,1,1,0);
00410             FILTER(h,1,2,0);
00411             FILTER(h,1,3,0);
00412         }
00413 #undef FILTER
00414     }
00415 }
00416 
00417 void ff_h264_filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {
00418     av_assert2(!FRAME_MBAFF);
00419     if(!h->h264dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff) {
00420         ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);
00421         return;
00422     }
00423 
00424 #if CONFIG_SMALL
00425     h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, h->pixel_shift);
00426 #else
00427     if(h->pixel_shift){
00428         h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 1);
00429     }else{
00430         h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 0);
00431     }
00432 #endif
00433 }
00434 
00435 static int check_mv(H264Context *h, long b_idx, long bn_idx, int mvy_limit){
00436     int v;
00437 
00438     v= h->ref_cache[0][b_idx] != h->ref_cache[0][bn_idx];
00439     if(!v && h->ref_cache[0][b_idx]!=-1)
00440         v= h->mv_cache[0][b_idx][0] - h->mv_cache[0][bn_idx][0] + 3 >= 7U |
00441            FFABS( h->mv_cache[0][b_idx][1] - h->mv_cache[0][bn_idx][1] ) >= mvy_limit;
00442 
00443     if(h->list_count==2){
00444         if(!v)
00445             v = h->ref_cache[1][b_idx] != h->ref_cache[1][bn_idx] |
00446                 h->mv_cache[1][b_idx][0] - h->mv_cache[1][bn_idx][0] + 3 >= 7U |
00447                 FFABS( h->mv_cache[1][b_idx][1] - h->mv_cache[1][bn_idx][1] ) >= mvy_limit;
00448 
00449         if(v){
00450             if(h->ref_cache[0][b_idx] != h->ref_cache[1][bn_idx] |
00451                h->ref_cache[1][b_idx] != h->ref_cache[0][bn_idx])
00452                 return 1;
00453             return
00454                 h->mv_cache[0][b_idx][0] - h->mv_cache[1][bn_idx][0] + 3 >= 7U |
00455                 FFABS( h->mv_cache[0][b_idx][1] - h->mv_cache[1][bn_idx][1] ) >= mvy_limit |
00456                 h->mv_cache[1][b_idx][0] - h->mv_cache[0][bn_idx][0] + 3 >= 7U |
00457                 FFABS( h->mv_cache[1][b_idx][1] - h->mv_cache[0][bn_idx][1] ) >= mvy_limit;
00458         }
00459     }
00460 
00461     return v;
00462 }
00463 
00464 static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int a, int b, int chroma, int dir) {
00465     MpegEncContext * const s = &h->s;
00466     int edge;
00467     int chroma_qp_avg[2];
00468     int chroma444 = CHROMA444;
00469     int chroma422 = CHROMA422;
00470     const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy;
00471     const int mbm_type = dir == 0 ? h->left_type[LTOP] : h->top_type;
00472 
00473     
00474     static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1},
00475                                               {0,3,1,1,3,3,3,3}};
00476     const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7];
00477     const int edges = mask_edge== 3 && !(h->cbp&15) ? 1 : 4;
00478 
00479     
00480     const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir));
00481 
00482     if(mbm_type && !first_vertical_edge_done){
00483 
00484         if (FRAME_MBAFF && (dir == 1) && ((mb_y&1) == 0)
00485             && IS_INTERLACED(mbm_type&~mb_type)
00486             ) {
00487             
00488             
00489             
00490             
00491             unsigned int tmp_linesize   = 2 *   linesize;
00492             unsigned int tmp_uvlinesize = 2 * uvlinesize;
00493             int mbn_xy = mb_xy - 2 * s->mb_stride;
00494             int j;
00495 
00496             for(j=0; j<2; j++, mbn_xy += s->mb_stride){
00497                 DECLARE_ALIGNED(8, int16_t, bS)[4];
00498                 int qp;
00499                 if (IS_INTRA(mb_type | s->current_picture.f.mb_type[mbn_xy])) {
00500                     AV_WN64A(bS, 0x0003000300030003ULL);
00501                 } else {
00502                     if (!CABAC && IS_8x8DCT(s->current_picture.f.mb_type[mbn_xy])) {
00503                         bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+0]);
00504                         bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+1]);
00505                         bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+2]);
00506                         bS[3]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+3]);
00507                     }else{
00508                     const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 3*4;
00509                     int i;
00510                     for( i = 0; i < 4; i++ ) {
00511                         bS[i] = 1 + !!(h->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]);
00512                     }
00513                     }
00514                 }
00515                 
00516                 
00517                 qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbn_xy] + 1) >> 1;
00518                 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);
00519                 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
00520                 filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, a, b, h, 0 );
00521                 chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1;
00522                 chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1;
00523                 if (chroma) {
00524                     if (chroma444) {
00525                         filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0);
00526                         filter_mb_edgeh (&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0);
00527                     } else {
00528                         filter_mb_edgech(&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0);
00529                         filter_mb_edgech(&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0);
00530                     }
00531                 }
00532             }
00533         }else{
00534             DECLARE_ALIGNED(8, int16_t, bS)[4];
00535             int qp;
00536 
00537             if( IS_INTRA(mb_type|mbm_type)) {
00538                 AV_WN64A(bS, 0x0003000300030003ULL);
00539                 if (   (!IS_INTERLACED(mb_type|mbm_type))
00540                     || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0))
00541                 )
00542                     AV_WN64A(bS, 0x0004000400040004ULL);
00543             } else {
00544                 int i;
00545                 int mv_done;
00546 
00547                 if( dir && FRAME_MBAFF && IS_INTERLACED(mb_type ^ mbm_type)) {
00548                     AV_WN64A(bS, 0x0001000100010001ULL);
00549                     mv_done = 1;
00550                 }
00551                 else if( mask_par0 && ((mbm_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) {
00552                     int b_idx= 8 + 4;
00553                     int bn_idx= b_idx - (dir ? 8:1);
00554 
00555                     bS[0] = bS[1] = bS[2] = bS[3] = check_mv(h, 8 + 4, bn_idx, mvy_limit);
00556                     mv_done = 1;
00557                 }
00558                 else
00559                     mv_done = 0;
00560 
00561                 for( i = 0; i < 4; i++ ) {
00562                     int x = dir == 0 ? 0 : i;
00563                     int y = dir == 0 ? i    : 0;
00564                     int b_idx= 8 + 4 + x + 8*y;
00565                     int bn_idx= b_idx - (dir ? 8:1);
00566 
00567                     if( h->non_zero_count_cache[b_idx] |
00568                         h->non_zero_count_cache[bn_idx] ) {
00569                         bS[i] = 2;
00570                     }
00571                     else if(!mv_done)
00572                     {
00573                         bS[i] = check_mv(h, b_idx, bn_idx, mvy_limit);
00574                     }
00575                 }
00576             }
00577 
00578             
00579             
00580             
00581             if(bS[0]+bS[1]+bS[2]+bS[3]){
00582                 qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbm_xy] + 1) >> 1;
00583                 
00584                 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
00585                 
00586                 chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1;
00587                 chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1;
00588                 if( dir == 0 ) {
00589                     filter_mb_edgev( &img_y[0], linesize, bS, qp, a, b, h, 1 );
00590                     if (chroma) {
00591                         if (chroma444) {
00592                             filter_mb_edgev ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
00593                             filter_mb_edgev ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
00594                         } else {
00595                             filter_mb_edgecv( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
00596                             filter_mb_edgecv( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
00597                         }
00598                     }
00599                 } else {
00600                     filter_mb_edgeh( &img_y[0], linesize, bS, qp, a, b, h, 1 );
00601                     if (chroma) {
00602                         if (chroma444) {
00603                             filter_mb_edgeh ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
00604                             filter_mb_edgeh ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
00605                         } else {
00606                             filter_mb_edgech( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
00607                             filter_mb_edgech( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
00608                         }
00609                     }
00610                 }
00611             }
00612         }
00613     }
00614 
00615     
00616     for( edge = 1; edge < edges; edge++ ) {
00617         DECLARE_ALIGNED(8, int16_t, bS)[4];
00618         int qp;
00619         const int deblock_edge = !IS_8x8DCT(mb_type & (edge<<24)); 
00620 
00621         if (!deblock_edge && (!chroma422 || dir == 0))
00622             continue;
00623 
00624         if( IS_INTRA(mb_type)) {
00625             AV_WN64A(bS, 0x0003000300030003ULL);
00626         } else {
00627             int i;
00628             int mv_done;
00629 
00630             if( edge & mask_edge ) {
00631                 AV_ZERO64(bS);
00632                 mv_done = 1;
00633             }
00634             else if( mask_par0 ) {
00635                 int b_idx= 8 + 4 + edge * (dir ? 8:1);
00636                 int bn_idx= b_idx - (dir ? 8:1);
00637 
00638                 bS[0] = bS[1] = bS[2] = bS[3] = check_mv(h, b_idx, bn_idx, mvy_limit);
00639                 mv_done = 1;
00640             }
00641             else
00642                 mv_done = 0;
00643 
00644             for( i = 0; i < 4; i++ ) {
00645                 int x = dir == 0 ? edge : i;
00646                 int y = dir == 0 ? i    : edge;
00647                 int b_idx= 8 + 4 + x + 8*y;
00648                 int bn_idx= b_idx - (dir ? 8:1);
00649 
00650                 if( h->non_zero_count_cache[b_idx] |
00651                     h->non_zero_count_cache[bn_idx] ) {
00652                     bS[i] = 2;
00653                 }
00654                 else if(!mv_done)
00655                 {
00656                     bS[i] = check_mv(h, b_idx, bn_idx, mvy_limit);
00657                 }
00658             }
00659 
00660             if(bS[0]+bS[1]+bS[2]+bS[3] == 0)
00661                 continue;
00662         }
00663 
00664         
00665         
00666         
00667         qp = s->current_picture.f.qscale_table[mb_xy];
00668         
00669         tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
00670         
00671         if( dir == 0 ) {
00672             filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, a, b, h, 0 );
00673             if (chroma) {
00674                 if (chroma444) {
00675                     filter_mb_edgev ( &img_cb[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
00676                     filter_mb_edgev ( &img_cr[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
00677                 } else if( (edge&1) == 0 ) {
00678                     filter_mb_edgecv( &img_cb[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
00679                     filter_mb_edgecv( &img_cr[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
00680                 }
00681             }
00682         } else {
00683             if (chroma422) {
00684                 if (deblock_edge)
00685                     filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0);
00686                 if (chroma) {
00687                     filter_mb_edgech(&img_cb[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
00688                     filter_mb_edgech(&img_cr[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
00689                 }
00690             } else {
00691                 filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0);
00692                 if (chroma) {
00693                     if (chroma444) {
00694                         filter_mb_edgeh (&img_cb[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
00695                         filter_mb_edgeh (&img_cr[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
00696                     } else if ((edge&1) == 0) {
00697                         filter_mb_edgech(&img_cb[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
00698                         filter_mb_edgech(&img_cr[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
00699                     }
00700                 }
00701             }
00702         }
00703     }
00704 }
00705 
00706 void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {
00707     MpegEncContext * const s = &h->s;
00708     const int mb_xy= mb_x + mb_y*s->mb_stride;
00709     const int mb_type = s->current_picture.f.mb_type[mb_xy];
00710     const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4;
00711     int first_vertical_edge_done = 0;
00712     av_unused int dir;
00713     int chroma = CHROMA && !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));
00714     int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
00715     int a = h->slice_alpha_c0_offset - qp_bd_offset;
00716     int b = h->slice_beta_offset - qp_bd_offset;
00717 
00718     if (FRAME_MBAFF
00719             
00720             && IS_INTERLACED(mb_type^h->left_type[LTOP])
00721             
00722             && h->left_type[LTOP]) {
00723         
00724 
00725 
00726         DECLARE_ALIGNED(8, int16_t, bS)[8];
00727         int qp[2];
00728         int bqp[2];
00729         int rqp[2];
00730         int mb_qp, mbn0_qp, mbn1_qp;
00731         int i;
00732         first_vertical_edge_done = 1;
00733 
00734         if( IS_INTRA(mb_type) ) {
00735             AV_WN64A(&bS[0], 0x0004000400040004ULL);
00736             AV_WN64A(&bS[4], 0x0004000400040004ULL);
00737         } else {
00738             static const uint8_t offset[2][2][8]={
00739                 {
00740                     {3+4*0, 3+4*0, 3+4*0, 3+4*0, 3+4*1, 3+4*1, 3+4*1, 3+4*1},
00741                     {3+4*2, 3+4*2, 3+4*2, 3+4*2, 3+4*3, 3+4*3, 3+4*3, 3+4*3},
00742                 },{
00743                     {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},
00744                     {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},
00745                 }
00746             };
00747             const uint8_t *off= offset[MB_FIELD][mb_y&1];
00748             for( i = 0; i < 8; i++ ) {
00749                 int j= MB_FIELD ? i>>2 : i&1;
00750                 int mbn_xy = h->left_mb_xy[LEFT(j)];
00751                 int mbn_type= h->left_type[LEFT(j)];
00752 
00753                 if( IS_INTRA( mbn_type ) )
00754                     bS[i] = 4;
00755                 else{
00756                     bS[i] = 1 + !!(h->non_zero_count_cache[12+8*(i>>1)] |
00757                          ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ?
00758                             (h->cbp_table[mbn_xy] & (((MB_FIELD ? (i&2) : (mb_y&1)) ? 8 : 2) << 12))
00759                                                                        :
00760                             h->non_zero_count[mbn_xy][ off[i] ]));
00761                 }
00762             }
00763         }
00764 
00765         mb_qp   = s->current_picture.f.qscale_table[mb_xy];
00766         mbn0_qp = s->current_picture.f.qscale_table[h->left_mb_xy[0]];
00767         mbn1_qp = s->current_picture.f.qscale_table[h->left_mb_xy[1]];
00768         qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1;
00769         bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) +
00770                    get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1;
00771         rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) +
00772                    get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1;
00773         qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;
00774         bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) +
00775                    get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1;
00776         rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) +
00777                    get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1;
00778 
00779         
00780         tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize);
00781         { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
00782         if(MB_FIELD){
00783             filter_mb_mbaff_edgev ( h, img_y                ,   linesize, bS  , 1, qp [0], a, b, 1 );
00784             filter_mb_mbaff_edgev ( h, img_y  + 8*  linesize,   linesize, bS+4, 1, qp [1], a, b, 1 );
00785             if (chroma){
00786                 if (CHROMA444) {
00787                     filter_mb_mbaff_edgev ( h, img_cb,                uvlinesize, bS  , 1, bqp[0], a, b, 1 );
00788                     filter_mb_mbaff_edgev ( h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 );
00789                     filter_mb_mbaff_edgev ( h, img_cr,                uvlinesize, bS  , 1, rqp[0], a, b, 1 );
00790                     filter_mb_mbaff_edgev ( h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 );
00791                 } else if (CHROMA422) {
00792                     filter_mb_mbaff_edgecv(h, img_cb,                uvlinesize, bS  , 1, bqp[0], a, b, 1);
00793                     filter_mb_mbaff_edgecv(h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1);
00794                     filter_mb_mbaff_edgecv(h, img_cr,                uvlinesize, bS  , 1, rqp[0], a, b, 1);
00795                     filter_mb_mbaff_edgecv(h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1);
00796                 }else{
00797                     filter_mb_mbaff_edgecv( h, img_cb,                uvlinesize, bS  , 1, bqp[0], a, b, 1 );
00798                     filter_mb_mbaff_edgecv( h, img_cb + 4*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 );
00799                     filter_mb_mbaff_edgecv( h, img_cr,                uvlinesize, bS  , 1, rqp[0], a, b, 1 );
00800                     filter_mb_mbaff_edgecv( h, img_cr + 4*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 );
00801                 }
00802             }
00803         }else{
00804             filter_mb_mbaff_edgev ( h, img_y              , 2*  linesize, bS  , 2, qp [0], a, b, 1 );
00805             filter_mb_mbaff_edgev ( h, img_y  +   linesize, 2*  linesize, bS+1, 2, qp [1], a, b, 1 );
00806             if (chroma){
00807                 if (CHROMA444) {
00808                     filter_mb_mbaff_edgev ( h, img_cb,              2*uvlinesize, bS  , 2, bqp[0], a, b, 1 );
00809                     filter_mb_mbaff_edgev ( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 );
00810                     filter_mb_mbaff_edgev ( h, img_cr,              2*uvlinesize, bS  , 2, rqp[0], a, b, 1 );
00811                     filter_mb_mbaff_edgev ( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 );
00812                 }else{
00813                     filter_mb_mbaff_edgecv( h, img_cb,              2*uvlinesize, bS  , 2, bqp[0], a, b, 1 );
00814                     filter_mb_mbaff_edgecv( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 );
00815                     filter_mb_mbaff_edgecv( h, img_cr,              2*uvlinesize, bS  , 2, rqp[0], a, b, 1 );
00816                     filter_mb_mbaff_edgecv( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 );
00817                 }
00818             }
00819         }
00820     }
00821 
00822 #if CONFIG_SMALL
00823     for( dir = 0; dir < 2; dir++ )
00824         filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, a, b, chroma, dir);
00825 #else
00826     filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, a, b, chroma, 0);
00827     filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0,                        a, b, chroma, 1);
00828 #endif
00829 }