comparison h264_loopfilter.c @ 11013:5e5d44c920b6 libavcodec

Simplify loop filter a little by using top/left_type.
author michael
date Tue, 26 Jan 2010 13:39:26 +0000
parents 541acd292c48
children d844c58b985a
comparison
equal deleted inserted replaced
11012:b2fd83b26dd9 11013:5e5d44c920b6
305 } 305 }
306 } 306 }
307 307
308 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) { 308 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) {
309 MpegEncContext * const s = &h->s; 309 MpegEncContext * const s = &h->s;
310 int mb_y_firstrow = s->picture_structure == PICT_BOTTOM_FIELD; 310 int mb_xy;
311 int mb_xy, mb_type; 311 int mb_type;
312 int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh; 312 int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh;
313 313
314 mb_xy = h->mb_xy; 314 mb_xy = h->mb_xy;
315 315
316 if(mb_x==0 || mb_y==mb_y_firstrow || !s->dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff || 316 if(!h->top_type || !h->left_type[0] || !s->dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff) {
317 (h->deblocking_filter == 2 && (h->slice_num != h->slice_table[h->top_mb_xy] ||
318 h->slice_num != h->slice_table[mb_xy - 1]))) {
319 ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); 317 ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);
320 return; 318 return;
321 } 319 }
322 assert(!FRAME_MBAFF); 320 assert(!FRAME_MBAFF);
323 321
374 bSv[0][0] = bSv[0][2] = bSv[1][0] = bSv[1][2] = 0x0002000200020002ULL; 372 bSv[0][0] = bSv[0][2] = bSv[1][0] = bSv[1][2] = 0x0002000200020002ULL;
375 } else { 373 } else {
376 int mask_edge1 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : 374 int mask_edge1 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 :
377 (mb_type & MB_TYPE_16x8) ? 1 : 0; 375 (mb_type & MB_TYPE_16x8) ? 1 : 0;
378 int mask_edge0 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) 376 int mask_edge0 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16))
379 && (s->current_picture.mb_type[mb_xy-1] & (MB_TYPE_16x16 | MB_TYPE_8x16)) 377 && (h->left_type[0] & (MB_TYPE_16x16 | MB_TYPE_8x16))
380 ? 3 : 0; 378 ? 3 : 0;
381 int step = IS_8x8DCT(mb_type) ? 2 : 1; 379 int step = IS_8x8DCT(mb_type) ? 2 : 1;
382 edges = (mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; 380 edges = (mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4;
383 s->dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache, 381 s->dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache,
384 h->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE); 382 h->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE);
385 } 383 }
386 if( IS_INTRA(s->current_picture.mb_type[mb_xy-1]) ) 384 if( IS_INTRA(h->left_type[0]) )
387 bSv[0][0] = 0x0004000400040004ULL; 385 bSv[0][0] = 0x0004000400040004ULL;
388 if( IS_INTRA(s->current_picture.mb_type[h->top_mb_xy]) ) 386 if( IS_INTRA(h->top_type) )
389 bSv[1][0] = FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL; 387 bSv[1][0] = FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL;
390 388
391 #define FILTER(hv,dir,edge)\ 389 #define FILTER(hv,dir,edge)\
392 if(bSv[dir][edge]) {\ 390 if(bSv[dir][edge]) {\
393 filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qp : qp##dir, h );\ 391 filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qp : qp##dir, h );\
421 419
422 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 dir) { 420 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 dir) {
423 MpegEncContext * const s = &h->s; 421 MpegEncContext * const s = &h->s;
424 int edge; 422 int edge;
425 const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy; 423 const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy;
426 const int mbm_type = s->current_picture.mb_type[mbm_xy]; 424 const int mbm_type = dir == 0 ? h->left_type[0] : h->top_type;
427 425
428 // how often to recheck mv-based bS when iterating between edges 426 // how often to recheck mv-based bS when iterating between edges
429 static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1}, 427 static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1},
430 {0,3,1,1,3,3,3,3}}; 428 {0,3,1,1,3,3,3,3}};
431 const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7]; 429 const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7];
616 614
617 if (FRAME_MBAFF 615 if (FRAME_MBAFF
618 // left mb is in picture 616 // left mb is in picture
619 && h->slice_table[mb_xy-1] != 0xFFFF 617 && h->slice_table[mb_xy-1] != 0xFFFF
620 // and current and left pair do not have the same interlaced type 618 // and current and left pair do not have the same interlaced type
621 && IS_INTERLACED(mb_type^s->current_picture.mb_type[mb_xy-1]) 619 && IS_INTERLACED(mb_type^h->left_type[0])
622 // and left mb is in the same slice if deblocking_filter == 2 620 // and left mb is in the same slice if deblocking_filter == 2
623 && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_num)) { 621 && h->left_type[0]) {
624 /* First vertical edge is different in MBAFF frames 622 /* First vertical edge is different in MBAFF frames
625 * There are 8 different bS to compute and 2 different Qp 623 * There are 8 different bS to compute and 2 different Qp
626 */ 624 */
627 const int pair_xy = mb_x + (mb_y&~1)*s->mb_stride; 625 const int pair_xy = mb_x + (mb_y&~1)*s->mb_stride;
628 const int left_mb_xy[2] = { pair_xy-1, pair_xy-1+s->mb_stride }; 626 const int left_mb_xy[2] = { pair_xy-1, pair_xy-1+s->mb_stride };