Mercurial > libavcodec.hg
annotate h264_loopfilter.c @ 10909:f4cf3960b8c6 libavcodec
Reorganize how values are stored in h->non_zero_count.
~1% faster
| author | michael |
|---|---|
| date | Sun, 17 Jan 2010 23:44:23 +0000 |
| parents | 1b5fba731e24 |
| children | 7cecaa3a6b38 |
| rev | line source |
|---|---|
| 10854 | 1 /* |
| 2 * H.26L/H.264/AVC/JVT/14496-10/... loop filter | |
| 3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2.1 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * FFmpeg is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
| 22 /** | |
| 23 * @file libavcodec/h264_loopfilter.c | |
| 24 * H.264 / AVC / MPEG4 part10 loop filter. | |
| 25 * @author Michael Niedermayer <michaelni@gmx.at> | |
| 26 */ | |
| 27 | |
| 28 #include "internal.h" | |
| 29 #include "dsputil.h" | |
| 30 #include "avcodec.h" | |
| 31 #include "mpegvideo.h" | |
| 32 #include "h264.h" | |
| 33 #include "mathops.h" | |
| 34 #include "rectangle.h" | |
| 35 | |
| 36 #if ARCH_X86 | |
| 37 #include "x86/h264_i386.h" | |
| 38 #endif | |
| 39 | |
| 40 //#undef NDEBUG | |
| 41 #include <assert.h> | |
| 42 | |
| 43 /* Deblocking filter (p153) */ | |
| 44 static const uint8_t alpha_table[52*3] = { | |
| 45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 50 0, 0, 0, 0, 0, 0, 4, 4, 5, 6, | |
| 51 7, 8, 9, 10, 12, 13, 15, 17, 20, 22, | |
| 52 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, | |
| 53 80, 90,101,113,127,144,162,182,203,226, | |
| 54 255,255, | |
| 55 255,255,255,255,255,255,255,255,255,255,255,255,255, | |
| 56 255,255,255,255,255,255,255,255,255,255,255,255,255, | |
| 57 255,255,255,255,255,255,255,255,255,255,255,255,255, | |
| 58 255,255,255,255,255,255,255,255,255,255,255,255,255, | |
| 59 }; | |
| 60 static const uint8_t beta_table[52*3] = { | |
| 61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 66 0, 0, 0, 0, 0, 0, 2, 2, 2, 3, | |
| 67 3, 3, 3, 4, 4, 4, 6, 6, 7, 7, | |
| 68 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, | |
| 69 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, | |
| 70 18, 18, | |
| 71 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, | |
| 72 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, | |
| 73 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, | |
| 74 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, | |
| 75 }; | |
| 76 static const uint8_t tc0_table[52*3][4] = { | |
| 77 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 78 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 79 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 80 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 81 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 82 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 83 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 84 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 85 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 86 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 87 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, | |
| 88 {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 1 }, | |
| 89 {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 1, 1 }, {-1, 0, 1, 1 }, {-1, 1, 1, 1 }, | |
| 90 {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, | |
| 91 {-1, 1, 1, 2 }, {-1, 1, 2, 3 }, {-1, 1, 2, 3 }, {-1, 2, 2, 3 }, {-1, 2, 2, 4 }, {-1, 2, 3, 4 }, | |
| 92 {-1, 2, 3, 4 }, {-1, 3, 3, 5 }, {-1, 3, 4, 6 }, {-1, 3, 4, 6 }, {-1, 4, 5, 7 }, {-1, 4, 5, 8 }, | |
| 93 {-1, 4, 6, 9 }, {-1, 5, 7,10 }, {-1, 6, 8,11 }, {-1, 6, 8,13 }, {-1, 7,10,14 }, {-1, 8,11,16 }, | |
| 94 {-1, 9,12,18 }, {-1,10,13,20 }, {-1,11,15,23 }, {-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 }, {-1,13,17,25 }, {-1,13,17,25 }, | |
| 100 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, | |
| 101 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, | |
| 102 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, | |
| 103 {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, | |
| 104 }; | |
| 105 | |
|
10903
8c8321b94c35
Mark a few functions as noinline, this makes ff_h264_filter_mb() a bit smaller
michael
parents:
10902
diff
changeset
|
106 static void av_noinline filter_mb_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) { |
| 10854 | 107 const int index_a = qp + h->slice_alpha_c0_offset; |
| 108 const int alpha = (alpha_table+52)[index_a]; | |
| 109 const int beta = (beta_table+52)[qp + h->slice_beta_offset]; | |
| 110 if (alpha ==0 || beta == 0) return; | |
| 111 | |
| 112 if( bS[0] < 4 ) { | |
| 113 int8_t tc[4]; | |
| 114 tc[0] = (tc0_table+52)[index_a][bS[0]]; | |
| 115 tc[1] = (tc0_table+52)[index_a][bS[1]]; | |
| 116 tc[2] = (tc0_table+52)[index_a][bS[2]]; | |
| 117 tc[3] = (tc0_table+52)[index_a][bS[3]]; | |
| 118 h->s.dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc); | |
| 119 } else { | |
| 120 h->s.dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta); | |
| 121 } | |
| 122 } | |
|
10903
8c8321b94c35
Mark a few functions as noinline, this makes ff_h264_filter_mb() a bit smaller
michael
parents:
10902
diff
changeset
|
123 static void av_noinline filter_mb_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) { |
| 10854 | 124 const int index_a = qp + h->slice_alpha_c0_offset; |
| 125 const int alpha = (alpha_table+52)[index_a]; | |
| 126 const int beta = (beta_table+52)[qp + h->slice_beta_offset]; | |
| 127 if (alpha ==0 || beta == 0) return; | |
| 128 | |
| 129 if( bS[0] < 4 ) { | |
| 130 int8_t tc[4]; | |
| 131 tc[0] = (tc0_table+52)[index_a][bS[0]]+1; | |
| 132 tc[1] = (tc0_table+52)[index_a][bS[1]]+1; | |
| 133 tc[2] = (tc0_table+52)[index_a][bS[2]]+1; | |
| 134 tc[3] = (tc0_table+52)[index_a][bS[3]]+1; | |
| 135 h->s.dsp.h264_h_loop_filter_chroma(pix, stride, alpha, beta, tc); | |
| 136 } else { | |
| 137 h->s.dsp.h264_h_loop_filter_chroma_intra(pix, stride, alpha, beta); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) { | |
| 142 int i; | |
| 143 for( i = 0; i < 16; i++, pix += stride) { | |
| 144 int index_a; | |
| 145 int alpha; | |
| 146 int beta; | |
| 147 | |
| 148 int qp_index; | |
| 149 int bS_index = (i >> 1); | |
| 150 if (!MB_FIELD) { | |
| 151 bS_index &= ~1; | |
| 152 bS_index |= (i & 1); | |
| 153 } | |
| 154 | |
| 155 if( bS[bS_index] == 0 ) { | |
| 156 continue; | |
| 157 } | |
| 158 | |
| 159 qp_index = MB_FIELD ? (i >> 3) : (i & 1); | |
| 160 index_a = qp[qp_index] + h->slice_alpha_c0_offset; | |
| 161 alpha = (alpha_table+52)[index_a]; | |
| 162 beta = (beta_table+52)[qp[qp_index] + h->slice_beta_offset]; | |
| 163 | |
| 164 if( bS[bS_index] < 4 ) { | |
| 165 const int tc0 = (tc0_table+52)[index_a][bS[bS_index]]; | |
| 166 const int p0 = pix[-1]; | |
| 167 const int p1 = pix[-2]; | |
| 168 const int p2 = pix[-3]; | |
| 169 const int q0 = pix[0]; | |
| 170 const int q1 = pix[1]; | |
| 171 const int q2 = pix[2]; | |
| 172 | |
| 173 if( FFABS( p0 - q0 ) < alpha && | |
| 174 FFABS( p1 - p0 ) < beta && | |
| 175 FFABS( q1 - q0 ) < beta ) { | |
| 176 int tc = tc0; | |
| 177 int i_delta; | |
| 178 | |
| 179 if( FFABS( p2 - p0 ) < beta ) { | |
| 180 pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 181 tc++; | |
| 182 } | |
| 183 if( FFABS( q2 - q0 ) < beta ) { | |
| 184 pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 185 tc++; | |
| 186 } | |
| 187 | |
| 188 i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 189 pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ | |
| 190 pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ | |
| 191 tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); | |
| 192 } | |
| 193 }else{ | |
| 194 const int p0 = pix[-1]; | |
| 195 const int p1 = pix[-2]; | |
| 196 const int p2 = pix[-3]; | |
| 197 | |
| 198 const int q0 = pix[0]; | |
| 199 const int q1 = pix[1]; | |
| 200 const int q2 = pix[2]; | |
| 201 | |
| 202 if( FFABS( p0 - q0 ) < alpha && | |
| 203 FFABS( p1 - p0 ) < beta && | |
| 204 FFABS( q1 - q0 ) < beta ) { | |
| 205 | |
| 206 if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ | |
| 207 if( FFABS( p2 - p0 ) < beta) | |
| 208 { | |
| 209 const int p3 = pix[-4]; | |
| 210 /* p0', p1', p2' */ | |
| 211 pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; | |
| 212 pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; | |
| 213 pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; | |
| 214 } else { | |
| 215 /* p0' */ | |
| 216 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 217 } | |
| 218 if( FFABS( q2 - q0 ) < beta) | |
| 219 { | |
| 220 const int q3 = pix[3]; | |
| 221 /* q0', q1', q2' */ | |
| 222 pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; | |
| 223 pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; | |
| 224 pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; | |
| 225 } else { | |
| 226 /* q0' */ | |
| 227 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 228 } | |
| 229 }else{ | |
| 230 /* p0', q0' */ | |
| 231 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 232 pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 233 } | |
| 234 tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); | |
| 235 } | |
| 236 } | |
| 237 } | |
| 238 } | |
| 239 static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) { | |
| 240 int i; | |
| 241 for( i = 0; i < 8; i++, pix += stride) { | |
| 242 int index_a; | |
| 243 int alpha; | |
| 244 int beta; | |
| 245 | |
| 246 int qp_index; | |
| 247 int bS_index = i; | |
| 248 | |
| 249 if( bS[bS_index] == 0 ) { | |
| 250 continue; | |
| 251 } | |
| 252 | |
| 253 qp_index = MB_FIELD ? (i >> 2) : (i & 1); | |
| 254 index_a = qp[qp_index] + h->slice_alpha_c0_offset; | |
| 255 alpha = (alpha_table+52)[index_a]; | |
| 256 beta = (beta_table+52)[qp[qp_index] + h->slice_beta_offset]; | |
| 257 | |
| 258 if( bS[bS_index] < 4 ) { | |
| 259 const int tc = (tc0_table+52)[index_a][bS[bS_index]] + 1; | |
| 260 const int p0 = pix[-1]; | |
| 261 const int p1 = pix[-2]; | |
| 262 const int q0 = pix[0]; | |
| 263 const int q1 = pix[1]; | |
| 264 | |
| 265 if( FFABS( p0 - q0 ) < alpha && | |
| 266 FFABS( p1 - p0 ) < beta && | |
| 267 FFABS( q1 - q0 ) < beta ) { | |
| 268 const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 269 | |
| 270 pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ | |
| 271 pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ | |
| 272 tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); | |
| 273 } | |
| 274 }else{ | |
| 275 const int p0 = pix[-1]; | |
| 276 const int p1 = pix[-2]; | |
| 277 const int q0 = pix[0]; | |
| 278 const int q1 = pix[1]; | |
| 279 | |
| 280 if( FFABS( p0 - q0 ) < alpha && | |
| 281 FFABS( p1 - p0 ) < beta && | |
| 282 FFABS( q1 - q0 ) < beta ) { | |
| 283 | |
| 284 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ | |
| 285 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ | |
| 286 tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); | |
| 287 } | |
| 288 } | |
| 289 } | |
| 290 } | |
| 291 | |
|
10903
8c8321b94c35
Mark a few functions as noinline, this makes ff_h264_filter_mb() a bit smaller
michael
parents:
10902
diff
changeset
|
292 static void av_noinline filter_mb_edgeh( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) { |
| 10854 | 293 const int index_a = qp + h->slice_alpha_c0_offset; |
| 294 const int alpha = (alpha_table+52)[index_a]; | |
| 295 const int beta = (beta_table+52)[qp + h->slice_beta_offset]; | |
| 296 if (alpha ==0 || beta == 0) return; | |
| 297 | |
| 298 if( bS[0] < 4 ) { | |
| 299 int8_t tc[4]; | |
| 300 tc[0] = (tc0_table+52)[index_a][bS[0]]; | |
| 301 tc[1] = (tc0_table+52)[index_a][bS[1]]; | |
| 302 tc[2] = (tc0_table+52)[index_a][bS[2]]; | |
| 303 tc[3] = (tc0_table+52)[index_a][bS[3]]; | |
| 304 h->s.dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc); | |
| 305 } else { | |
| 306 h->s.dsp.h264_v_loop_filter_luma_intra(pix, stride, alpha, beta); | |
| 307 } | |
| 308 } | |
| 309 | |
|
10903
8c8321b94c35
Mark a few functions as noinline, this makes ff_h264_filter_mb() a bit smaller
michael
parents:
10902
diff
changeset
|
310 static void av_noinline filter_mb_edgech( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) { |
| 10854 | 311 const int index_a = qp + h->slice_alpha_c0_offset; |
| 312 const int alpha = (alpha_table+52)[index_a]; | |
| 313 const int beta = (beta_table+52)[qp + h->slice_beta_offset]; | |
| 314 if (alpha ==0 || beta == 0) return; | |
| 315 | |
| 316 if( bS[0] < 4 ) { | |
| 317 int8_t tc[4]; | |
| 318 tc[0] = (tc0_table+52)[index_a][bS[0]]+1; | |
| 319 tc[1] = (tc0_table+52)[index_a][bS[1]]+1; | |
| 320 tc[2] = (tc0_table+52)[index_a][bS[2]]+1; | |
| 321 tc[3] = (tc0_table+52)[index_a][bS[3]]+1; | |
| 322 h->s.dsp.h264_v_loop_filter_chroma(pix, stride, alpha, beta, tc); | |
| 323 } else { | |
| 324 h->s.dsp.h264_v_loop_filter_chroma_intra(pix, stride, alpha, beta); | |
| 325 } | |
| 326 } | |
| 327 | |
| 328 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) { | |
| 329 MpegEncContext * const s = &h->s; | |
| 330 int mb_y_firstrow = s->picture_structure == PICT_BOTTOM_FIELD; | |
| 331 int mb_xy, mb_type; | |
| 332 int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh; | |
| 333 | |
| 334 mb_xy = h->mb_xy; | |
| 335 | |
| 336 if(mb_x==0 || mb_y==mb_y_firstrow || !s->dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff || | |
| 337 !(s->flags2 & CODEC_FLAG2_FAST) || //FIXME filter_mb_fast is broken, thus hasto be, but should not under CODEC_FLAG2_FAST | |
| 338 (h->deblocking_filter == 2 && (h->slice_table[mb_xy] != h->slice_table[h->top_mb_xy] || | |
| 339 h->slice_table[mb_xy] != h->slice_table[mb_xy - 1]))) { | |
| 340 ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); | |
| 341 return; | |
| 342 } | |
| 343 assert(!FRAME_MBAFF); | |
| 344 | |
| 345 mb_type = s->current_picture.mb_type[mb_xy]; | |
| 346 qp = s->current_picture.qscale_table[mb_xy]; | |
| 347 qp0 = s->current_picture.qscale_table[mb_xy-1]; | |
| 348 qp1 = s->current_picture.qscale_table[h->top_mb_xy]; | |
| 349 qpc = get_chroma_qp( h, 0, qp ); | |
| 350 qpc0 = get_chroma_qp( h, 0, qp0 ); | |
| 351 qpc1 = get_chroma_qp( h, 0, qp1 ); | |
| 352 qp0 = (qp + qp0 + 1) >> 1; | |
| 353 qp1 = (qp + qp1 + 1) >> 1; | |
| 354 qpc0 = (qpc + qpc0 + 1) >> 1; | |
| 355 qpc1 = (qpc + qpc1 + 1) >> 1; | |
| 356 qp_thresh = 15 - h->slice_alpha_c0_offset; | |
| 357 if(qp <= qp_thresh && qp0 <= qp_thresh && qp1 <= qp_thresh && | |
| 358 qpc <= qp_thresh && qpc0 <= qp_thresh && qpc1 <= qp_thresh) | |
| 359 return; | |
| 360 | |
| 361 if( IS_INTRA(mb_type) ) { | |
| 362 int16_t bS4[4] = {4,4,4,4}; | |
| 363 int16_t bS3[4] = {3,3,3,3}; | |
| 364 int16_t *bSH = FIELD_PICTURE ? bS3 : bS4; | |
| 365 if( IS_8x8DCT(mb_type) ) { | |
| 366 filter_mb_edgev( h, &img_y[4*0], linesize, bS4, qp0 ); | |
| 367 filter_mb_edgev( h, &img_y[4*2], linesize, bS3, qp ); | |
| 368 filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bSH, qp1 ); | |
| 369 filter_mb_edgeh( h, &img_y[4*2*linesize], linesize, bS3, qp ); | |
| 370 } else { | |
| 371 filter_mb_edgev( h, &img_y[4*0], linesize, bS4, qp0 ); | |
| 372 filter_mb_edgev( h, &img_y[4*1], linesize, bS3, qp ); | |
| 373 filter_mb_edgev( h, &img_y[4*2], linesize, bS3, qp ); | |
| 374 filter_mb_edgev( h, &img_y[4*3], linesize, bS3, qp ); | |
| 375 filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bSH, qp1 ); | |
| 376 filter_mb_edgeh( h, &img_y[4*1*linesize], linesize, bS3, qp ); | |
| 377 filter_mb_edgeh( h, &img_y[4*2*linesize], linesize, bS3, qp ); | |
| 378 filter_mb_edgeh( h, &img_y[4*3*linesize], linesize, bS3, qp ); | |
| 379 } | |
| 380 filter_mb_edgecv( h, &img_cb[2*0], uvlinesize, bS4, qpc0 ); | |
| 381 filter_mb_edgecv( h, &img_cb[2*2], uvlinesize, bS3, qpc ); | |
| 382 filter_mb_edgecv( h, &img_cr[2*0], uvlinesize, bS4, qpc0 ); | |
| 383 filter_mb_edgecv( h, &img_cr[2*2], uvlinesize, bS3, qpc ); | |
| 384 filter_mb_edgech( h, &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1 ); | |
| 385 filter_mb_edgech( h, &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc ); | |
| 386 filter_mb_edgech( h, &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1 ); | |
| 387 filter_mb_edgech( h, &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc ); | |
| 388 return; | |
| 389 } else { | |
| 390 DECLARE_ALIGNED_8(int16_t, bS[2][4][4]); | |
| 391 uint64_t (*bSv)[4] = (uint64_t(*)[4])bS; | |
| 392 int edges; | |
| 393 if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 ) { | |
| 394 edges = 4; | |
| 395 bSv[0][0] = bSv[0][2] = bSv[1][0] = bSv[1][2] = 0x0002000200020002ULL; | |
| 396 } else { | |
| 397 int mask_edge1 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : | |
| 398 (mb_type & MB_TYPE_16x8) ? 1 : 0; | |
| 399 int mask_edge0 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) | |
| 400 && (s->current_picture.mb_type[mb_xy-1] & (MB_TYPE_16x16 | MB_TYPE_8x16)) | |
| 401 ? 3 : 0; | |
| 402 int step = IS_8x8DCT(mb_type) ? 2 : 1; | |
| 403 edges = (mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; | |
| 404 s->dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache, | |
| 405 (h->slice_type_nos == FF_B_TYPE), edges, step, mask_edge0, mask_edge1, FIELD_PICTURE); | |
| 406 } | |
| 407 if( IS_INTRA(s->current_picture.mb_type[mb_xy-1]) ) | |
| 408 bSv[0][0] = 0x0004000400040004ULL; | |
| 409 if( IS_INTRA(s->current_picture.mb_type[h->top_mb_xy]) ) | |
| 410 bSv[1][0] = FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL; | |
| 411 | |
| 412 #define FILTER(hv,dir,edge)\ | |
| 413 if(bSv[dir][edge]) {\ | |
| 414 filter_mb_edge##hv( h, &img_y[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qp : qp##dir );\ | |
| 415 if(!(edge&1)) {\ | |
| 416 filter_mb_edgec##hv( h, &img_cb[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir );\ | |
| 417 filter_mb_edgec##hv( h, &img_cr[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir );\ | |
| 418 }\ | |
| 419 } | |
| 420 if( edges == 1 ) { | |
| 421 FILTER(v,0,0); | |
| 422 FILTER(h,1,0); | |
| 423 } else if( IS_8x8DCT(mb_type) ) { | |
| 424 FILTER(v,0,0); | |
| 425 FILTER(v,0,2); | |
| 426 FILTER(h,1,0); | |
| 427 FILTER(h,1,2); | |
| 428 } else { | |
| 429 FILTER(v,0,0); | |
| 430 FILTER(v,0,1); | |
| 431 FILTER(v,0,2); | |
| 432 FILTER(v,0,3); | |
| 433 FILTER(h,1,0); | |
| 434 FILTER(h,1,1); | |
| 435 FILTER(h,1,2); | |
| 436 FILTER(h,1,3); | |
| 437 } | |
| 438 #undef FILTER | |
| 439 } | |
| 440 } | |
| 441 | |
| 442 | |
| 443 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) { | |
| 444 MpegEncContext * const s = &h->s; | |
| 445 int edge; | |
| 446 const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy; | |
| 447 const int mbm_type = s->current_picture.mb_type[mbm_xy]; | |
| 448 int (*ref2frm) [64] = h->ref2frm[ h->slice_num &(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); | |
| 449 int (*ref2frmm)[64] = h->ref2frm[ h->slice_table[mbm_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); | |
| 450 int start = h->slice_table[mbm_xy] == 0xFFFF ? 1 : 0; | |
| 451 | |
| 452 const int edges = (mb_type & (MB_TYPE_16x16|MB_TYPE_SKIP)) | |
| 453 == (MB_TYPE_16x16|MB_TYPE_SKIP) ? 1 : 4; | |
| 454 // how often to recheck mv-based bS when iterating between edges | |
| 455 const int mask_edge = (mb_type & (MB_TYPE_16x16 | (MB_TYPE_16x8 << dir))) ? 3 : | |
| 456 (mb_type & (MB_TYPE_8x16 >> dir)) ? 1 : 0; | |
| 457 // how often to recheck mv-based bS when iterating along each edge | |
| 458 const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)); | |
| 459 | |
| 460 if (first_vertical_edge_done) { | |
| 461 start = 1; | |
| 462 } | |
| 463 | |
| 464 if (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_table[mb_xy]) | |
| 465 start = 1; | |
| 466 | |
| 467 if (FRAME_MBAFF && (dir == 1) && ((mb_y&1) == 0) && start == 0 | |
| 468 && !IS_INTERLACED(mb_type) | |
| 469 && IS_INTERLACED(mbm_type) | |
| 470 ) { | |
| 471 // This is a special case in the norm where the filtering must | |
| 472 // be done twice (one each of the field) even if we are in a | |
| 473 // frame macroblock. | |
| 474 // | |
| 475 unsigned int tmp_linesize = 2 * linesize; | |
| 476 unsigned int tmp_uvlinesize = 2 * uvlinesize; | |
| 477 int mbn_xy = mb_xy - 2 * s->mb_stride; | |
| 478 int qp; | |
| 479 int i, j; | |
| 480 int16_t bS[4]; | |
| 481 | |
| 482 for(j=0; j<2; j++, mbn_xy += s->mb_stride){ | |
| 483 if( IS_INTRA(mb_type) || | |
| 484 IS_INTRA(s->current_picture.mb_type[mbn_xy]) ) { | |
| 485 bS[0] = bS[1] = bS[2] = bS[3] = 3; | |
| 486 } else { | |
| 487 const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy]; | |
| 488 for( i = 0; i < 4; i++ ) { | |
| 489 if( h->non_zero_count_cache[scan8[0]+i] != 0 || | |
|
10909
f4cf3960b8c6
Reorganize how values are stored in h->non_zero_count.
michael
parents:
10906
diff
changeset
|
490 mbn_nnz[i+4+3*8] != 0 ) |
| 10854 | 491 bS[i] = 2; |
| 492 else | |
| 493 bS[i] = 1; | |
| 494 } | |
| 495 } | |
| 496 // Do not use s->qscale as luma quantizer because it has not the same | |
| 497 // value in IPCM macroblocks. | |
| 498 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; | |
| 499 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); | |
| 500 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | |
| 501 filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp ); | |
| 502 filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, | |
| 503 ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); | |
| 504 filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, | |
| 505 ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); | |
| 506 } | |
| 507 | |
| 508 start = 1; | |
| 509 } | |
| 510 | |
| 511 /* Calculate bS */ | |
| 512 for( edge = start; edge < edges; edge++ ) { | |
| 513 /* mbn_xy: neighbor macroblock */ | |
| 514 const int mbn_xy = edge > 0 ? mb_xy : mbm_xy; | |
| 515 const int mbn_type = s->current_picture.mb_type[mbn_xy]; | |
| 516 int (*ref2frmn)[64] = edge > 0 ? ref2frm : ref2frmm; | |
| 517 int16_t bS[4]; | |
| 518 int qp; | |
| 519 | |
| 520 if( (edge&1) && IS_8x8DCT(mb_type) ) | |
| 521 continue; | |
| 522 | |
| 523 if( IS_INTRA(mb_type) || | |
| 524 IS_INTRA(mbn_type) ) { | |
| 525 int value; | |
| 526 if (edge == 0) { | |
| 527 if ( (!IS_INTERLACED(mb_type) && !IS_INTERLACED(mbm_type)) | |
| 528 || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0)) | |
| 529 ) { | |
| 530 value = 4; | |
| 531 } else { | |
| 532 value = 3; | |
| 533 } | |
| 534 } else { | |
| 535 value = 3; | |
| 536 } | |
| 537 bS[0] = bS[1] = bS[2] = bS[3] = value; | |
| 538 } else { | |
| 539 int i, l; | |
| 540 int mv_done; | |
| 541 | |
| 542 if( edge & mask_edge ) { | |
| 543 bS[0] = bS[1] = bS[2] = bS[3] = 0; | |
| 544 mv_done = 1; | |
| 545 } | |
| 546 else if( FRAME_MBAFF && IS_INTERLACED(mb_type ^ mbn_type)) { | |
| 547 bS[0] = bS[1] = bS[2] = bS[3] = 1; | |
| 548 mv_done = 1; | |
| 549 } | |
| 550 else if( mask_par0 && (edge || (mbn_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) { | |
| 551 int b_idx= 8 + 4 + edge * (dir ? 8:1); | |
| 552 int bn_idx= b_idx - (dir ? 8:1); | |
| 553 int v = 0; | |
| 554 | |
| 555 for( l = 0; !v && l < 1 + (h->slice_type_nos == FF_B_TYPE); l++ ) { | |
| 10899 | 556 v |= ref2frm[l][h->ref_cache[l][b_idx]] != ref2frmn[l][h->ref_cache[l][bn_idx]] | |
|
10901
2a5c3d89201d
Another microopt, 4 cpu cycles for avoidance of FFABS().
michael
parents:
10899
diff
changeset
|
557 h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] + 3 >= 7U | |
| 10854 | 558 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit; |
| 559 } | |
| 560 | |
| 561 if(h->slice_type_nos == FF_B_TYPE && v){ | |
| 562 v=0; | |
| 563 for( l = 0; !v && l < 2; l++ ) { | |
| 564 int ln= 1-l; | |
| 10899 | 565 v |= ref2frm[l][h->ref_cache[l][b_idx]] != ref2frmn[ln][h->ref_cache[ln][bn_idx]] | |
|
10901
2a5c3d89201d
Another microopt, 4 cpu cycles for avoidance of FFABS().
michael
parents:
10899
diff
changeset
|
566 h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] + 3 >= 7U | |
| 10854 | 567 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit; |
| 568 } | |
| 569 } | |
| 570 | |
| 571 bS[0] = bS[1] = bS[2] = bS[3] = v; | |
| 572 mv_done = 1; | |
| 573 } | |
| 574 else | |
| 575 mv_done = 0; | |
| 576 | |
| 577 for( i = 0; i < 4; i++ ) { | |
| 578 int x = dir == 0 ? edge : i; | |
| 579 int y = dir == 0 ? i : edge; | |
| 580 int b_idx= 8 + 4 + x + 8*y; | |
| 581 int bn_idx= b_idx - (dir ? 8:1); | |
| 582 | |
| 583 if( h->non_zero_count_cache[b_idx] | | |
| 584 h->non_zero_count_cache[bn_idx] ) { | |
| 585 bS[i] = 2; | |
| 586 } | |
| 587 else if(!mv_done) | |
| 588 { | |
| 589 bS[i] = 0; | |
| 590 for( l = 0; l < 1 + (h->slice_type_nos == FF_B_TYPE); l++ ) { | |
|
10902
1e41e6ab9a18
Apply last 2 optimizations to similar code i forgot.
michael
parents:
10901
diff
changeset
|
591 if( ref2frm[l][h->ref_cache[l][b_idx]] != ref2frmn[l][h->ref_cache[l][bn_idx]] | |
|
1e41e6ab9a18
Apply last 2 optimizations to similar code i forgot.
michael
parents:
10901
diff
changeset
|
592 h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] + 3 >= 7U | |
| 10854 | 593 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit ) { |
| 594 bS[i] = 1; | |
| 595 break; | |
| 596 } | |
| 597 } | |
| 598 | |
| 599 if(h->slice_type_nos == FF_B_TYPE && bS[i]){ | |
| 600 bS[i] = 0; | |
| 601 for( l = 0; l < 2; l++ ) { | |
| 602 int ln= 1-l; | |
|
10902
1e41e6ab9a18
Apply last 2 optimizations to similar code i forgot.
michael
parents:
10901
diff
changeset
|
603 if( ref2frm[l][h->ref_cache[l][b_idx]] != ref2frmn[ln][h->ref_cache[ln][bn_idx]] | |
|
1e41e6ab9a18
Apply last 2 optimizations to similar code i forgot.
michael
parents:
10901
diff
changeset
|
604 h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] + 3 >= 7U | |
| 10854 | 605 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit ) { |
| 606 bS[i] = 1; | |
| 607 break; | |
| 608 } | |
| 609 } | |
| 610 } | |
| 611 } | |
| 612 } | |
| 613 | |
| 614 if(bS[0]+bS[1]+bS[2]+bS[3] == 0) | |
| 615 continue; | |
| 616 } | |
| 617 | |
| 618 /* Filter edge */ | |
| 619 // Do not use s->qscale as luma quantizer because it has not the same | |
| 620 // value in IPCM macroblocks. | |
| 621 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; | |
| 10906 | 622 //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]); |
| 10854 | 623 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); |
| 10904 | 624 //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } |
| 10854 | 625 if( dir == 0 ) { |
| 626 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); | |
| 627 if( (edge&1) == 0 ) { | |
| 628 filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, | |
| 629 ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); | |
| 630 filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, | |
| 631 ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); | |
| 632 } | |
| 633 } else { | |
| 634 filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp ); | |
| 635 if( (edge&1) == 0 ) { | |
| 636 filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, | |
| 637 ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); | |
| 638 filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, | |
| 639 ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); | |
| 640 } | |
| 641 } | |
| 642 } | |
| 643 } | |
| 644 | |
| 645 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) { | |
| 646 MpegEncContext * const s = &h->s; | |
| 647 const int mb_xy= mb_x + mb_y*s->mb_stride; | |
| 648 const int mb_type = s->current_picture.mb_type[mb_xy]; | |
| 649 const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4; | |
| 650 int first_vertical_edge_done = 0; | |
| 651 av_unused int dir; | |
| 10906 | 652 int list; |
| 10854 | 653 |
| 654 //for sufficiently low qp, filtering wouldn't do anything | |
| 655 //this is a conservative estimate: could also check beta_offset and more accurate chroma_qp | |
| 656 if(!FRAME_MBAFF){ | |
|
10896
f112b4d030fa
Avoid wasting 4 cpu cycles per MB in redundantly calculating qp_thresh.
michael
parents:
10854
diff
changeset
|
657 int qp_thresh = h->qp_thresh; |
| 10854 | 658 int qp = s->current_picture.qscale_table[mb_xy]; |
| 659 if(qp <= qp_thresh | |
| 660 && (mb_x == 0 || ((qp + s->current_picture.qscale_table[mb_xy-1] + 1)>>1) <= qp_thresh) | |
| 661 && (h->top_mb_xy < 0 || ((qp + s->current_picture.qscale_table[h->top_mb_xy] + 1)>>1) <= qp_thresh)){ | |
| 662 return; | |
| 663 } | |
| 664 } | |
| 665 // CAVLC 8x8dct requires NNZ values for residual decoding that differ from what the loop filter needs | |
| 666 if(!h->pps.cabac && h->pps.transform_8x8_mode){ | |
| 667 int top_type, left_type[2]; | |
| 668 top_type = s->current_picture.mb_type[h->top_mb_xy] ; | |
| 669 left_type[0] = s->current_picture.mb_type[h->left_mb_xy[0]]; | |
| 670 left_type[1] = s->current_picture.mb_type[h->left_mb_xy[1]]; | |
| 671 | |
| 672 if(IS_8x8DCT(top_type)){ | |
| 673 h->non_zero_count_cache[4+8*0]= | |
| 674 h->non_zero_count_cache[5+8*0]= h->cbp_table[h->top_mb_xy] & 4; | |
| 675 h->non_zero_count_cache[6+8*0]= | |
| 676 h->non_zero_count_cache[7+8*0]= h->cbp_table[h->top_mb_xy] & 8; | |
| 677 } | |
| 678 if(IS_8x8DCT(left_type[0])){ | |
| 679 h->non_zero_count_cache[3+8*1]= | |
| 680 h->non_zero_count_cache[3+8*2]= h->cbp_table[h->left_mb_xy[0]]&2; //FIXME check MBAFF | |
| 681 } | |
| 682 if(IS_8x8DCT(left_type[1])){ | |
| 683 h->non_zero_count_cache[3+8*3]= | |
| 684 h->non_zero_count_cache[3+8*4]= h->cbp_table[h->left_mb_xy[1]]&8; //FIXME check MBAFF | |
| 685 } | |
| 686 | |
| 687 if(IS_8x8DCT(mb_type)){ | |
| 688 h->non_zero_count_cache[scan8[0 ]]= h->non_zero_count_cache[scan8[1 ]]= | |
| 10906 | 689 h->non_zero_count_cache[scan8[2 ]]= h->non_zero_count_cache[scan8[3 ]]= h->cbp_table[mb_xy] & 1; |
| 10854 | 690 |
| 691 h->non_zero_count_cache[scan8[0+ 4]]= h->non_zero_count_cache[scan8[1+ 4]]= | |
| 10906 | 692 h->non_zero_count_cache[scan8[2+ 4]]= h->non_zero_count_cache[scan8[3+ 4]]= h->cbp_table[mb_xy] & 2; |
| 10854 | 693 |
| 694 h->non_zero_count_cache[scan8[0+ 8]]= h->non_zero_count_cache[scan8[1+ 8]]= | |
| 10906 | 695 h->non_zero_count_cache[scan8[2+ 8]]= h->non_zero_count_cache[scan8[3+ 8]]= h->cbp_table[mb_xy] & 4; |
| 10854 | 696 |
| 697 h->non_zero_count_cache[scan8[0+12]]= h->non_zero_count_cache[scan8[1+12]]= | |
| 10906 | 698 h->non_zero_count_cache[scan8[2+12]]= h->non_zero_count_cache[scan8[3+12]]= h->cbp_table[mb_xy] & 8; |
| 10854 | 699 } |
| 700 } | |
| 701 | |
| 702 if (FRAME_MBAFF | |
| 703 // left mb is in picture | |
| 704 && h->slice_table[mb_xy-1] != 0xFFFF | |
| 705 // and current and left pair do not have the same interlaced type | |
| 706 && (IS_INTERLACED(mb_type) != IS_INTERLACED(s->current_picture.mb_type[mb_xy-1])) | |
| 707 // and left mb is in the same slice if deblocking_filter == 2 | |
| 708 && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_table[mb_xy])) { | |
| 709 /* First vertical edge is different in MBAFF frames | |
| 710 * There are 8 different bS to compute and 2 different Qp | |
| 711 */ | |
| 712 const int pair_xy = mb_x + (mb_y&~1)*s->mb_stride; | |
| 713 const int left_mb_xy[2] = { pair_xy-1, pair_xy-1+s->mb_stride }; | |
| 714 int16_t bS[8]; | |
| 715 int qp[2]; | |
| 716 int bqp[2]; | |
| 717 int rqp[2]; | |
| 718 int mb_qp, mbn0_qp, mbn1_qp; | |
| 719 int i; | |
| 720 first_vertical_edge_done = 1; | |
| 721 | |
| 722 if( IS_INTRA(mb_type) ) | |
| 723 bS[0] = bS[1] = bS[2] = bS[3] = bS[4] = bS[5] = bS[6] = bS[7] = 4; | |
| 724 else { | |
| 725 for( i = 0; i < 8; i++ ) { | |
| 726 int mbn_xy = MB_FIELD ? left_mb_xy[i>>2] : left_mb_xy[i&1]; | |
| 727 | |
| 728 if( IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) | |
| 729 bS[i] = 4; | |
| 730 else if( h->non_zero_count_cache[12+8*(i>>1)] != 0 || | |
| 731 ((!h->pps.cabac && IS_8x8DCT(s->current_picture.mb_type[mbn_xy])) ? | |
| 732 (h->cbp_table[mbn_xy] & ((MB_FIELD ? (i&2) : (mb_y&1)) ? 8 : 2)) | |
| 733 : | |
|
10909
f4cf3960b8c6
Reorganize how values are stored in h->non_zero_count.
michael
parents:
10906
diff
changeset
|
734 h->non_zero_count[mbn_xy][7+(MB_FIELD ? (i&3) : (i>>2)+(mb_y&1)*2)*8])) |
| 10854 | 735 bS[i] = 2; |
| 736 else | |
| 737 bS[i] = 1; | |
| 738 } | |
| 739 } | |
| 740 | |
| 741 mb_qp = s->current_picture.qscale_table[mb_xy]; | |
| 742 mbn0_qp = s->current_picture.qscale_table[left_mb_xy[0]]; | |
| 743 mbn1_qp = s->current_picture.qscale_table[left_mb_xy[1]]; | |
| 744 qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1; | |
| 745 bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) + | |
| 746 get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1; | |
| 747 rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) + | |
| 748 get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1; | |
| 749 qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1; | |
| 750 bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) + | |
| 751 get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1; | |
| 752 rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) + | |
| 753 get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1; | |
| 754 | |
| 755 /* Filter edge */ | |
| 756 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); | |
| 757 { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | |
| 758 filter_mb_mbaff_edgev ( h, &img_y [0], linesize, bS, qp ); | |
| 759 filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, bqp ); | |
| 760 filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, rqp ); | |
| 761 } | |
| 762 | |
| 763 #if CONFIG_SMALL | |
| 764 for( dir = 0; dir < 2; dir++ ) | |
| 765 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, dir); | |
| 766 #else | |
| 767 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, 0); | |
| 768 filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, 1); | |
| 769 #endif | |
| 770 } |
