public static void h_block_filter(MpegEncContext s,int[] dst_base,int dst_offset,int w,int h,int stride,int is_luma){
  int b_x, b_y, mvx_stride, mvy_stride;
  int[] cm_base=H264DSPContext.ff_cropTbl;
  int cm_offset=H264DSPContext.MAX_NEG_CROP;
  int[] param=new int[2];
  set_mv_strides(s,param);
  mvx_stride=param[0];
  mvy_stride=param[1];
  mvx_stride>>=is_luma;
  mvy_stride*=mvx_stride;
  for (b_y=0; b_y < h; b_y++) {
    for (b_x=0; b_x < w - 1; b_x++) {
      int y;
      int left_status=s.error_status_table[(b_x >> is_luma) + (b_y >> is_luma) * s.mb_stride];
      int right_status=s.error_status_table[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s.mb_stride];
      int left_intra=7 & (int)(s.current_picture.mb_type_base[s.current_picture.mb_type_offset + (b_x >> is_luma) + (b_y >> is_luma) * s.mb_stride]);
      int right_intra=7 & (int)(s.current_picture.mb_type_base[s.current_picture.mb_type_offset + ((b_x + 1) >> is_luma) + (b_y >> is_luma) * s.mb_stride]);
      int left_damage=left_status & (MpegEncContext.DC_ERROR | MpegEncContext.AC_ERROR | MpegEncContext.MV_ERROR);
      int right_damage=right_status & (MpegEncContext.DC_ERROR | MpegEncContext.AC_ERROR | MpegEncContext.MV_ERROR);
      int offset=b_x * 8 + b_y * stride * 8;
      int[] left_mv=s.current_picture.motion_val_base[0][s.current_picture.motion_val_offset[0] + mvy_stride * b_y + mvx_stride * b_x];
      int[] right_mv=s.current_picture.motion_val_base[0][s.current_picture.motion_val_offset[0] + mvy_stride * b_y + mvx_stride * (b_x + 1)];
      if (!(left_damage != 0 || right_damage != 0))       continue;
      if ((0 == left_intra) && (0 == right_intra) && Math.abs(left_mv[0] - right_mv[0]) + Math.abs(left_mv[1] + right_mv[1]) < 2)       continue;
      for (y=0; y < 8; y++) {
        int a, b, c, d;
        a=dst_base[dst_offset + offset + 7+ y * stride] - dst_base[dst_offset + offset + 6+ y * stride];
        b=dst_base[dst_offset + offset + 8+ y * stride] - dst_base[dst_offset + offset + 7+ y * stride];
        c=dst_base[dst_offset + offset + 9+ y * stride] - dst_base[dst_offset + offset + 8+ y * stride];
        d=Math.abs(b) - ((Math.abs(a) + Math.abs(c) + 1) >> 1);
        d=Math.max(d,0);
        if (b < 0)         d=-d;
        if (d == 0)         continue;
        if (!(left_damage != 0 && right_damage != 0))         d=d * 16 / 9;
        if (left_damage != 0) {
          dst_base[dst_offset + offset + 7+ y * stride]=cm_base[cm_offset + dst_base[dst_offset + offset + 7+ y * stride] + ((d * 7) >> 4)];
          dst_base[dst_offset + offset + 6+ y * stride]=cm_base[cm_offset + dst_base[dst_offset + offset + 6+ y * stride] + ((d * 5) >> 4)];
          dst_base[dst_offset + offset + 5+ y * stride]=cm_base[cm_offset + dst_base[dst_offset + offset + 5+ y * stride] + ((d * 3) >> 4)];
          dst_base[dst_offset + offset + 4+ y * stride]=cm_base[cm_offset + dst_base[dst_offset + offset + 4+ y * stride] + ((d * 1) >> 4)];
        }
        if (right_damage != 0) {
          dst_base[dst_offset + offset + 8+ y * stride]=cm_base[cm_offset + dst_base[dst_offset + offset + 8+ y * stride] - ((d * 7) >> 4)];
          dst_base[dst_offset + offset + 9+ y * stride]=cm_base[cm_offset + dst_base[dst_offset + offset + 9+ y * stride] - ((d * 5) >> 4)];
          dst_base[dst_offset + offset + 10+ y * stride]=cm_base[cm_offset + dst_base[dst_offset + offset + 10+ y * stride] - ((d * 3) >> 4)];
          dst_base[dst_offset + offset + 11+ y * stride]=cm_base[cm_offset + dst_base[dst_offset + offset + 11+ y * stride] - ((d * 1) >> 4)];
        }
      }
    }
  }
}

