Coverage Report

Created: 2025-06-13 07:07

/src/aom/av1/common/scale.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include "config/aom_dsp_rtcd.h"
13
#include "config/av1_rtcd.h"
14
15
#include "av1/common/filter.h"
16
#include "av1/common/scale.h"
17
#include "aom_dsp/aom_filter.h"
18
19
756k
static int get_fixed_point_scale_factor(int other_size, int this_size) {
20
  // Calculate scaling factor once for each reference frame
21
  // and use fixed point scaling factors in decoding and encoding routines.
22
  // Hardware implementations can calculate scale factor in device driver
23
  // and use multiplication and shifting on hardware instead of division.
24
756k
  return ((other_size << REF_SCALE_SHIFT) + this_size / 2) / this_size;
25
756k
}
26
27
// Given the fixed point scale, calculate coarse point scale.
28
756k
static int fixed_point_scale_to_coarse_point_scale(int scale_fp) {
29
756k
  return ROUND_POWER_OF_TWO(scale_fp, REF_SCALE_SHIFT - SCALE_SUBPEL_BITS);
30
756k
}
31
32
// Note: x and y are integer precision, mvq4 is q4 precision.
33
MV32 av1_scale_mv(const MV *mvq4, int x, int y,
34
2.31M
                  const struct scale_factors *sf) {
35
2.31M
  const int x_off_q4 = av1_scaled_x(x << SUBPEL_BITS, sf);
36
2.31M
  const int y_off_q4 = av1_scaled_y(y << SUBPEL_BITS, sf);
37
2.31M
  const MV32 res = {
38
2.31M
    av1_scaled_y((y << SUBPEL_BITS) + mvq4->row, sf) - y_off_q4,
39
2.31M
    av1_scaled_x((x << SUBPEL_BITS) + mvq4->col, sf) - x_off_q4
40
2.31M
  };
41
2.31M
  return res;
42
2.31M
}
43
44
void av1_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w,
45
385k
                                       int other_h, int this_w, int this_h) {
46
385k
  if (!valid_ref_frame_size(other_w, other_h, this_w, this_h)) {
47
6.81k
    sf->x_scale_fp = REF_INVALID_SCALE;
48
6.81k
    sf->y_scale_fp = REF_INVALID_SCALE;
49
6.81k
    return;
50
6.81k
  }
51
52
378k
  sf->x_scale_fp = get_fixed_point_scale_factor(other_w, this_w);
53
378k
  sf->y_scale_fp = get_fixed_point_scale_factor(other_h, this_h);
54
55
378k
  sf->x_step_q4 = fixed_point_scale_to_coarse_point_scale(sf->x_scale_fp);
56
378k
  sf->y_step_q4 = fixed_point_scale_to_coarse_point_scale(sf->y_scale_fp);
57
378k
}