+static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int bS[8], int qp[2] ) {
+ int i;
+ for( i = 0; i < 16; i++, pix += stride) {
+ int index_a;
+ int alpha;
+ int beta;
+
+ int qp_index;
+ int bS_index = (i >> 1);
+ if (h->mb_field_decoding_flag) {
+ bS_index &= ~1;
+ bS_index |= (i & 1);
+ }
+
+ if( bS[bS_index] == 0 ) {
+ continue;
+ }
+
+ qp_index = h->mb_field_decoding_flag ? (i & 1) : (i >> 3);
+ index_a = clip( qp[qp_index] + h->slice_alpha_c0_offset, 0, 51 );
+ alpha = alpha_table[index_a];
+ beta = beta_table[clip( qp[qp_index] + h->slice_beta_offset, 0, 51 )];
+
+
+ if( bS[bS_index] < 4 ) {
+ const int tc0 = tc0_table[index_a][bS[bS_index] - 1];
+ /* 4px edge length */
+ const int p0 = pix[-1];
+ const int p1 = pix[-2];
+ const int p2 = pix[-3];
+ const int q0 = pix[0];
+ const int q1 = pix[1];
+ const int q2 = pix[2];
+
+ if( ABS( p0 - q0 ) < alpha &&
+ ABS( p1 - p0 ) < beta &&
+ ABS( q1 - q0 ) < beta ) {
+ int tc = tc0;
+ int i_delta;
+
+ if( ABS( p2 - p0 ) < beta ) {
+ pix[-2] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
+ tc++;
+ }
+ if( ABS( q2 - q0 ) < beta ) {
+ pix[1] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
+ tc++;
+ }
+
+ i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
+ pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */
+ pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
+ tprintf("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);
+ }
+ }else{
+ /* 4px edge length */
+ const int p0 = pix[-1];
+ const int p1 = pix[-2];
+ const int p2 = pix[-3];
+
+ const int q0 = pix[0];
+ const int q1 = pix[1];
+ const int q2 = pix[2];
+
+ if( ABS( p0 - q0 ) < alpha &&
+ ABS( p1 - p0 ) < beta &&
+ ABS( q1 - q0 ) < beta ) {
+
+ if(ABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){
+ if( ABS( p2 - p0 ) < beta)
+ {
+ const int p3 = pix[-4];
+ /* p0', p1', p2' */
+ pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
+ pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
+ pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
+ } else {
+ /* p0' */
+ pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
+ }
+ if( ABS( q2 - q0 ) < beta)
+ {
+ const int q3 = pix[3];
+ /* q0', q1', q2' */
+ pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
+ pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
+ pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
+ } else {
+ /* q0' */
+ pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
+ }
+ }else{
+ /* p0', q0' */
+ pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
+ pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
+ }
+ tprintf("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]);
+ }
+ }
+ }
+}
+static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int bS[4], int qp[2] ) {
+ int i;
+ for( i = 0; i < 8; i++, pix += stride) {
+ int index_a;
+ int alpha;
+ int beta;
+
+ int qp_index;
+ int bS_index = i;
+
+ if( bS[bS_index] == 0 ) {
+ continue;
+ }
+
+ qp_index = h->mb_field_decoding_flag ? (i & 1) : (i >> 3);
+ index_a = clip( qp[qp_index] + h->slice_alpha_c0_offset, 0, 51 );
+ alpha = alpha_table[index_a];
+ beta = beta_table[clip( qp[qp_index] + h->slice_beta_offset, 0, 51 )];
+ if( bS[bS_index] < 4 ) {
+ const int tc = tc0_table[index_a][bS[bS_index] - 1] + 1;
+ /* 2px edge length (because we use same bS than the one for luma) */
+ const int p0 = pix[-1];
+ const int p1 = pix[-2];
+ const int q0 = pix[0];
+ const int q1 = pix[1];
+
+ if( ABS( p0 - q0 ) < alpha &&
+ ABS( p1 - p0 ) < beta &&
+ ABS( q1 - q0 ) < beta ) {
+ const int i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
+
+ pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */
+ pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
+ tprintf("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);
+ }
+ }else{
+ const int p0 = pix[-1];
+ const int p1 = pix[-2];
+ const int q0 = pix[0];
+ const int q1 = pix[1];
+
+ if( ABS( p0 - q0 ) < alpha &&
+ ABS( p1 - p0 ) < beta &&
+ ABS( q1 - q0 ) < beta ) {
+
+ pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
+ pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
+ tprintf("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]);
+ }
+ }
+ }
+}
+