public static void h_block_filter ( MpegEncContext s , int [ ] dst_base , int dst_offset , int w , int h , int stride , int is_luma ) { int b_x , b_y , mvx_stride , mvy_stride ; int [ ] cm_base = H264DSPContext . ff_cropTbl ; int cm_offset = H264DSPContext . MAX_NEG_CROP ; int [ ] param = new int [ 2 ] ; set_mv_strides ( s , param ) ; mvx_stride = param [ 0 ] ; mvy_stride = param [ 1 ] ; mvx_stride >>= is_luma ; mvy_stride *= mvx_stride ; for ( b_y = 0 ; b_y < h ; b_y ++ ) { for ( b_x = 0 ; b_x < w - 1 ; b_x ++ ) { int y ; int left_status = s . error_status_table [ ( b_x > > is_luma ) + ( b_y > > is_luma ) * s . mb_stride ] ; int right_status = s . error_status_table [ ( ( b_x + 1 ) > > is_luma ) + ( b_y > > is_luma ) * s . mb_stride ] ; int left_intra = 7 & ( int ) ( s . current_picture . mb_type_base [ s . current_picture . mb_type_offset + ( b_x > > is_luma ) + ( b_y > > is_luma ) * s . mb_stride ] ) ; int right_intra = 7 & ( int ) ( s . current_picture . mb_type_base [ s . current_picture . mb_type_offset + ( ( b_x + 1 ) > > is_luma ) + ( b_y > > is_luma ) * s . mb_stride ] ) ; int left_damage = left_status & ( MpegEncContext . DC_ERROR | MpegEncContext . AC_ERROR | MpegEncContext . MV_ERROR ) ; int right_damage = right_status & ( MpegEncContext . DC_ERROR | MpegEncContext . AC_ERROR | MpegEncContext . MV_ERROR ) ; int offset = b_x * 8 + b_y * stride * 8 ; int [ ] left_mv = s . current_picture . motion_val_base [ 0 ] [ s . current_picture . motion_val_offset [ 0 ] + mvy_stride * b_y + mvx_stride * b_x ] ; int [ ] right_mv = s . current_picture . motion_val_base [ 0 ] [ s . current_picture . motion_val_offset [ 0 ] + mvy_stride * b_y + mvx_stride * ( b_x + 1 ) ] ; if ( ! ( left_damage != 0 || right_damage != 0 ) ) continue ; if ( ( 0 == left_intra ) && ( 0 == right_intra ) && Math . abs ( left_mv [ 0 ] - right_mv [ 0 ] ) + Math . abs ( left_mv [ 1 ] + right_mv [ 1 ] ) < 2 ) continue ; for ( y = 0 ; y < 8 ; y ++ ) { int a , b , c , d ; a = dst_base [ dst_offset + offset + 7 + y * stride ] - dst_base [ dst_offset + offset + 6 + y * stride ] ; b = dst_base [ dst_offset + offset + 8 + y * stride ] - dst_base [ dst_offset + offset + 7 + y * stride ] ; c = dst_base [ dst_offset + offset + 9 + y * stride ] - dst_base [ dst_offset + offset + 8 + y * stride ] ; d = Math . abs ( b ) - ( ( Math . abs ( a ) + Math . abs ( c ) + 1 ) > > 1 ) ; d = Math . max ( d , 0 ) ; if ( b < 0 ) d = - d ; if ( d == 0 ) continue ; if ( ! ( left_damage != 0 && right_damage != 0 ) ) d = d * 16 / 9 ; if ( left_damage != 0 ) { dst_base [ dst_offset + offset + 7 + y * stride ] = cm_base [ cm_offset + dst_base [ dst_offset + offset + 7 + y * stride ] + ( ( d * 7 ) > > 4 ) ] ; dst_base [ dst_offset + offset + 6 + y * stride ] = cm_base [ cm_offset + dst_base [ dst_offset + offset + 6 + y * stride ] + ( ( d * 5 ) > > 4 ) ] ; dst_base [ dst_offset + offset + 5 + y * stride ] = cm_base [ cm_offset + dst_base [ dst_offset + offset + 5 + y * stride ] + ( ( d * 3 ) > > 4 ) ] ; dst_base [ dst_offset + offset + 4 + y * stride ] = cm_base [ cm_offset + dst_base [ dst_offset + offset + 4 + y * stride ] + ( ( d * 1 ) > > 4 ) ] ; } if ( right_damage != 0 ) { dst_base [ dst_offset + offset + 8 + y * stride ] = cm_base [ cm_offset + dst_base [ dst_offset + offset + 8 + y * stride ] - ( ( d * 7 ) > > 4 ) ] ; dst_base [ dst_offset + offset + 9 + y * stride ] = cm_base [ cm_offset + dst_base [ dst_offset + offset + 9 + y * stride ] - ( ( d * 5 ) > > 4 ) ] ; dst_base [ dst_offset + offset + 10 + y * stride ] = cm_base [ cm_offset + dst_base [ dst_offset + offset + 10 + y * stride ] - ( ( d * 3 ) > > 4 ) ] ; dst_base [ dst_offset + offset + 11 + y * stride ] = cm_base [ cm_offset + dst_base [ dst_offset + offset + 11 + y * stride ] - ( ( d * 1 ) > > 4 ) ] ; } } } } }
simple horizontal deblocking filter used for error resilience
