41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 4, 4, 5, 6,
47 7, 8, 9, 10, 12, 13, 15, 17, 20, 22,
48 25, 28, 32, 36, 40, 45, 50, 56, 63, 71,
49 80, 90,101,113,127,144,162,182,203,226,
51 255,255,255,255,255,255,255,255,255,255,255,255,255,
52 255,255,255,255,255,255,255,255,255,255,255,255,255,
53 255,255,255,255,255,255,255,255,255,255,255,255,255,
54 255,255,255,255,255,255,255,255,255,255,255,255,255,
57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62 0, 0, 0, 0, 0, 0, 2, 2, 2, 3,
63 3, 3, 3, 4, 4, 4, 6, 6, 7, 7,
64 8, 8, 9, 9, 10, 10, 11, 11, 12, 12,
65 13, 13, 14, 14, 15, 15, 16, 16, 17, 17,
67 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
68 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
69 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
70 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
73 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
74 {-1, 0, 0,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 1, 1 }, {-1, 0, 1, 1 }, {-1, 1, 1, 1 },
86 {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 },
87 {-1, 1, 1, 2 }, {-1, 1, 2, 3 }, {-1, 1, 2, 3 }, {-1, 2, 2, 3 }, {-1, 2, 2, 4 }, {-1, 2, 3, 4 },
88 {-1, 2, 3, 4 }, {-1, 3, 3, 5 }, {-1, 3, 4, 6 }, {-1, 3, 4, 6 }, {-1, 4, 5, 7 }, {-1, 4, 5, 8 },
89 {-1, 4, 6, 9 }, {-1, 5, 7,10 }, {-1, 6, 8,11 }, {-1, 6, 8,13 }, {-1, 7,10,14 }, {-1, 8,11,16 },
90 {-1, 9,12,18 }, {-1,10,13,20 }, {-1,11,15,23 }, {-1,13,17,25 },
91 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
92 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
93 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
94 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
95 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
96 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
97 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
98 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
99 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
105 unsigned int qp,
int a,
int b,
108 const unsigned int index_a = qp +
a;
111 if (
alpha ==0 || beta == 0)
return;
113 if( bS[0] < 4 || !intra ) {
121 h->h264dsp.h264_h_loop_filter_luma_intra(pix,
stride,
alpha, beta);
127 unsigned int qp,
int a,
int b,
130 const unsigned int index_a = qp +
a;
133 if (
alpha ==0 || beta == 0)
return;
135 if( bS[0] < 4 || !intra ) {
141 h->h264dsp.h264_h_loop_filter_chroma(pix,
stride,
alpha, beta,
tc);
143 h->h264dsp.h264_h_loop_filter_chroma_intra(pix,
stride,
alpha, beta);
149 const int16_t bS[7],
int bsi,
150 int qp,
int a,
int b,
153 const unsigned int index_a = qp +
a;
156 if (
alpha ==0 || beta == 0)
return;
158 if( bS[0] < 4 || !intra ) {
164 h->h264dsp.h264_h_loop_filter_luma_mbaff(pix,
stride,
alpha, beta,
tc);
166 h->h264dsp.h264_h_loop_filter_luma_mbaff_intra(pix,
stride,
alpha, beta);
173 int bsi,
int qp,
int a,
176 const unsigned int index_a = qp +
a;
179 if (
alpha ==0 || beta == 0)
return;
181 if( bS[0] < 4 || !intra ) {
187 h->h264dsp.h264_h_loop_filter_chroma_mbaff(pix,
stride,
alpha, beta,
tc);
189 h->h264dsp.h264_h_loop_filter_chroma_mbaff_intra(pix,
stride,
alpha, beta);
195 unsigned int qp,
int a,
int b,
198 const unsigned int index_a = qp +
a;
201 if (
alpha ==0 || beta == 0)
return;
203 if( bS[0] < 4 || !intra ) {
211 h->h264dsp.h264_v_loop_filter_luma_intra(pix,
stride,
alpha, beta);
217 unsigned int qp,
int a,
int b,
220 const unsigned int index_a = qp +
a;
223 if (
alpha ==0 || beta == 0)
return;
225 if( bS[0] < 4 || !intra ) {
231 h->h264dsp.h264_v_loop_filter_chroma(pix,
stride,
alpha, beta,
tc);
233 h->h264dsp.h264_v_loop_filter_chroma_intra(pix,
stride,
alpha, beta);
243 unsigned int linesize,
244 unsigned int uvlinesize,
251 int mb_xy = sl->
mb_xy;
255 int qp_bd_offset = 6 * (
h->ps.sps->bit_depth_luma - 8);
259 int mb_type =
h->cur_pic.mb_type[mb_xy];
260 int qp =
h->cur_pic.qscale_table[mb_xy];
261 int qp0 =
h->cur_pic.qscale_table[mb_xy - 1];
262 int qp1 =
h->cur_pic.qscale_table[sl->
top_mb_xy];
266 qp0 = (qp + qp0 + 1) >> 1;
267 qp1 = (qp + qp1 + 1) >> 1;
268 qpc0 = (qpc + qpc0 + 1) >> 1;
269 qpc1 = (qpc + qpc1 + 1) >> 1;
272 static const int16_t bS4[4] = {4,4,4,4};
273 static const int16_t bS3[4] = {3,3,3,3};
363 if(
IS_8x8DCT(mb_type) && (sl->
cbp&7) == 7 && !chroma444 ) {
365 AV_WN64A(bS[0][0], 0x0002000200020002ULL);
366 AV_WN64A(bS[0][2], 0x0002000200020002ULL);
367 AV_WN64A(bS[1][0], 0x0002000200020002ULL);
368 AV_WN64A(bS[1][2], 0x0002000200020002ULL);
370 int mask_edge1 = (3*(((5*mb_type)>>5)&1)) | (mb_type>>4);
371 int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1);
372 int step = 1+(mb_type>>24);
373 edges = 4 - 3*((mb_type>>3) & !(sl->
cbp & 15));
378 AV_WN64A(bS[0][0], 0x0004000400040004ULL);
382 #define FILTER(hv,dir,edge,intra)\
383 if(AV_RN64A(bS[dir][edge])) { \
384 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 );\
387 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 );\
388 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 );\
389 } else if(!(edge&1)) {\
390 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 );\
391 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 );\
420 int mb_x,
int mb_y, uint8_t *img_y,
421 uint8_t *img_cb, uint8_t *img_cr,
422 unsigned int linesize,
unsigned int uvlinesize)
425 if(!
h->h264dsp.h264_loop_filter_strength ||
h->ps.pps->chroma_qp_diff) {
473 uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
474 unsigned int linesize,
unsigned int uvlinesize,
475 int mb_xy,
int mb_type,
int mvy_limit,
476 int first_vertical_edge_done,
int a,
int b,
480 int chroma_qp_avg[2];
483 const int mbm_xy = dir == 0 ? mb_xy -1 : sl->
top_mb_xy;
487 static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1},
489 const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7];
490 const int edges = mask_edge== 3 && !(sl->
cbp&15) ? 1 : 4;
495 if(mbm_type && !first_vertical_edge_done){
504 unsigned int tmp_linesize = 2 * linesize;
505 unsigned int tmp_uvlinesize = 2 * uvlinesize;
506 int mbn_xy = mb_xy - 2 *
h->mb_stride;
509 for(j=0; j<2; j++, mbn_xy +=
h->mb_stride){
512 if (
IS_INTRA(mb_type |
h->cur_pic.mb_type[mbn_xy])) {
513 AV_WN64A(bS, 0x0003000300030003ULL);
521 const uint8_t *mbn_nnz =
h->non_zero_count[mbn_xy] + 3*4;
523 for(
i = 0;
i < 4;
i++ ) {
530 qp = (
h->cur_pic.qscale_table[mb_xy] +
h->cur_pic.qscale_table[mbn_xy] + 1) >> 1;
531 ff_tlog(
h->avctx,
"filter mb:%d/%d dir:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, qp, tmp_linesize, tmp_uvlinesize);
538 filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0],
a,
b,
h, 0);
539 filter_mb_edgeh (&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1],
a,
b,
h, 0);
551 AV_WN64A(bS, 0x0003000300030003ULL);
555 AV_WN64A(bS, 0x0004000400040004ULL);
561 AV_WN64A(bS, 0x0001000100010001ULL);
566 int bn_idx= b_idx - (dir ? 8:1);
568 bS[0] = bS[1] = bS[2] = bS[3] =
check_mv(sl, 8 + 4, bn_idx, mvy_limit);
574 for(
i = 0;
i < 4;
i++ ) {
575 int x = dir == 0 ? 0 :
i;
576 int y = dir == 0 ?
i : 0;
577 int b_idx= 8 + 4 + x + 8*y;
578 int bn_idx= b_idx - (dir ? 8:1);
586 bS[
i] =
check_mv(sl, b_idx, bn_idx, mvy_limit);
594 if(bS[0]+bS[1]+bS[2]+bS[3]){
595 qp = (
h->cur_pic.qscale_table[mb_xy] +
h->cur_pic.qscale_table[mbm_xy] + 1) >> 1;
597 ff_tlog(
h->avctx,
"filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
629 for( edge = 1; edge < edges; edge++ ) {
632 const int deblock_edge = !
IS_8x8DCT(mb_type & (edge<<24));
634 if (!deblock_edge && (!chroma422 || dir == 0))
638 AV_WN64A(bS, 0x0003000300030003ULL);
643 if( edge & mask_edge ) {
647 else if( mask_par0 ) {
648 int b_idx= 8 + 4 + edge * (dir ? 8:1);
649 int bn_idx= b_idx - (dir ? 8:1);
651 bS[0] = bS[1] = bS[2] = bS[3] =
check_mv(sl, b_idx, bn_idx, mvy_limit);
657 for(
i = 0;
i < 4;
i++ ) {
658 int x = dir == 0 ? edge :
i;
659 int y = dir == 0 ?
i : edge;
660 int b_idx= 8 + 4 + x + 8*y;
661 int bn_idx= b_idx - (dir ? 8:1);
669 bS[
i] =
check_mv(sl, b_idx, bn_idx, mvy_limit);
673 if(bS[0]+bS[1]+bS[2]+bS[3] == 0)
680 qp =
h->cur_pic.qscale_table[mb_xy];
682 ff_tlog(
h->avctx,
"filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
690 }
else if( (edge&1) == 0 ) {
709 }
else if ((edge&1) == 0) {
721 uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
722 unsigned int linesize,
unsigned int uvlinesize)
724 const int mb_xy= mb_x + mb_y*
h->mb_stride;
725 const int mb_type =
h->cur_pic.mb_type[mb_xy];
727 int first_vertical_edge_done = 0;
729 int qp_bd_offset = 6 * (
h->ps.sps->bit_depth_luma - 8);
745 int mb_qp, mbn0_qp, mbn1_qp;
747 first_vertical_edge_done = 1;
750 AV_WN64A(&bS[0], 0x0004000400040004ULL);
751 AV_WN64A(&bS[4], 0x0004000400040004ULL);
753 static const uint8_t
offset[2][2][8]={
755 {3+4*0, 3+4*0, 3+4*0, 3+4*0, 3+4*1, 3+4*1, 3+4*1, 3+4*1},
756 {3+4*2, 3+4*2, 3+4*2, 3+4*2, 3+4*3, 3+4*3, 3+4*3, 3+4*3},
758 {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},
759 {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},
763 for(
i = 0;
i < 8;
i++ ) {
773 (
h->cbp_table[mbn_xy] & (((
MB_FIELD(sl) ? (
i&2) : (mb_y&1)) ? 8 : 2) << 12))
775 h->non_zero_count[mbn_xy][ off[
i] ]));
780 mb_qp =
h->cur_pic.qscale_table[mb_xy];
781 mbn0_qp =
h->cur_pic.qscale_table[sl->
left_mb_xy[0]];
782 mbn1_qp =
h->cur_pic.qscale_table[sl->
left_mb_xy[1]];
783 qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1;
788 qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;
795 ff_tlog(
h->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);
840 for (dir = 0; dir < 2; dir++)
842 uvlinesize, mb_xy, mb_type, mvy_limit,
843 dir ? 0 : first_vertical_edge_done,
a,
b,
847 filter_mb_dir(
h, sl, 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);
848 filter_mb_dir(
h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0,
a,
b,
chroma, 1);