av1/encoder/intra_mode_search.c
// With given luma directional intra prediction mode, pick the best angle delta
// Return the RD cost corresponding to the best angle delta.
With given luma directional intra prediction mode, pick the best angle delta
Return the RD cost corresponding to the best angle delta.
With given luma directional intra prediction mode pick the best angle delta Return the RD cost corresponding to the best angle delta .
static int64_t rd_pick_intra_angle_sby(const AV1_COMP *const cpi, MACROBLOCK *x,
                                       int *rate, RD_STATS *rd_stats,
                                       BLOCK_SIZE bsize, int mode_cost,
                                       int64_t best_rd, int64_t *best_model_rd,
                                       int skip_model_rd_for_zero_deg) {
  MACROBLOCKD *xd = &x->e_mbd;
  MB_MODE_INFO *mbmi = xd->mi[0];
  assert(!is_inter_block(mbmi));
  int best_angle_delta = 0;
  int64_t rd_cost[2 * (MAX_ANGLE_DELTA + 2)];
  TX_SIZE best_tx_size = mbmi->tx_size;
  uint8_t best_blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
  uint8_t best_tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE];
  for (int i = 0; i < 2 * (MAX_ANGLE_DELTA + 2); ++i) rd_cost[i] = INT64_MAX;
  int first_try = 1;
  for (int angle_delta = 0; angle_delta <= MAX_ANGLE_DELTA; angle_delta += 2) {
    for (int i = 0; i < 2; ++i) {
      const int64_t best_rd_in =
          (best_rd == INT64_MAX) ? INT64_MAX
                                 : (best_rd + (best_rd >> (first_try ? 3 : 5)));
      const int64_t this_rd = calc_rd_given_intra_angle(
          cpi, x, bsize, mode_cost, best_rd_in, (1 - 2 * i) * angle_delta,
          MAX_ANGLE_DELTA, rate, rd_stats, &best_angle_delta, &best_tx_size,
          &best_rd, best_model_rd, best_tx_type_map, best_blk_skip,
          (skip_model_rd_for_zero_deg & !angle_delta));
      rd_cost[2 * angle_delta + i] = this_rd;
      if (first_try && this_rd == INT64_MAX) return best_rd;
      first_try = 0;
      if (angle_delta == 0) {
        rd_cost[1] = this_rd;
        break;
      }
    }
  }
  assert(best_rd != INT64_MAX);
  for (int angle_delta = 1; angle_delta <= MAX_ANGLE_DELTA; angle_delta += 2) {
    for (int i = 0; i < 2; ++i) {
      int skip_search = 0;
      const int64_t rd_thresh = best_rd + (best_rd >> 5);
      if (rd_cost[2 * (angle_delta + 1) + i] > rd_thresh &&
          rd_cost[2 * (angle_delta - 1) + i] > rd_thresh)
        skip_search = 1;
      if (!skip_search) {
        calc_rd_given_intra_angle(
            cpi, x, bsize, mode_cost, best_rd, (1 - 2 * i) * angle_delta,
            MAX_ANGLE_DELTA, rate, rd_stats, &best_angle_delta, &best_tx_size,
            &best_rd, best_model_rd, best_tx_type_map, best_blk_skip, 0);
      }
    }
  }
  if (rd_stats->rate != INT_MAX) {
    mbmi->tx_size = best_tx_size;
    mbmi->angle_delta[PLANE_TYPE_Y] = best_angle_delta;
    const int n4 = bsize_to_num_blk(bsize);
    memcpy(x->blk_skip, best_blk_skip, sizeof(best_blk_skip[0]) * n4);
    av1_copy_array(xd->tx_type_map, best_tx_type_map, n4);
  }
  return best_rd;
}
static int64_t rd_pick_intra_angle_sby ( const AV1_COMP * const cpi , MACROBLOCK * x , int * rate , RD_STATS * rd_stats , BLOCK_SIZE bsize , int mode_cost , int64_t best_rd , int64_t * best_model_rd , int skip_model_rd_for_zero_deg ) { MACROBLOCKD * xd = & x -> e_mbd ; MB_MODE_INFO * mbmi = xd -> mi [ 0 ] ; assert ( ! is_inter_block ( mbmi ) ) ; int best_angle_delta = 0 ; int64_t rd_cost [ 2 * ( MAX_ANGLE_DELTA + 2 ) ] ; TX_SIZE best_tx_size = mbmi -> tx_size ; uint8_t best_blk_skip [ MAX_MIB_SIZE * MAX_MIB_SIZE ] ; uint8_t best_tx_type_map [ MAX_MIB_SIZE * MAX_MIB_SIZE ] ; for ( int i = 0 ; i < 2 * ( MAX_ANGLE_DELTA + 2 ) ; ++ i ) rd_cost [ i ] = INT64_MAX ; int first_try = 1 ; for ( int angle_delta = 0 ; angle_delta <= MAX_ANGLE_DELTA ; angle_delta += 2 ) { for ( int i = 0 ; i < 2 ; ++ i ) { const int64_t best_rd_in = ( best_rd == INT64_MAX ) ? INT64_MAX : ( best_rd + ( best_rd >> ( first_try ? 3 : 5 ) ) ) ; const int64_t this_rd = calc_rd_given_intra_angle ( cpi , x , bsize , mode_cost , best_rd_in , ( 1 - 2 * i ) * angle_delta , MAX_ANGLE_DELTA , rate , rd_stats , & best_angle_delta , & best_tx_size , & best_rd , best_model_rd , best_tx_type_map , best_blk_skip , ( skip_model_rd_for_zero_deg & ! angle_delta ) ) ; rd_cost [ 2 * angle_delta + i ] = this_rd ; if ( first_try && this_rd == INT64_MAX ) return best_rd ; first_try = 0 ; if ( angle_delta == 0 ) { rd_cost [ 1 ] = this_rd ; break ; } } } assert ( best_rd != INT64_MAX ) ; for ( int angle_delta = 1 ; angle_delta <= MAX_ANGLE_DELTA ; angle_delta += 2 ) { for ( int i = 0 ; i < 2 ; ++ i ) { int skip_search = 0 ; const int64_t rd_thresh = best_rd + ( best_rd >> 5 ) ; if ( rd_cost [ 2 * ( angle_delta + 1 ) + i ] > rd_thresh && rd_cost [ 2 * ( angle_delta - 1 ) + i ] > rd_thresh ) skip_search = 1 ; if ( ! skip_search ) { calc_rd_given_intra_angle ( cpi , x , bsize , mode_cost , best_rd , ( 1 - 2 * i ) * angle_delta , MAX_ANGLE_DELTA , rate , rd_stats , & best_angle_delta , & best_tx_size , & best_rd , best_model_rd , best_tx_type_map , best_blk_skip , 0 ) ; } } } if ( rd_stats -> rate != INT_MAX ) { mbmi -> tx_size = best_tx_size ; mbmi -> angle_delta [ PLANE_TYPE_Y ] = best_angle_delta ; const int n4 = bsize_to_num_blk ( bsize ) ; memcpy ( x -> blk_skip , best_blk_skip , sizeof ( best_blk_skip [ 0 ] ) * n4 ) ; av1_copy_array ( xd -> tx_type_map , best_tx_type_map , n4 ) ; } return best_rd ; }
With given luma directional intra prediction mode, pick the best angle delta
Return the RD cost corresponding to the best angle delta.
With given luma directional intra prediction mode pick the best angle delta Return the RD cost corresponding to the best angle delta .