Coverage Report

Created: 2022-08-24 06:17

/src/aom/av1/common/scale.c
Line
Count
Source (jump to first uncovered line)
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
// Note: Expect val to be in q4 precision
20
0
static INLINE int scaled_x(int val, const struct scale_factors *sf) {
21
0
  const int off =
22
0
      (sf->x_scale_fp - (1 << REF_SCALE_SHIFT)) * (1 << (SUBPEL_BITS - 1));
23
0
  const int64_t tval = (int64_t)val * sf->x_scale_fp + off;
24
0
  return (int)ROUND_POWER_OF_TWO_SIGNED_64(tval,
25
0
                                           REF_SCALE_SHIFT - SCALE_EXTRA_BITS);
26
0
}
27
28
// Note: Expect val to be in q4 precision
29
0
static INLINE int scaled_y(int val, const struct scale_factors *sf) {
30
0
  const int off =
31
0
      (sf->y_scale_fp - (1 << REF_SCALE_SHIFT)) * (1 << (SUBPEL_BITS - 1));
32
0
  const int64_t tval = (int64_t)val * sf->y_scale_fp + off;
33
0
  return (int)ROUND_POWER_OF_TWO_SIGNED_64(tval,
34
0
                                           REF_SCALE_SHIFT - SCALE_EXTRA_BITS);
35
0
}
36
37
// Note: Expect val to be in q4 precision
38
0
static int unscaled_value(int val, const struct scale_factors *sf) {
39
0
  (void)sf;
40
0
  return val * (1 << SCALE_EXTRA_BITS);
41
0
}
42
43
5.52k
static int get_fixed_point_scale_factor(int other_size, int this_size) {
44
  // Calculate scaling factor once for each reference frame
45
  // and use fixed point scaling factors in decoding and encoding routines.
46
  // Hardware implementations can calculate scale factor in device driver
47
  // and use multiplication and shifting on hardware instead of division.
48
5.52k
  return ((other_size << REF_SCALE_SHIFT) + this_size / 2) / this_size;
49
5.52k
}
50
51
// Given the fixed point scale, calculate coarse point scale.
52
5.52k
static int fixed_point_scale_to_coarse_point_scale(int scale_fp) {
53
5.52k
  return ROUND_POWER_OF_TWO(scale_fp, REF_SCALE_SHIFT - SCALE_SUBPEL_BITS);
54
5.52k
}
55
56
// Note: x and y are integer precision, mvq4 is q4 precision.
57
MV32 av1_scale_mv(const MV *mvq4, int x, int y,
58
0
                  const struct scale_factors *sf) {
59
0
  const int x_off_q4 = scaled_x(x << SUBPEL_BITS, sf);
60
0
  const int y_off_q4 = scaled_y(y << SUBPEL_BITS, sf);
61
0
  const MV32 res = { scaled_y((y << SUBPEL_BITS) + mvq4->row, sf) - y_off_q4,
62
0
                     scaled_x((x << SUBPEL_BITS) + mvq4->col, sf) - x_off_q4 };
63
0
  return res;
64
0
}
65
66
void av1_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w,
67
2.76k
                                       int other_h, int this_w, int this_h) {
68
2.76k
  if (!valid_ref_frame_size(other_w, other_h, this_w, this_h)) {
69
0
    sf->x_scale_fp = REF_INVALID_SCALE;
70
0
    sf->y_scale_fp = REF_INVALID_SCALE;
71
0
    return;
72
0
  }
73
74
2.76k
  sf->x_scale_fp = get_fixed_point_scale_factor(other_w, this_w);
75
2.76k
  sf->y_scale_fp = get_fixed_point_scale_factor(other_h, this_h);
76
77
2.76k
  sf->x_step_q4 = fixed_point_scale_to_coarse_point_scale(sf->x_scale_fp);
78
2.76k
  sf->y_step_q4 = fixed_point_scale_to_coarse_point_scale(sf->y_scale_fp);
79
80
2.76k
  if (av1_is_scaled(sf)) {
81
0
    sf->scale_value_x = scaled_x;
82
0
    sf->scale_value_y = scaled_y;
83
2.76k
  } else {
84
2.76k
    sf->scale_value_x = unscaled_value;
85
2.76k
    sf->scale_value_y = unscaled_value;
86
2.76k
  }
87
2.76k
}