comparison h264_loopfilter.c @ 11035:4debec8a15fa libavcodec

Cosmetics, mostly indention, 2 or so new fixme comments that i was to lazy to split out
author michael
date Thu, 28 Jan 2010 02:20:31 +0000
parents fd5921186064
children faedf5cdb8c3
comparison
equal deleted inserted replaced
11034:fd5921186064 11035:4debec8a15fa
340 int16_t bS4[4] = {4,4,4,4}; 340 int16_t bS4[4] = {4,4,4,4};
341 int16_t bS3[4] = {3,3,3,3}; 341 int16_t bS3[4] = {3,3,3,3};
342 int16_t *bSH = FIELD_PICTURE ? bS3 : bS4; 342 int16_t *bSH = FIELD_PICTURE ? bS3 : bS4;
343 if( IS_8x8DCT(mb_type) ) { 343 if( IS_8x8DCT(mb_type) ) {
344 if(left_type) 344 if(left_type)
345 filter_mb_edgev( &img_y[4*0], linesize, bS4, qp0, h); 345 filter_mb_edgev( &img_y[4*0], linesize, bS4, qp0, h);
346 filter_mb_edgev( &img_y[4*2], linesize, bS3, qp, h); 346 filter_mb_edgev( &img_y[4*2], linesize, bS3, qp, h);
347 filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, h); 347 filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, h);
348 filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, h); 348 filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, h);
349 } else { 349 } else {
350 if(left_type) 350 if(left_type)
351 filter_mb_edgev( &img_y[4*0], linesize, bS4, qp0, h); 351 filter_mb_edgev( &img_y[4*0], linesize, bS4, qp0, h);
352 filter_mb_edgev( &img_y[4*1], linesize, bS3, qp, h); 352 filter_mb_edgev( &img_y[4*1], linesize, bS3, qp, h);
353 filter_mb_edgev( &img_y[4*2], linesize, bS3, qp, h); 353 filter_mb_edgev( &img_y[4*2], linesize, bS3, qp, h);
354 filter_mb_edgev( &img_y[4*3], linesize, bS3, qp, h); 354 filter_mb_edgev( &img_y[4*3], linesize, bS3, qp, h);
355 filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, h); 355 filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, h);
356 filter_mb_edgeh( &img_y[4*1*linesize], linesize, bS3, qp, h); 356 filter_mb_edgeh( &img_y[4*1*linesize], linesize, bS3, qp, h);
399 filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, h );\ 399 filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, h );\
400 }\ 400 }\
401 } 401 }
402 if( edges == 1 ) { 402 if( edges == 1 ) {
403 if(left_type) 403 if(left_type)
404 FILTER(v,0,0); 404 FILTER(v,0,0);
405 FILTER(h,1,0); 405 FILTER(h,1,0);
406 } else if( IS_8x8DCT(mb_type) ) { 406 } else if( IS_8x8DCT(mb_type) ) {
407 if(left_type) 407 if(left_type)
408 FILTER(v,0,0); 408 FILTER(v,0,0);
409 FILTER(v,0,2); 409 FILTER(v,0,2);
410 FILTER(h,1,0); 410 FILTER(h,1,0);
411 FILTER(h,1,2); 411 FILTER(h,1,2);
412 } else { 412 } else {
413 if(left_type) 413 if(left_type)
414 FILTER(v,0,0); 414 FILTER(v,0,0);
415 FILTER(v,0,1); 415 FILTER(v,0,1);
416 FILTER(v,0,2); 416 FILTER(v,0,2);
417 FILTER(v,0,3); 417 FILTER(v,0,3);
418 FILTER(h,1,0); 418 FILTER(h,1,0);
419 FILTER(h,1,1); 419 FILTER(h,1,1);
443 if(!(h->slice_table[mbm_xy] == 0xFFFF 443 if(!(h->slice_table[mbm_xy] == 0xFFFF
444 || first_vertical_edge_done 444 || first_vertical_edge_done
445 || (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_num))){ 445 || (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_num))){
446 446
447 if (FRAME_MBAFF && (dir == 1) && ((mb_y&1) == 0) 447 if (FRAME_MBAFF && (dir == 1) && ((mb_y&1) == 0)
448 && IS_INTERLACED(mbm_type&~mb_type) 448 && IS_INTERLACED(mbm_type&~mb_type)
449 ) { 449 ) {
450 // This is a special case in the norm where the filtering must 450 // This is a special case in the norm where the filtering must
451 // be done twice (one each of the field) even if we are in a 451 // be done twice (one each of the field) even if we are in a
452 // frame macroblock. 452 // frame macroblock.
453 // 453 //
454 unsigned int tmp_linesize = 2 * linesize; 454 unsigned int tmp_linesize = 2 * linesize;
455 unsigned int tmp_uvlinesize = 2 * uvlinesize; 455 unsigned int tmp_uvlinesize = 2 * uvlinesize;
456 int mbn_xy = mb_xy - 2 * s->mb_stride; 456 int mbn_xy = mb_xy - 2 * s->mb_stride;
457 int j; 457 int j;
458 458
459 for(j=0; j<2; j++, mbn_xy += s->mb_stride){ 459 for(j=0; j<2; j++, mbn_xy += s->mb_stride){
460 DECLARE_ALIGNED_8(int16_t, bS)[4];
461 int qp;
462 if( IS_INTRA(mb_type|s->current_picture.mb_type[mbn_xy]) ) {
463 *(uint64_t*)bS= 0x0003000300030003ULL;
464 } else {
465 const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 4+3*8; //FIXME 8x8dct?
466 int i;
467 for( i = 0; i < 4; i++ ) {
468 bS[i] = 1 + !!(h->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]);
469 }
470 }
471 // Do not use s->qscale as luma quantizer because it has not the same
472 // value in IPCM macroblocks.
473 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
474 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);
475 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
476 filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, h );
477 filter_mb_edgech( &img_cb[j*uvlinesize], tmp_uvlinesize, bS,
478 ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1, h);
479 filter_mb_edgech( &img_cr[j*uvlinesize], tmp_uvlinesize, bS,
480 ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1, h);
481 }
482 }else{
460 DECLARE_ALIGNED_8(int16_t, bS)[4]; 483 DECLARE_ALIGNED_8(int16_t, bS)[4];
461 int qp; 484 int qp;
462 if( IS_INTRA(mb_type|s->current_picture.mb_type[mbn_xy]) ) { 485
486 if( IS_INTRA(mb_type|mbm_type)) {
463 *(uint64_t*)bS= 0x0003000300030003ULL; 487 *(uint64_t*)bS= 0x0003000300030003ULL;
488 if ( (!IS_INTERLACED(mb_type|mbm_type))
489 || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0))
490 )
491 *(uint64_t*)bS= 0x0004000400040004ULL;
464 } else { 492 } else {
465 const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 4+3*8; 493 int i, l;
466 int i; 494 int mv_done;
495
496 if( FRAME_MBAFF && IS_INTERLACED(mb_type ^ mbm_type)) { //FIXME not posible left
497 *(uint64_t*)bS= 0x0001000100010001ULL;
498 mv_done = 1;
499 }
500 else if( mask_par0 && ((mbm_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) {
501 int b_idx= 8 + 4;
502 int bn_idx= b_idx - (dir ? 8:1);
503 int v = 0;
504
505 for( l = 0; !v && l < h->list_count; l++ ) {
506 v |= h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] |
507 h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] + 3 >= 7U |
508 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit;
509 }
510
511 if(h->list_count==2 && v){
512 v=0;
513 for( l = 0; !v && l < 2; l++ ) {
514 int ln= 1-l;
515 v |= h->ref_cache[l][b_idx] != h->ref_cache[ln][bn_idx] |
516 h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] + 3 >= 7U |
517 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit;
518 }
519 }
520
521 bS[0] = bS[1] = bS[2] = bS[3] = v;
522 mv_done = 1;
523 }
524 else
525 mv_done = 0;
526
467 for( i = 0; i < 4; i++ ) { 527 for( i = 0; i < 4; i++ ) {
468 bS[i] = 1 + !!(h->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]); 528 int x = dir == 0 ? 0 : i;
469 } 529 int y = dir == 0 ? i : 0;
470 } 530 int b_idx= 8 + 4 + x + 8*y;
471 // Do not use s->qscale as luma quantizer because it has not the same 531 int bn_idx= b_idx - (dir ? 8:1);
472 // value in IPCM macroblocks. 532
473 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; 533 if( h->non_zero_count_cache[b_idx] |
474 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); 534 h->non_zero_count_cache[bn_idx] ) {
475 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } 535 bS[i] = 2;
476 filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, h ); 536 }
477 filter_mb_edgech( &img_cb[j*uvlinesize], tmp_uvlinesize, bS, 537 else if(!mv_done)
478 ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1, h); 538 {
479 filter_mb_edgech( &img_cr[j*uvlinesize], tmp_uvlinesize, bS,
480 ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1, h);
481 }
482 }else{
483 DECLARE_ALIGNED_8(int16_t, bS)[4];
484 int qp;
485
486 if( IS_INTRA(mb_type|mbm_type)) {
487 *(uint64_t*)bS= 0x0003000300030003ULL;
488 if ( (!IS_INTERLACED(mb_type|mbm_type))
489 || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0))
490 )
491 *(uint64_t*)bS= 0x0004000400040004ULL;
492 } else {
493 int i, l;
494 int mv_done;
495
496 if( FRAME_MBAFF && IS_INTERLACED(mb_type ^ mbm_type)) { //FIXME not posible left
497 *(uint64_t*)bS= 0x0001000100010001ULL;
498 mv_done = 1;
499 }
500 else if( mask_par0 && ((mbm_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) {
501 int b_idx= 8 + 4;
502 int bn_idx= b_idx - (dir ? 8:1);
503 int v = 0;
504
505 for( l = 0; !v && l < h->list_count; l++ ) {
506 v |= h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] |
507 h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] + 3 >= 7U |
508 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit;
509 }
510
511 if(h->list_count==2 && v){
512 v=0;
513 for( l = 0; !v && l < 2; l++ ) {
514 int ln= 1-l;
515 v |= h->ref_cache[l][b_idx] != h->ref_cache[ln][bn_idx] |
516 h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] + 3 >= 7U |
517 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit;
518 }
519 }
520
521 bS[0] = bS[1] = bS[2] = bS[3] = v;
522 mv_done = 1;
523 }
524 else
525 mv_done = 0;
526
527 for( i = 0; i < 4; i++ ) {
528 int x = dir == 0 ? 0 : i;
529 int y = dir == 0 ? i : 0;
530 int b_idx= 8 + 4 + x + 8*y;
531 int bn_idx= b_idx - (dir ? 8:1);
532
533 if( h->non_zero_count_cache[b_idx] |
534 h->non_zero_count_cache[bn_idx] ) {
535 bS[i] = 2;
536 }
537 else if(!mv_done)
538 {
539 bS[i] = 0;
540 for( l = 0; l < h->list_count; l++ ) {
541 if( h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] |
542 h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] + 3 >= 7U |
543 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit ) {
544 bS[i] = 1;
545 break;
546 }
547 }
548
549 if(h->list_count == 2 && bS[i]){
550 bS[i] = 0; 539 bS[i] = 0;
551 for( l = 0; l < 2; l++ ) { 540 for( l = 0; l < h->list_count; l++ ) {
552 int ln= 1-l; 541 if( h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] |
553 if( h->ref_cache[l][b_idx] != h->ref_cache[ln][bn_idx] | 542 h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] + 3 >= 7U |
554 h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] + 3 >= 7U | 543 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit ) {
555 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit ) {
556 bS[i] = 1; 544 bS[i] = 1;
557 break; 545 break;
558 } 546 }
559 } 547 }
560 } 548
561 } 549 if(h->list_count == 2 && bS[i]){
562 } 550 bS[i] = 0;
563 } 551 for( l = 0; l < 2; l++ ) {
564 552 int ln= 1-l;
565 /* Filter edge */ 553 if( h->ref_cache[l][b_idx] != h->ref_cache[ln][bn_idx] |
566 // Do not use s->qscale as luma quantizer because it has not the same 554 h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] + 3 >= 7U |
567 // value in IPCM macroblocks. 555 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit ) {
568 if(bS[0]+bS[1]+bS[2]+bS[3]){ 556 bS[i] = 1;
569 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbm_xy] + 1 ) >> 1; 557 break;
570 //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); 558 }
571 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); 559 }
572 //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } 560 }
573 if( dir == 0 ) { 561 }
574 filter_mb_edgev( &img_y[0], linesize, bS, qp, h ); 562 }
575 { 563 }
576 int qp= ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; 564
577 filter_mb_edgecv( &img_cb[0], uvlinesize, bS, qp, h); 565 /* Filter edge */
578 if(h->pps.chroma_qp_diff) 566 // Do not use s->qscale as luma quantizer because it has not the same
579 qp= ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; 567 // value in IPCM macroblocks.
580 filter_mb_edgecv( &img_cr[0], uvlinesize, bS, qp, h); 568 if(bS[0]+bS[1]+bS[2]+bS[3]){
581 } 569 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbm_xy] + 1 ) >> 1;
582 } else { 570 //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]);
583 filter_mb_edgeh( &img_y[0], linesize, bS, qp, h ); 571 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);
584 { 572 //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
585 int qp= ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; 573 if( dir == 0 ) {
586 filter_mb_edgech( &img_cb[0], uvlinesize, bS, qp, h); 574 filter_mb_edgev( &img_y[0], linesize, bS, qp, h );
587 if(h->pps.chroma_qp_diff) 575 {
588 qp= ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; 576 int qp= ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1;
589 filter_mb_edgech( &img_cr[0], uvlinesize, bS, qp, h); 577 filter_mb_edgecv( &img_cb[0], uvlinesize, bS, qp, h);
590 } 578 if(h->pps.chroma_qp_diff)
591 } 579 qp= ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1;
592 } 580 filter_mb_edgecv( &img_cr[0], uvlinesize, bS, qp, h);
593 } 581 }
582 } else {
583 filter_mb_edgeh( &img_y[0], linesize, bS, qp, h );
584 {
585 int qp= ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1;
586 filter_mb_edgech( &img_cb[0], uvlinesize, bS, qp, h);
587 if(h->pps.chroma_qp_diff)
588 qp= ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1;
589 filter_mb_edgech( &img_cr[0], uvlinesize, bS, qp, h);
590 }
591 }
592 }
593 }
594 } 594 }
595 595
596 /* Calculate bS */ 596 /* Calculate bS */
597 for( edge = 1; edge < edges; edge++ ) { 597 for( edge = 1; edge < edges; edge++ ) {
598 DECLARE_ALIGNED_8(int16_t, bS)[4]; 598 DECLARE_ALIGNED_8(int16_t, bS)[4];