av1/encoder/temporal_filter.c
// Builds predictor for blocks in temporal filtering. This is the second step
// for temporal filtering, which is to construct predictions from all reference
// frames INCLUDING the frame to be filtered itself. These predictors are built
// based on the motion search results (motion vector is set as 0 for the frame
// to be filtered), and will be futher used for weighted averaging.
// Inputs:
//   ref_frame: Pointer to the reference frame (or the frame to be filtered).
//   mbd: Pointer to the block for filtering. Besides containing the subsampling
//        information of all planes, this field also gives the searched motion
//        vector for the entire block, i.e., `mbd->mi[0]->mv[0]`. This vector
//        should be 0 if the `ref_frame` itself is the frame to be filtered.
//   block_size: Size of the block.
//   mb_row: Row index of the block in the entire frame.
//   mb_col: Column index of the block in the entire frame.
//   num_planes: Number of planes in the frame.
//   scale: Scaling factor.
//   use_subblock: Whether to use 4 sub-blocks to replace the original block.
//   subblock_mvs: The motion vectors for each sub-block (row-major order).
//   pred: Pointer to the predictor to build.
// Returns:
//   Nothing will be returned. But the content to which `pred` points will be
//   modified.
Builds predictor for blocks in temporal filtering. This is the second step
for temporal filtering, which is to construct predictions from all reference
frames INCLUDING the frame to be filtered itself. These predictors are built
based on the motion search results (motion vector is set as 0 for the frame
to be filtered), and will be futher used for weighted averaging.
Inputs:
ref_frame: Pointer to the reference frame (or the frame to be filtered).
mbd: Pointer to the block for filtering. Besides containing the subsampling
information of all planes, this field also gives the searched motion
vector for the entire block, i.e., `mbd->mi[0]->mv[0]`. This vector
should be 0 if the `ref_frame` itself is the frame to be filtered.
block_size: Size of the block.
mb_row: Row index of the block in the entire frame.
mb_col: Column index of the block in the entire frame.
num_planes: Number of planes in the frame.
scale: Scaling factor.
use_subblock: Whether to use 4 sub-blocks to replace the original block.
subblock_mvs: The motion vectors for each sub-block (row-major order).
pred: Pointer to the predictor to build.
Returns:
Nothing will be returned. But the content to which `pred` points will be
modified.
Builds predictor for blocks in temporal filtering . This is the second step for temporal filtering which is to construct predictions from all reference frames INCLUDING the frame to be filtered itself . These predictors are built based on the motion search results ( motion vector is set as 0 for the frame to be filtered ) and will be futher used for weighted averaging . Inputs : ref_frame : Pointer to the reference frame ( or the frame to be filtered ) . mbd : Pointer to the block for filtering . Besides containing the subsampling information of all planes this field also gives the searched motion vector for the entire block i . e . ` mbd - > mi [ 0 ] - > mv [ 0 ] ` . This vector should be 0 if the ` ref_frame ` itself is the frame to be filtered . block_size : Size of the block . mb_row : Row index of the block in the entire frame . mb_col : Column index of the block in the entire frame . num_planes : Number of planes in the frame . scale : Scaling factor . use_subblock : Whether to use 4 sub - blocks to replace the original block . subblock_mvs : The motion vectors for each sub - block ( row - major order ) . pred : Pointer to the predictor to build . Returns : Nothing will be returned . But the content to which ` pred ` points will be modified .
static void tf_build_predictor(const YV12_BUFFER_CONFIG *ref_frame,
                               const MACROBLOCKD *mbd,
                               const BLOCK_SIZE block_size, const int mb_row,
                               const int mb_col, const int num_planes,
                               const struct scale_factors *scale,
                               const int use_subblock, const MV *subblock_mvs,
                               uint8_t *pred) {
  assert(num_planes >= 1 && num_planes <= MAX_MB_PLANE);
  const int mb_height = block_size_high[block_size];  
  const int mb_width = block_size_wide[block_size];   
  const int mb_pels = mb_height * mb_width;           
  const int mb_y = mb_height * mb_row;                
  const int mb_x = mb_width * mb_col;                 
  const int bit_depth = mbd->bd;                      
  const int is_intrabc = 0;                           
  const int mb_mv_row = mbd->mi[0]->mv[0].as_mv.row;  
  const int mb_mv_col = mbd->mi[0]->mv[0].as_mv.col;  
  const MV mb_mv = { (int16_t)mb_mv_row, (int16_t)mb_mv_col };
  const int is_high_bitdepth = is_frame_high_bitdepth(ref_frame);
  const int num_blocks = use_subblock ? 2 : 1;  
  const int block_height = mb_height >> (num_blocks - 1);  
  const int block_width = mb_width >> (num_blocks - 1);    
  const int_interpfilters interp_filters =
      av1_broadcast_interp_filter(MULTITAP_SHARP);
  int plane_offset = 0;
  for (int plane = 0; plane < num_planes; ++plane) {
    const int subsampling_y = mbd->plane[plane].subsampling_y;
    const int subsampling_x = mbd->plane[plane].subsampling_x;
    const int plane_h = mb_height >> subsampling_y;  
    const int plane_w = mb_width >> subsampling_x;   
    const int plane_y = mb_y >> subsampling_y;       
    const int plane_x = mb_x >> subsampling_x;       
    const int h = block_height >> subsampling_y;     
    const int w = block_width >> subsampling_x;      
    const int is_y_plane = (plane == 0);             
    const struct buf_2d ref_buf = { NULL, ref_frame->buffers[plane],
                                    ref_frame->widths[is_y_plane ? 0 : 1],
                                    ref_frame->heights[is_y_plane ? 0 : 1],
                                    ref_frame->strides[is_y_plane ? 0 : 1] };
    int subblock_idx = 0;
    for (int i = 0; i < plane_h; i += h) {
      for (int j = 0; j < plane_w; j += w) {
        const MV mv = use_subblock ? subblock_mvs[subblock_idx] : mb_mv;
        assert(mv.row >= INT16_MIN && mv.row <= INT16_MAX &&
               mv.col >= INT16_MIN && mv.col <= INT16_MAX);
        const int y = plane_y + i;
        const int x = plane_x + j;
        InterPredParams inter_pred_params;
        av1_init_inter_params(&inter_pred_params, w, h, y, x, subsampling_x,
                              subsampling_y, bit_depth, is_high_bitdepth,
                              is_intrabc, scale, &ref_buf, interp_filters);
        inter_pred_params.conv_params = get_conv_params(0, plane, bit_depth);
        av1_build_inter_predictor(&pred[plane_offset + i * plane_w + j],
                                  plane_w, &mv, &inter_pred_params);
        ++subblock_idx;
      }
    }
    plane_offset += mb_pels;
  }
}
static void tf_build_predictor ( const YV12_BUFFER_CONFIG * ref_frame , const MACROBLOCKD * mbd , const BLOCK_SIZE block_size , const int mb_row , const int mb_col , const int num_planes , const struct scale_factors * scale , const int use_subblock , const MV * subblock_mvs , uint8_t * pred ) { assert ( num_planes >= 1 && num_planes <= MAX_MB_PLANE ) ; const int mb_height = block_size_high [ block_size ] ; const int mb_width = block_size_wide [ block_size ] ; const int mb_pels = mb_height * mb_width ; const int mb_y = mb_height * mb_row ; const int mb_x = mb_width * mb_col ; const int bit_depth = mbd -> bd ; const int is_intrabc = 0 ; const int mb_mv_row = mbd -> mi [ 0 ] -> mv [ 0 ] . as_mv . row ; const int mb_mv_col = mbd -> mi [ 0 ] -> mv [ 0 ] . as_mv . col ; const MV mb_mv = { ( int16_t ) mb_mv_row , ( int16_t ) mb_mv_col } ; const int is_high_bitdepth = is_frame_high_bitdepth ( ref_frame ) ; const int num_blocks = use_subblock ? 2 : 1 ; const int block_height = mb_height >> ( num_blocks - 1 ) ; const int block_width = mb_width >> ( num_blocks - 1 ) ; const int_interpfilters interp_filters = av1_broadcast_interp_filter ( MULTITAP_SHARP ) ; int plane_offset = 0 ; for ( int plane = 0 ; plane < num_planes ; ++ plane ) { const int subsampling_y = mbd -> plane [ plane ] . subsampling_y ; const int subsampling_x = mbd -> plane [ plane ] . subsampling_x ; const int plane_h = mb_height >> subsampling_y ; const int plane_w = mb_width >> subsampling_x ; const int plane_y = mb_y >> subsampling_y ; const int plane_x = mb_x >> subsampling_x ; const int h = block_height >> subsampling_y ; const int w = block_width >> subsampling_x ; const int is_y_plane = ( plane == 0 ) ; const struct buf_2d ref_buf = { NULL , ref_frame -> buffers [ plane ] , ref_frame -> widths [ is_y_plane ? 0 : 1 ] , ref_frame -> heights [ is_y_plane ? 0 : 1 ] , ref_frame -> strides [ is_y_plane ? 0 : 1 ] } ; int subblock_idx = 0 ; for ( int i = 0 ; i < plane_h ; i += h ) { for ( int j = 0 ; j < plane_w ; j += w ) { const MV mv = use_subblock ? subblock_mvs [ subblock_idx ] : mb_mv ; assert ( mv . row >= INT16_MIN && mv . row <= INT16_MAX && mv . col >= INT16_MIN && mv . col <= INT16_MAX ) ; const int y = plane_y + i ; const int x = plane_x + j ; InterPredParams inter_pred_params ; av1_init_inter_params ( & inter_pred_params , w , h , y , x , subsampling_x , subsampling_y , bit_depth , is_high_bitdepth , is_intrabc , scale , & ref_buf , interp_filters ) ; inter_pred_params . conv_params = get_conv_params ( 0 , plane , bit_depth ) ; av1_build_inter_predictor ( & pred [ plane_offset + i * plane_w + j ] , plane_w , & mv , & inter_pred_params ) ; ++ subblock_idx ; } } plane_offset += mb_pels ; } }
Builds predictor for blocks in temporal filtering.
Builds predictor for blocks in temporal filtering .
// Information of the entire block. // Height. // Width. // Number of pixels. // Y-coord (Top-left). // X-coord (Top-left). // Bit depth. // Is intra-copied? // Motion vector (y). // Motion vector (x). // Information of each sub-block (actually in use). // Num of blocks on each side. // Height. // Width. // Default interpolation filters. // Handle Y-plane, U-plane and V-plane (if needed) in sequence. // Information of each sub-block in current plane. // Plane height. // Plane width. // Y-coord (Top-left). // X-coord (Top-left). // Sub-block height. // Sub-block width. // Is Y-plane? // Handle entire block or sub-blocks if needed. // Choose proper motion vector. // Build predictior for each sub-block on current plane.